void Update() { VAnimation anim = ed.tile.GetAnimation(ed.tile.GetAnimationIndex()); if (playAnimation) { animationTime += Time.deltaTime; if (loopAnimation) { animationTime %= anim.GetDuration(); } else if (animationTime >= anim.GetDuration()) { playAnimation = false; } } if (playAnimation) { float frameTime = 0f; for (int i = 0; i < anim.GetFrameCount(); i++) { if (i != ed.tile.GetFrameIndex() && animationTime >= frameTime && animationTime < frameTime + anim.GetFrame(i).GetDuration()) { actQueue.Enqueue(new ChangeFrameIndexAct(i)); } frameTime += anim.GetFrame(i).GetDuration(); } } while (actQueue.Count > 0) { Edit.Do(actQueue.Dequeue()); } }
void Frames() { int index = ed.tile.GetFrameIndex(); int animIndex = ed.tile.GetAnimationIndex(); if (animIndex >= ed.tile.GetAnimationCount()) { return; } VAnimation anim = ed.tile.GetAnimation(animIndex); int count = anim.GetFrameCount(); GUILayout.BeginVertical("box"); showFrames = GUILayout.Toggle(showFrames, "Timeline", "boxhead"); if (showFrames) { GUILayout.BeginHorizontal(); GUILayout.Label("Frames"); if (count > 1 && index < count && GUILayout.Button("-", GUILayout.Width(20))) { actQueue.Enqueue(new RemoveFrameAct(animIndex, index)); } for (int i = 0; i < count; i++) { if (GUILayout.Toggle(i == index, "" + i, "button") && i != index) { actQueue.Enqueue(new ChangeFrameIndexAct(i)); } } GUILayout.FlexibleSpace(); if (GUILayout.Button("+", GUILayout.Width(20))) { actQueue.Enqueue(new AddFrameAct(animIndex)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Frame Duration"); float duration; if (float.TryParse(GUILayout.TextField(anim.GetFrame(index).GetDuration().ToString(), GUILayout.Width(50)), out duration)) { if (duration != anim.GetFrame(index).GetDuration()) { actQueue.Enqueue(new ChangeFrameInfoAct(animIndex, index, duration)); } } GUILayout.FlexibleSpace(); GUILayout.Label("Playback"); bool play = GUILayout.Toggle(playAnimation, "Play", "button"); if (play != playAnimation) { animationTime = 0f; playAnimation = play; } loopAnimation = GUILayout.Toggle(loopAnimation, "Loop", "button"); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); if (repaint) { boxRects.Add(GUILayoutUtility.GetLastRect()); } }