private IEnumerator RunEffect(BattleAnimationEffect effect, bool dummy = false) { Pause(); yield return(Display.PlayAndWait(effect, Display.Variables)); Unpause(); }
private Transform GetParent(BattleAnimationEffect animation, out bool deleteParent) { deleteParent = false; switch (animation.EffectTarget) { case CreatureDisplayTarget.Battler: { if (string.IsNullOrEmpty(animation.MountPoint)) { return(BattlerPlayer.transform); } var mountObject = BattlerPlayer.transform.Find(animation.MountPoint); if (mountObject) { return(mountObject); } Debug.LogWarningFormat(this, _mountMissingWarning, animation.Effect, animation.MountPoint); return(BattlerPlayer.transform); } case CreatureDisplayTarget.Creature: { if (string.IsNullOrEmpty(animation.MountPoint)) { return(CreatureAnimator.transform); } else if (Creature.Creature.Species.MountPoints.TryGetValue(animation.MountPoint, out var mount)) { deleteParent = true; var renderer = CreatureAnimator.GetComponent <SpriteRenderer>(); var offset = CreatureAnimator.transform.position - renderer.bounds.min; var x = mount.X * renderer.bounds.size.x; var y = mount.Y * renderer.bounds.size.y; var mountObject = new GameObject(animation.MountPoint); mountObject.transform.parent = CreatureAnimator.transform; mountObject.transform.localPosition = new Vector3(x - offset.x, y - offset.y); mountObject.transform.rotation = Quaternion.Euler(0.0f, 0.0f, mount.Rotation); return(mountObject.transform); } else { Debug.LogWarningFormat(this, _mountMissingWarning, animation.Effect, animation.MountPoint); return(CreatureAnimator.transform); } } } return(transform); }
private GameObject GetEffect(BattleAnimationEffect animation, IVariableStore variables) { GameObject effect = null; switch (animation.EffectSource) { case BattleAnimationSource.Display: Effects.TryGetValue(animation.Effect, out effect); break; case BattleAnimationSource.Variables: variables.GetVariable(animation.Effect).TryGetObject(out effect); break; } return(effect); }
public IEnumerator PlayAndWait(BattleAnimationEffect animation, IVariableStore variables) { var effect = GetEffect(animation, variables); if (effect) { var parent = GetParent(animation, out bool deleteParent); var system = Instantiate(effect, parent); if (!animation.FollowParent) { system.transform.SetParent(null, true); } yield return(null); // wait for awake in the spawned object var completionNotifier = system.GetComponentInChildren <ICompletionNotifier>(); var particles = system.GetComponentInChildren <ParticleSystem>(); while ((completionNotifier != null && !completionNotifier.IsComplete) || (particles != null && particles.IsAlive())) { yield return(null); } if (deleteParent) { Destroy(parent.gameObject); } if (!deleteParent || !animation.FollowParent) { Destroy(system.gameObject); } } else { Debug.LogWarningFormat(this, _missingEffectWarning, animation.Effect, animation.EffectSource); } }
public void Play(BattleAnimationEffect animation, IVariableStore variables) { StartCoroutine(PlayAndWait(animation, variables)); // running this as a coroutine so the system gets destroyed when it finishes }