public int AddFrame(int animationIndex, VFrame frame) { VAnimation anim = animations[animationIndex]; anim.AddFrame(frame); for (int layer = 0; layer < GetLayerCount(); layer++) { chunks.Add(new VTileChunk(layer, animationIndex, anim.GetFrameCount() - 1, width, height, depth)); } SetDirty(); return(anim.GetFrameCount() - 1); }
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()); } }
public int AddAnimation(VAnimation anim) { animations.Add(anim); for (int layer = 0; layer < GetLayerCount(); layer++) { for (int frame = 0; frame < anim.GetFrameCount(); frame++) { chunks.Add(new VTileChunk(layer, animations.Count - 1, frame, width, height, depth)); } } SetDirty(); return(animations.Count - 1); }
public void InsertAnimation(int index, VAnimation anim) { foreach (VChunk chunk in chunks) { if (chunk.GetAnimationIndex() >= index) { chunk.SetAnimationIndex(chunk.GetAnimationIndex() + 1); } } animations.Insert(index, anim); for (int layer = 0; layer < GetLayerCount(); layer++) { for (int frame = 0; frame < anim.GetFrameCount(); frame++) { chunks.Add(new VTileChunk(layer, index, frame, width, height, depth)); } } SetDirty(); }
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()); } }