简体   繁体   English

UNITY 寻找一种方法来存储特定咒语的临时全局增量值

[英]UNITY Looking for a way to store temporary global delta value for a specific spell

I am kind of new to unity and currently designing a spell architecture in a multi-player game that could make spell parameters vary with the environment(eg character, equipment, buffs, etc...).我对统一有点陌生,目前在多人游戏中设计一个咒语架构,可以使咒语参数随环境而变化(例如角色、设备、增益等......)。

Yes, it is a multi-player game and I am using Mirror as the multi-player service framework, which means I may consider these delta values as sync vars.是的,它是一个多人游戏,我使用Mirror作为多人服务框架,这意味着我可以将这些delta values视为同步变量。

For example, I designed a fireball spell.例如,我设计了一个火球法术。 The damage of this spell may increase because I could gain a buff.这个法术的伤害可能会增加,因为我可以获得一个增益。 My idea is to use a scriptable object to store the basic parameter values of the spell(eg damage, spell radius, etc...), and then all delta values(eg damage increment) would be collected somewhere.我的想法是使用scriptable object来存储法术的基本参数值(例如伤害、法术半径等),然后在某处收集所有增量值(例如伤害增量)。 This place should be exclusive to a player.这个地方应该是玩家专属的。

In this way, I can calculate the total damage by just adding all delta values on the basic damage stored in the scriptable object.通过这种方式,我可以通过将所有增量值添加到存储在可编写脚本的 object 中的基本伤害上来计算总伤害。

My question is where to store these delta values for every spell separately?我的问题是在哪里分别存储每个咒语的这些增量值?

Is there a global way to store these delta values without instantiating an object?是否有一种全局方法来存储这些增量值而不实例化 object?

I tried scriptable objects but as they are assets, maybe it is not a good idea to use them in this non-persistent scenario.我尝试了scriptable objects ,但由于它们是资产,因此在这种非持久性场景中使用它们可能不是一个好主意。 I wish these delta values could be collected by GC when I do not need them.我希望这些增量值可以在我不需要时由 GC 收集。

I also tried to create scriptable objects at runtime but it doesn't work as well.我还尝试在运行时创建scriptable objects ,但效果不佳。 I don't want to access these scriptable objects after instantiating the object, and scriptable objects no longer exist when the object is destroyed.我不想在实例化 object 后访问这些scriptable objects ,并且当 object 被销毁时scriptable objects不再存在。 I want these delta values could be in a global variable that accompanies the entire life cycle of the game.我希望这些增量值可以在伴随游戏整个生命周期的全局变量中。 So I can keep firing fireballs that improve damage.所以我可以继续发射提高伤害的火球。

The character(hero) already have a temporary scriptable object to store delta values for all spell.角色(英雄)已经有一个临时的脚本 object 来存储所有法术的增量值。 But what if I only want to improve specific spell damage like fireball?但是如果我只想提高像火球术这样的特定法术伤害呢?

Or there actually is a better architecture to implement this spell system without storing delta values separately?或者实际上有更好的架构来实现这个拼写系统而不单独存储增量值?

After @derHugo reminder(very much appreciate it), I found that I forgot to explain that this is a multiplayer game.在@derHugo 提醒后(非常感谢),我发现我忘了解释这是一个多人游戏。 A simple static class for all players may not solve this problem.一个简单的 static class 可能无法解决所有玩家的问题。

I found I can meet my need without storing delta spell parameters.我发现我可以在不存储 delta 拼写参数的情况下满足我的需求。 They can be calculated dynamically by other SpellCalculator .它们可以由其他SpellCalculator动态计算。

If I insist, I can also store the delta spell parameters by dynamically creating ScriptableObject at run time.如果我坚持,我还可以通过在运行时动态创建ScriptableObject来存储 delta 拼写参数。 Obviously, this is unnecessary.显然,这是不必要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM