123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- using System;
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using Debug = System.Diagnostics.Debug;
- public class Shake : MoveRoot
- {
- #region 变量
- public override bool InDestination
- {
- get
- {
- if (Target.position.Equal(Origin))
- {
- InDestination_ = true;
- }
- else
- {
- InDestination_ = false;
- }
- return InDestination_;
- }
- set
- {
- InDestination_ = value;
- InPause = false;
- if (InDestination_)
- {
- Target.position = Origin;
- }
- }
- }
- public int Repeat;
- public float Z;
- public float Timer;
- public float Duration;
- public Vector3 Origin;
- public Vector3 Strength;
- public Transform Target;
- public ShakeFunctionV Func;
- #endregion
- public Shake(Transform transform)
- {
- Target = transform;
- }
- public override bool DoForward()
- {
- Timer += Time.fixedDeltaTime;
- if (Timer > Duration)
- {
- Timer = 0;
- InDestination = true;
- if (OnForwardFinish != null)
- {
- OnForwardFinish.Invoke();
- }
- return true;
- }
- else
- {
- Target.position = Func(Timer, Duration, Repeat, Origin, Strength);
- Target.SetZ(Z);
- return false;
- }
- }
- public override bool DoBackward()
- {
- throw new Exception();
- }
- public void StartShake(int repeat, float duration, Vector3 strength, Curve curve)
- {
- Timer = 0;
- InDestination = false;
- Repeat = repeat;
- Z = Target.position.z;
- Origin = Target.position;
- Strength = strength;
- Duration = duration;
- Func = ManaAnim.ShakeFuncDicV[curve];
- OnForwardStart.SafeInvoke();
- ManaAnim.MoveForList.Remove(this);
- ManaAnim.MoveForList.Add(this);
- }
- }
|