using System.Collections.Generic; using UnityEngine; namespace Pegasus { /// /// Control the animation on the target with this trigger. /// public class TriggerControlAnimation : TriggerBase { public Animation m_targetAnimation; public PegasusConstants.PoiAnimationTriggerAction m_actionOnStart = PegasusConstants.PoiAnimationTriggerAction.PlayAnimation; public PegasusConstants.PoiAnimationTriggerAction m_actionOnEnd = PegasusConstants.PoiAnimationTriggerAction.DoNothing; public int m_startAnimationIdx = 0; public int m_endAnimation = 0; private List m_animations = new List(); void Start() { if (m_targetAnimation != null) { foreach (AnimationState state in m_targetAnimation) { m_animations.Add(state); } } } /// /// Called when the trigger starts /// /// public override void OnStart(PegasusPoi poi) { if (poi == null) { Debug.LogWarning(string.Format("Poi was not supplied on {0} - exiting", name)); return; } if (m_targetAnimation == null) { Debug.LogWarning(string.Format("Animation was not supplied on {0} - exiting", name)); return; } if (m_triggerAtStart) { if (m_actionOnStart == PegasusConstants.PoiAnimationTriggerAction.PlayAnimation) { m_targetAnimation.Play(m_animations[m_startAnimationIdx].name); } else if (m_actionOnStart == PegasusConstants.PoiAnimationTriggerAction.StopAnimation) { m_targetAnimation.Stop(); } } } /// /// Called when the trigger ends /// /// public override void OnEnd(PegasusPoi poi) { if (poi == null) { Debug.LogWarning(string.Format("Poi was not supplied on {0} - exiting", name)); return; } if (m_targetAnimation == null) { Debug.LogWarning(string.Format("Animation was not supplied on {0} - exiting", name)); return; } if (m_triggerAtEnd) { if (m_actionOnStart == PegasusConstants.PoiAnimationTriggerAction.PlayAnimation) { m_targetAnimation.Play(m_animations[m_startAnimationIdx].name); } else if (m_actionOnStart == PegasusConstants.PoiAnimationTriggerAction.StopAnimation) { m_targetAnimation.Stop(); } } } } }