|
@@ -12,6 +12,13 @@ public enum Curve
|
|
|
EaseOutQuad,
|
|
|
}
|
|
|
|
|
|
+public delegate float ShakeFunctionF(float timer, float duration, int repeat, float start, float strength);
|
|
|
+
|
|
|
+public delegate Color ShakeFunctionC(float timer, float duration, int repeat, Color start, Color strength);
|
|
|
+
|
|
|
+public delegate Vector3 ShakeFunctionV(float timer, float duration, int repeat, Vector3 start, Vector3 strength);
|
|
|
+
|
|
|
+
|
|
|
public delegate float CurveFunctionF(float timer, float duration, float start, float delta);
|
|
|
|
|
|
public delegate Color CurveFunctionC(float timer, float duration, Color start, Color delta);
|
|
@@ -22,15 +29,19 @@ public class ManaAnim : Regist
|
|
|
{
|
|
|
#region 变量
|
|
|
|
|
|
- public static List<Move> MoveList;
|
|
|
+ public static List<Anim> AnimList;
|
|
|
public static List<Tween> TweenForList;
|
|
|
public static List<Tween> TweenBacList;
|
|
|
|
|
|
- public static Dictionary<Curve, CurveFunctionF> FunctionDicF;
|
|
|
- public static Dictionary<Curve, CurveFunctionC> FunctionDicC;
|
|
|
- public static Dictionary<Curve, CurveFunctionV> FunctionDicV;
|
|
|
+ public static Dictionary<Curve, ShakeFunctionF> ShakeFunctionDicF;
|
|
|
+ public static Dictionary<Curve, ShakeFunctionC> ShakeFunctionDicC;
|
|
|
+ public static Dictionary<Curve, ShakeFunctionV> ShakeFunctionDicV;
|
|
|
+ public static Dictionary<Curve, CurveFunctionF> CurveFunctionDicF;
|
|
|
+ public static Dictionary<Curve, CurveFunctionC> CurveFunctionDicC;
|
|
|
+ public static Dictionary<Curve, CurveFunctionV> CurveFunctionDicV;
|
|
|
|
|
|
- public static Dictionary<Transform, MoveVec> MoveVecDic;
|
|
|
+ public static Dictionary<Transform, Move> MoveDic;
|
|
|
+ public static Dictionary<Transform, Shake> ShakeDic;
|
|
|
public static Dictionary<Transform, TweenSr> TweenSrDic;
|
|
|
public static Dictionary<Transform, TweenCG> TweenCgDic;
|
|
|
public static Dictionary<Transform, TweenGra> TweenGraDic;
|
|
@@ -44,9 +55,9 @@ public class ManaAnim : Regist
|
|
|
|
|
|
private void FixedUpdate()
|
|
|
{
|
|
|
- for (int i = 0; i < MoveList.Count; i++)
|
|
|
+ for (int i = 0; i < AnimList.Count; i++)
|
|
|
{
|
|
|
- if (MoveList[i].DoMove())
|
|
|
+ if (AnimList[i].Do())
|
|
|
{
|
|
|
i--;
|
|
|
}
|
|
@@ -72,15 +83,19 @@ public class ManaAnim : Regist
|
|
|
|
|
|
public override void RegistValueA()
|
|
|
{
|
|
|
- MoveList = new List<Move>();
|
|
|
+ AnimList = new List<Anim>();
|
|
|
TweenForList = new List<Tween>();
|
|
|
TweenBacList = new List<Tween>();
|
|
|
|
|
|
- FunctionDicF = new Dictionary<Curve, CurveFunctionF>();
|
|
|
- FunctionDicC = new Dictionary<Curve, CurveFunctionC>();
|
|
|
- FunctionDicV = new Dictionary<Curve, CurveFunctionV>();
|
|
|
+ CurveFunctionDicF = new Dictionary<Curve, CurveFunctionF>();
|
|
|
+ CurveFunctionDicC = new Dictionary<Curve, CurveFunctionC>();
|
|
|
+ CurveFunctionDicV = new Dictionary<Curve, CurveFunctionV>();
|
|
|
+ ShakeFunctionDicF = new Dictionary<Curve, ShakeFunctionF>();
|
|
|
+ ShakeFunctionDicC = new Dictionary<Curve, ShakeFunctionC>();
|
|
|
+ ShakeFunctionDicV = new Dictionary<Curve, ShakeFunctionV>();
|
|
|
|
|
|
- MoveVecDic = new Dictionary<Transform, MoveVec>();
|
|
|
+ MoveDic = new Dictionary<Transform, Move>();
|
|
|
+ ShakeDic = new Dictionary<Transform, Shake>();
|
|
|
TweenSrDic = new Dictionary<Transform, TweenSr>();
|
|
|
TweenCgDic = new Dictionary<Transform, TweenCG>();
|
|
|
TweenGraDic = new Dictionary<Transform, TweenGra>();
|
|
@@ -90,19 +105,245 @@ public class ManaAnim : Regist
|
|
|
TweenScaleDic = new Dictionary<Transform, TweenScale>();
|
|
|
TweenAudioDic = new Dictionary<Transform, TweenAudio>();
|
|
|
|
|
|
- FunctionDicF.Add(Curve.Linear, Linear);
|
|
|
- FunctionDicF.Add(Curve.EaseOutQuad, EaseOutQuad);
|
|
|
+ ShakeFunctionDicF.Add(Curve.Linear, ShakeLinear);
|
|
|
+ ShakeFunctionDicF.Add(Curve.EaseOutQuad, ShakeEaseOutQuad);
|
|
|
+
|
|
|
+ ShakeFunctionDicC.Add(Curve.Linear, ShakeLinear);
|
|
|
+ ShakeFunctionDicC.Add(Curve.EaseOutQuad, ShakeEaseOutQuad);
|
|
|
+
|
|
|
+ ShakeFunctionDicV.Add(Curve.Linear, ShakeLinear);
|
|
|
+ ShakeFunctionDicV.Add(Curve.EaseOutQuad, ShakeEaseOutQuad);
|
|
|
|
|
|
- FunctionDicC.Add(Curve.Linear, Linear);
|
|
|
- FunctionDicC.Add(Curve.EaseOutQuad, EaseOutQuad);
|
|
|
+ CurveFunctionDicF.Add(Curve.Linear, Linear);
|
|
|
+ CurveFunctionDicF.Add(Curve.EaseOutQuad, EaseOutQuad);
|
|
|
|
|
|
- FunctionDicV.Add(Curve.Linear, Linear);
|
|
|
- FunctionDicV.Add(Curve.EaseOutQuad, EaseOutQuad);
|
|
|
+ CurveFunctionDicC.Add(Curve.Linear, Linear);
|
|
|
+ CurveFunctionDicC.Add(Curve.EaseOutQuad, EaseOutQuad);
|
|
|
+
|
|
|
+ CurveFunctionDicV.Add(Curve.Linear, Linear);
|
|
|
+ CurveFunctionDicV.Add(Curve.EaseOutQuad, EaseOutQuad);
|
|
|
}
|
|
|
|
|
|
|
|
|
#region 曲线
|
|
|
|
|
|
+ public static float LinearTimer(float value, float duration, float start, float delta)
|
|
|
+ {
|
|
|
+ return (value - start) * duration / delta;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static float EaseOutQuadTimer(float value, float duration, float start, float delta)
|
|
|
+ {
|
|
|
+ return ((2 - Mathf.Sqrt(4 - 4*(value - start)/delta))/2)*duration;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static float ShakeLinear(float timer, float duration, int repeat, float start, float strength)
|
|
|
+ {
|
|
|
+ float sliceTime = duration/(4*repeat);
|
|
|
+
|
|
|
+ for (int i = 0; i < repeat*4; i += 4)
|
|
|
+ {
|
|
|
+ if (timer > duration)
|
|
|
+ {
|
|
|
+ return start;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (timer <= (i + 1) * sliceTime)
|
|
|
+ {
|
|
|
+ timer -= (i)*sliceTime;
|
|
|
+
|
|
|
+ return Linear(timer, sliceTime, start, strength/(i/4 + 1));
|
|
|
+ }
|
|
|
+ else if (timer <= (i + 3)*sliceTime)
|
|
|
+ {
|
|
|
+ timer -= (i + 1)*sliceTime;
|
|
|
+
|
|
|
+ return Linear(timer, 2*sliceTime, start + strength/(i/4 + 1), -2*strength/(i/4 + 1));
|
|
|
+ }
|
|
|
+ else if (timer <= (i + 4)*sliceTime)
|
|
|
+ {
|
|
|
+ timer -= (i + 3)*sliceTime;
|
|
|
+
|
|
|
+ return Linear(timer, sliceTime, start - strength/(i/4 + 1), strength/(i/4 + 1));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ throw new Exception();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Color ShakeLinear(float timer, float duration, int repeat, Color start, Color strength)
|
|
|
+ {
|
|
|
+ float sliceTime = duration / (4 * repeat);
|
|
|
+
|
|
|
+ for (int i = 0; i < repeat * 4; i += 4)
|
|
|
+ {
|
|
|
+ if (timer > duration)
|
|
|
+ {
|
|
|
+ return start;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (timer <= (i + 1) * sliceTime)
|
|
|
+ {
|
|
|
+ timer -= (i) * sliceTime;
|
|
|
+
|
|
|
+ return Linear(timer, sliceTime, start, strength / (i / 4 + 1));
|
|
|
+ }
|
|
|
+ else if (timer <= (i + 3) * sliceTime)
|
|
|
+ {
|
|
|
+ timer -= (i + 1) * sliceTime;
|
|
|
+
|
|
|
+ return Linear(timer, 2 * sliceTime, start + strength / (i / 4 + 1), -2 * strength / (i / 4 + 1));
|
|
|
+ }
|
|
|
+ else if (timer <= (i + 4) * sliceTime)
|
|
|
+ {
|
|
|
+ timer -= (i + 3) * sliceTime;
|
|
|
+
|
|
|
+ return Linear(timer, sliceTime, start - strength / (i / 4 + 1), strength / (i / 4 + 1));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ throw new Exception();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Vector3 ShakeLinear(float timer, float duration, int repeat, Vector3 start, Vector3 strength)
|
|
|
+ {
|
|
|
+ float sliceTime = duration / (4 * repeat);
|
|
|
+
|
|
|
+ for (int i = 0; i < repeat * 4; i += 4)
|
|
|
+ {
|
|
|
+ if (timer > duration)
|
|
|
+ {
|
|
|
+ return start;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (timer <= (i + 1) * sliceTime)
|
|
|
+ {
|
|
|
+ timer -= (i) * sliceTime;
|
|
|
+
|
|
|
+ return Linear(timer, sliceTime, start, strength / (i / 4 + 1));
|
|
|
+ }
|
|
|
+ else if (timer <= (i + 3) * sliceTime)
|
|
|
+ {
|
|
|
+ timer -= (i + 1) * sliceTime;
|
|
|
+
|
|
|
+ return Linear(timer, 2 * sliceTime, start + strength / (i / 4 + 1), -2 * strength / (i / 4 + 1));
|
|
|
+ }
|
|
|
+ else if (timer <= (i + 4) * sliceTime)
|
|
|
+ {
|
|
|
+ timer -= (i + 3) * sliceTime;
|
|
|
+
|
|
|
+ return Linear(timer, sliceTime, start - strength / (i / 4 + 1), strength / (i / 4 + 1));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ throw new Exception();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static float ShakeEaseOutQuad(float timer, float duration, int repeat, float start, float strength)
|
|
|
+ {
|
|
|
+ float sliceTime = duration / (4 * repeat);
|
|
|
+
|
|
|
+ for (int i = 0; i < repeat * 4; i += 4)
|
|
|
+ {
|
|
|
+ if (timer > duration)
|
|
|
+ {
|
|
|
+ return start;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (timer <= (i + 1) * sliceTime)
|
|
|
+ {
|
|
|
+ timer -= (i) * sliceTime;
|
|
|
+
|
|
|
+ return EaseOutQuad(timer, sliceTime, start, strength / (i / 4 + 1));
|
|
|
+ }
|
|
|
+ else if (timer <= (i + 3) * sliceTime)
|
|
|
+ {
|
|
|
+ timer -= (i + 1) * sliceTime;
|
|
|
+
|
|
|
+ return EaseOutQuad(timer, 2 * sliceTime, start + strength / (i / 4 + 1), -2 * strength / (i / 4 + 1));
|
|
|
+ }
|
|
|
+ else if (timer <= (i + 4) * sliceTime)
|
|
|
+ {
|
|
|
+ timer -= (i + 3) * sliceTime;
|
|
|
+
|
|
|
+ return EaseOutQuad(timer, sliceTime, start - strength / (i / 4 + 1), strength / (i / 4 + 1));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ throw new Exception();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Color ShakeEaseOutQuad(float timer, float duration, int repeat, Color start, Color strength)
|
|
|
+ {
|
|
|
+ float sliceTime = duration / (4 * repeat);
|
|
|
+
|
|
|
+ for (int i = 0; i < repeat * 4; i += 4)
|
|
|
+ {
|
|
|
+ if (timer > duration)
|
|
|
+ {
|
|
|
+ return start;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (timer <= (i + 1) * sliceTime)
|
|
|
+ {
|
|
|
+ timer -= (i) * sliceTime;
|
|
|
+
|
|
|
+ return EaseOutQuad(timer, sliceTime, start, strength / (i / 4 + 1));
|
|
|
+ }
|
|
|
+ else if (timer <= (i + 3) * sliceTime)
|
|
|
+ {
|
|
|
+ timer -= (i + 1) * sliceTime;
|
|
|
+
|
|
|
+ return EaseOutQuad(timer, 2 * sliceTime, start + strength / (i / 4 + 1), -2 * strength / (i / 4 + 1));
|
|
|
+ }
|
|
|
+ else if (timer <= (i + 4) * sliceTime)
|
|
|
+ {
|
|
|
+ timer -= (i + 3) * sliceTime;
|
|
|
+
|
|
|
+ return EaseOutQuad(timer, sliceTime, start - strength / (i / 4 + 1), strength / (i / 4 + 1));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ throw new Exception();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Vector3 ShakeEaseOutQuad(float timer, float duration, int repeat, Vector3 start, Vector3 strength)
|
|
|
+ {
|
|
|
+ float sliceTime = duration / (4 * repeat);
|
|
|
+
|
|
|
+ for (int i = 0; i < repeat * 4; i += 4)
|
|
|
+ {
|
|
|
+ if (timer > duration)
|
|
|
+ {
|
|
|
+ return start;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (timer <= (i + 1) * sliceTime)
|
|
|
+ {
|
|
|
+ timer -= (i) * sliceTime;
|
|
|
+
|
|
|
+ return EaseOutQuad(timer, sliceTime, start, strength / (i / 4 + 1));
|
|
|
+ }
|
|
|
+ else if (timer <= (i + 3) * sliceTime)
|
|
|
+ {
|
|
|
+ timer -= (i + 1) * sliceTime;
|
|
|
+
|
|
|
+ return EaseOutQuad(timer, 2 * sliceTime, start + strength / (i / 4 + 1), -2 * strength / (i / 4 + 1));
|
|
|
+ }
|
|
|
+ else if (timer <= (i + 4) * sliceTime)
|
|
|
+ {
|
|
|
+ timer -= (i + 3) * sliceTime;
|
|
|
+
|
|
|
+ return EaseOutQuad(timer, sliceTime, start - strength / (i / 4 + 1), strength / (i / 4 + 1));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ throw new Exception();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public static float Linear(float timer, float duration, float start, float delta)
|
|
|
{
|
|
|
if (Math.Abs(duration) < 0.0005f)
|
|
@@ -154,19 +395,35 @@ public class ManaAnim : Regist
|
|
|
|
|
|
#region 播放动画
|
|
|
|
|
|
- public static void MoveVec(Transform target, Vector3 destination, float duration, Curve curve)
|
|
|
+ public static void Move(Transform target, Vector3 destination, float duration, Curve curve)
|
|
|
{
|
|
|
- MoveVec moveVec;
|
|
|
+ Move move;
|
|
|
|
|
|
- if (MoveVecDic.TryGetValue(target, out moveVec))
|
|
|
+ if (MoveDic.TryGetValue(target, out move))
|
|
|
{
|
|
|
- moveVec.StartMove(destination, duration, curve);
|
|
|
+ move.StartMove(destination, duration, curve);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- moveVec = CreateMoveVec(target);
|
|
|
+ move = CreateMove(target);
|
|
|
|
|
|
- moveVec.StartMove(destination, duration, curve);
|
|
|
+ move.StartMove(destination, duration, curve);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void Shake(Transform target, float duration, int repeat, Vector3 strength, Curve curve)
|
|
|
+ {
|
|
|
+ Shake shake;
|
|
|
+
|
|
|
+ if (ShakeDic.TryGetValue(target, out shake))
|
|
|
+ {
|
|
|
+ shake.StartShake(repeat, duration, strength, curve);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ shake = CreateShake(target);
|
|
|
+
|
|
|
+ shake.StartShake(repeat, duration, strength, curve);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -626,13 +883,27 @@ public class ManaAnim : Regist
|
|
|
|
|
|
#region 得到动画
|
|
|
|
|
|
- public static MoveVec GetMoveVec(Transform target)
|
|
|
+ public static Move GetMove(Transform target)
|
|
|
{
|
|
|
- MoveVec moveVec;
|
|
|
+ Move move;
|
|
|
|
|
|
- if (MoveVecDic.TryGetValue(target, out moveVec))
|
|
|
+ if (MoveDic.TryGetValue(target, out move))
|
|
|
{
|
|
|
- return moveVec;
|
|
|
+ return move;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ throw new Exception();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Shake GetShake(Transform target)
|
|
|
+ {
|
|
|
+ Shake shake;
|
|
|
+
|
|
|
+ if (ShakeDic.TryGetValue(target, out shake))
|
|
|
+ {
|
|
|
+ return shake;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -655,7 +926,6 @@ public class ManaAnim : Regist
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
public static TweenCG GetTweenCG(Transform target)
|
|
|
{
|
|
|
TweenCG tweenCG;
|
|
@@ -758,26 +1028,46 @@ public class ManaAnim : Regist
|
|
|
|
|
|
#region 创建动画
|
|
|
|
|
|
- public static MoveVec CreateMoveVec(Transform target)
|
|
|
+ public static Move CreateMove(Transform target)
|
|
|
{
|
|
|
- if (MoveVecDic.ContainsKey(target))
|
|
|
+ if (MoveDic.ContainsKey(target))
|
|
|
{
|
|
|
- MoveVec move = MoveVecDic[target];
|
|
|
+ Move move = MoveDic[target];
|
|
|
|
|
|
- move = new MoveVec(target);
|
|
|
+ move = new Move(target);
|
|
|
|
|
|
return move;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- MoveVec move = new MoveVec(target);
|
|
|
+ Move move = new Move(target);
|
|
|
|
|
|
- MoveVecDic.Add(target, move);
|
|
|
+ MoveDic.Add(target, move);
|
|
|
|
|
|
return move;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static Shake CreateShake(Transform target)
|
|
|
+ {
|
|
|
+ if (ShakeDic.ContainsKey(target))
|
|
|
+ {
|
|
|
+ Shake shake = ShakeDic[target];
|
|
|
+
|
|
|
+ shake = new Shake(target);
|
|
|
+
|
|
|
+ return shake;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Shake shake = new Shake(target);
|
|
|
+
|
|
|
+ ShakeDic.Add(target, shake);
|
|
|
+
|
|
|
+ return shake;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public static TweenSr CreateTweenSr(Transform target, Color origin, Color destination, float duration, bool originActive, bool destActive, Curve curve)
|
|
|
{
|
|
@@ -827,7 +1117,6 @@ public class ManaAnim : Regist
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
public static TweenCG CreateTweenCG(Transform target, float origin, float destination, float duration, bool originActive, bool destActive, Curve curve)
|
|
|
{
|
|
|
if (TweenCgDic.ContainsKey(target))
|