public static float Ease(int esType, float t) { switch (esType) { case EsType.Quad: case EsType.QuadIn: return(t * t); case EsType.QuadOut: return(t * (2 - t)); case EsType.QuadInOut: return((t *= 2) < 1 ? .5f * t * t : .5f * (1 - (t - 1) * (t - 3))); case EsType.Cubic: case EsType.CubicIn: return(t * t * t); case EsType.CubicOut: return((t -= 1) * t * t + 1); case EsType.CubicInOut: return((t *= 2) < 1 ? .5f * t * t * t : .5f * ((t -= 2) * t * t + 2)); case EsType.Quart: case EsType.QuartIn: return(t * t * t * t); case EsType.QuartOut: return(1 - (t -= 1) * t * t * t); case EsType.QuartInOut: return((t *= 2) < 1 ? .5f * t * t * t * t : .5f * (2 - (t -= 2) * t * t * t)); case EsType.Quint: case EsType.QuintIn: return(t * t * t * t * t); case EsType.QuintOut: return((t -= 1) * t * t * t * t + 1); case EsType.QuintInOut: return((t *= 2) < 1 ? .5f * t * t * t * t * t : .5f * ((t -= 2) * t * t * t * t + 2)); case EsType.Sine: case EsType.SineIn: return(1 - (float)Math.Cos(t * HalfPi)); case EsType.SineOut: return((float)Math.Sin(t * HalfPi)); case EsType.SineInOut: return(.5f * (1 - (float)Math.Cos(t * Pi))); case EsType.Expo: case EsType.ExpoIn: return((float)Math.Exp(7 * (t - 1))); case EsType.ExpoOut: return(1 - (float)Math.Exp(-7 * t)); case EsType.ExpoInOut: return((t *= 2) < 1 ? .5f * (float)Math.Exp(7 * (t - 1)) : .5f * (2 - (float)Math.Exp(-7 * (t - 1)))); case EsType.Circ: case EsType.CircIn: return(1 - (float)Math.Sqrt(1 - t * t)); case EsType.CircOut: return((float)Math.Sqrt(1 - (t -= 1) * t)); case EsType.CircInOut: return((t *= 2) < 1 ? .5f * (1 - (float)Math.Sqrt(1 - t * t)) : .5f * ((float)Math.Sqrt(1 - (t -= 2) * t) + 1)); case EsType.Back: case EsType.BackIn: return(t * t * (2.70158f * t - 1.70158f)); case EsType.BackOut: return((t -= 1) * t * (2.70158f * t + 1.70158f) + 1); case EsType.BackInOut: return((t *= 2) < 1 ? .5f * (t * t * (3.5949095f * t - 2.5949095f)) : .5f * ((t -= 2) * t * (3.5949095f * t + 2.5949095f) + 2)); case EsType.Elastic: case EsType.ElasticIn: return((float)(-Math.Exp(7 * (t -= 1)) * Math.Sin((t - 0.075) * 20.9439510239))); case EsType.ElasticOut: return((float)(Math.Exp(-7 * t) * Math.Sin((t - 0.075) * 20.9439510239) + 1)); case EsType.ElasticInOut: return((t *= 2) < 1 ? (float)(-.5 * Math.Exp(7 * (t -= 1)) * Math.Sin((t - 0.1125) * 13.962634016)) : (float)(Math.Exp(-7 * (t -= 1)) * Math.Sin((t - 0.1125) * 13.962634016) * .5 + 1)); case EsType.Bounce: case EsType.BounceIn: return(1 - Es.Ease(EsType.BounceOut, 1 - t)); case EsType.BounceOut: return(t < 0.363636363636f ? 7.5625f * t * t : t < 0.727272727273f ? 7.5625f * (t -= 0.545454545455f) * t + .75f : t < 0.909090909091f ? 7.5625f * (t -= 0.818181818182f) * t + .9375f : 7.5625f * (t -= 0.954545454545f) * t + .984375f); case EsType.BounceInOut: return((t *= 2) < 1 ? .5f * (1 - Es.Ease(EsType.BounceOut, 1 - t)) : .5f * (Es.Ease(EsType.BounceOut, t - 1) + 1)); } return(t); }
public void Update(float deltaTime) { time += deltaTime; // execute commands if (time > waitEndTime) { while (time > waitEndTime && cmdQueue.Count > 0) { var cmd = cmdQueue.Dequeue(); switch (cmd.GetType().Name) { case "WaitCmd": Wait(cmd as WaitCmd); break; case "AddImgCmd": AddImg(cmd as AddImgCmd); break; case "RmImgCmd": RmImg(cmd as RmImgCmd); break; case "SetImgAttrCmd": SetImgAttr(cmd as SetImgAttrCmd); break; case "SetImgAttrEasedCmd": SetImgAttrEased(cmd as SetImgAttrEasedCmd); break; case "SetCamAttrCmd": SetCamAttr(cmd as SetCamAttrCmd); break; case "SetCamAttrEasedCmd": SetCamAttrEased(cmd as SetCamAttrEasedCmd); break; } } } // execute easing jobs for (var node = esJobList.First; node != null;) { var next = node.Next; var job = node.Value; if ((job.time += deltaTime) > job.duration) { job.Finish(); esJobList.Remove(node); } else { job.Apply(Es.Ease(job.esType, job.time / job.duration)); } node = next; } // sort if (needDepthSort) { needDepthSort = false; Algo.MergeSort(spritePtrLst->arr, spritePtrLst->count, TpSprite.DepthCmp); } var arr = (TpSprite **)spritePtrLst->arr; // mouse (0 for left button, 1 for right button, 2 for the middle button) for (int m = 0; m <= 2; m += 1) { int phase = TchPhase.FromUnityMouse(m); if (phase == TchPhase.None) { continue; } var pos = cam.ScreenToWorldPoint(UnityEngine.Input.mousePosition); float x = pos.x, y = pos.y; for (int i = spritePtrLst->count - 1; i >= 0; i -= 1) { int id = arr[i]->id; if (nodeTouchHandlerDict.ContainsKey(id) && TpSprite.Raycast(arr[i], x, y)) // has a handler && pos in sprite { nodeTouchHandlerDict[id].Invoke(TchPhase.FromUnityMouse(m), x, y); break; } } } // touch var touches = UnityEngine.Input.touches; foreach (var touch in touches) { var pos = cam.ScreenToWorldPoint(touch.position); float x = pos.x, y = pos.y; for (int i = spritePtrLst->count - 1; i >= 0; i -= 1) { int id = arr[i]->id; if (nodeTouchHandlerDict.ContainsKey(id) && TpSprite.Raycast(arr[i], x, y)) // has a handler && pos in sprite { nodeTouchHandlerDict[id].Invoke(TchPhase.FromUnityTouch(touch.phase), x, y); break; } } } // draw DrawCtx.Start(); for (int i = 0, end = spritePtrLst->count; i < end; i += 1) { Node.Draw(arr[i], null, false); } DrawCtx.Finish(); }