using UnityEngine; using System.Collections; using System.Collections.Generic; using Debug = System.Diagnostics.Debug; public class Shake : Anim { #region 变量 protected override bool InDestination { get { if (Target.position == Origin) { _InDestination = true; } else { _InDestination = false; } return _InDestination; } set { _InDestination = value; if (_InDestination) { Target.position = Origin; } } } protected int Repeat; protected float Z; protected float Timer; protected float Duration; protected Vector3 Origin; protected Vector3 Strength; protected Transform Target; protected ShakeFunctionV Func; #endregion public Shake(Transform transform) { Target = transform; } public override bool Do() { Timer += Time.fixedDeltaTime; if (Timer > Duration) { Timer = 0; InDestination = true; ManaAnim.AnimList.Remove(this); if (OnFinish != null) { OnFinish.Invoke(); } return true; } else { Target.position = Func(Timer, Duration, Repeat, Origin, Strength); Target.SetZ(Z); return false; } } public void StartShake(int repeat, float duration, Vector3 strength, Curve curve) { InDestination = false; Repeat = repeat; Z = Target.position.z; Origin = Target.position; Strength = strength; Duration = duration; Func = ManaAnim.ShakeFunctionDicV[curve]; if (OnStart != null) { OnStart.Invoke(); } ManaAnim.AnimList.Remove(this); ManaAnim.AnimList.Add(this); } }