I’m trying to figure out if I can program generic effect resolvers for my game. What I mean with that is that my effects exist out of two parts. A visual part and a data part. The visual part is for example a cannon ball leaving an origin and hitting a target. The data part being the target hp lowering by x amount. I had the following in mind but I’m not sure if this will be able to render my visual part since it’s outside of any update() method. Could you tell me if I’m on the right track ?
I have following classes now
- an enum giving the effect a name
- an abstract class giving an interface to an effect resolver
- two implementations of that abstract class
- a factory to instantiate an effect resolver
public enum CastEffectEnum {
NONE, NORMAL_DAMAGE, RANDOM_DAMAGE
}
public abstract class CastEffectResolver {
public void ResolveCastEffect(Ship origin, Ship target)
{
ResolveVisualEffect(origin, target);
ResolveDataEffect(origin, target);
}
internal abstract void ResolveDataEffect(Ship origin, Ship target);
internal abstract void ResolveVisualEffect(Ship origin, Ship target);
}
public class NormalDamageCastEffect : CastEffectResolver
{
internal override void ResolveDataEffect(Ship origin, Ship target)
{
throw new NotImplementedException();
}
internal override void ResolveVisualEffect(Ship origin, Ship target)
{
throw new NotImplementedException();
}
}
public class CastEffectFactory {
public CastEffectResolver GetCastEffectResolver(CastEffectEnum castEffect)
{
switch(castEffect)
{
case CastEffectEnum.NORMAL_DAMAGE: return new NormalDamageCastEffect();
case CastEffectEnum.RANDOM_DAMAGE: return new RandomDamageCastEffect();
default: throw new System.Exception("No casteffect found for [" + castEffect + "]");
}
}
}
before I spend to much time in the rabbit hole I would love a second opinion if this is a good way to go and how I would deal showing effects without using an update() method. I read about coroutines so I’m looking in that direction. Seems the rest of a scene runs on a single thread ? I’m still new to unity being a java developer this is a new world for me I’m still learning to navigate through.
Thanks in advance