void DrawFrameEditor(tk2dSpriteAnimationClip clip, int frameId, int frameCount) { var frame = clip.frames[frameId]; tk2dGuiUtility.BeginChangeCheck(); frame.spriteCollection = tk2dSpriteGuiUtility.SpriteCollectionPopup(frame.spriteCollection); if (tk2dGuiUtility.EndChangeCheck()) { frame.spriteId = tk2dSpriteGuiUtility.GetValidSpriteId(frame.spriteCollection, frame.spriteId); PropogateFrameChange(clip, frameId, frameCount, (dest, src) => { dest.spriteCollection = src.spriteCollection; dest.spriteId = src.spriteId; } ); } tk2dGuiUtility.BeginChangeCheck(); frame.spriteId = tk2dSpriteGuiUtility.SpriteSelectorPopup(null, frame.spriteId, frame.spriteCollection); if (tk2dGuiUtility.EndChangeCheck()) PropogateFrameChange(clip, frameId, frameCount, (dest, src) => dest.spriteId = src.spriteId ); if (tk2dPreferences.inst.groupAnimDisplay) { int newFrameCount = EditorGUILayout.Popup(frameCount, GetDurationTableForClip(clip)); if (newFrameCount != frameCount) { if (newFrameCount == 0) { deferredFrameOp = delegate(tk2dSpriteAnimationClip target) { if (frameCount == target.frames.Length) frameCount--; // don't delete last sprite if (frameCount > 0) { List<tk2dSpriteAnimationFrame> frames = new List<tk2dSpriteAnimationFrame>(target.frames); frames.RemoveRange(frameId, frameCount); target.frames = frames.ToArray(); } }; } else if (newFrameCount < frameCount) { deferredFrameOp = delegate(tk2dSpriteAnimationClip target) { int toRemove = frameCount - newFrameCount; List<tk2dSpriteAnimationFrame> frames = new List<tk2dSpriteAnimationFrame>(target.frames); frames.RemoveRange(frameId + frameCount - 1 - toRemove, toRemove); target.frames = frames.ToArray(); }; } else if (newFrameCount > frameCount) { deferredFrameOp = delegate(tk2dSpriteAnimationClip target) { int toAdd = newFrameCount - frameCount; List<tk2dSpriteAnimationFrame> frames = new List<tk2dSpriteAnimationFrame>(target.frames); var source = target.frames[frameId + frameCount - 1]; // last valid one var framesToInsert = new List<tk2dSpriteAnimationFrame>(toAdd); for (int j = 0; j < toAdd; ++j) { tk2dSpriteAnimationFrame f = new tk2dSpriteAnimationFrame(); f.CopyFrom(source, false); framesToInsert.Add(f); } frames.InsertRange(frameId + frameCount, framesToInsert); target.frames = frames.ToArray(); }; } } GUILayout.Space(8); } tk2dGuiUtility.BeginChangeCheck(); frame.triggerEvent = EditorGUILayout.Toggle("Trigger", frame.triggerEvent); if (tk2dGuiUtility.EndChangeCheck()) PropogateFrameChange(clip, frameId, frameCount, (dest, src) => dest.triggerEvent = src.triggerEvent ); if (frame.triggerEvent) { EditorGUI.indentLevel++; tk2dGuiUtility.BeginChangeCheck(); frame.eventInfo = EditorGUILayout.TextField("Info", frame.eventInfo); if (tk2dGuiUtility.EndChangeCheck()) PropogateFrameChange(clip, frameId, frameCount, (dest, src) => dest.eventInfo = src.eventInfo ); tk2dGuiUtility.BeginChangeCheck(); frame.eventFloat = EditorGUILayout.FloatField("Float", frame.eventFloat); if (tk2dGuiUtility.EndChangeCheck()) PropogateFrameChange(clip, frameId, frameCount, (dest, src) => dest.eventFloat = src.eventFloat ); tk2dGuiUtility.BeginChangeCheck(); frame.eventInt = EditorGUILayout.IntField("Int", frame.eventInt); if (tk2dGuiUtility.EndChangeCheck()) PropogateFrameChange(clip, frameId, frameCount, (dest, src) => dest.eventInt = src.eventInt ); GUILayout.Space(8); EditorGUI.indentLevel--; } }
void DrawClipEditor(tk2dSpriteAnimationClip clip) { EditorGUIUtility.LookLikeControls(80.0f, 50.0f); var frameBorderStyle = EditorStyles.textField; int clipNumFrames = clip.frames.Length; if (tk2dPreferences.inst.horizontalAnimDisplay) { scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, GUILayout.Height(144.0f)); EditorGUILayout.BeginHorizontal(); for (int i = 0; i < clipNumFrames; ++i) { int frameCount = GetFrameCount(clip, i); EditorGUILayout.BeginHorizontal(frameBorderStyle); EditorGUILayout.BeginVertical(); GUILayout.Label(new GUIContent(i.ToString(), "Frame")); // GUILayout.Label(new GUIContent((i / clip.fps).ToString("0.00" + "s"), "Time")); EditorGUILayout.EndVertical(); DrawSpritePreview(clip.frames[i].spriteCollection, clip.frames[i].spriteId); EditorGUILayout.BeginVertical(); DrawFrameEditor(clip, i, frameCount); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.Space(); i += (frameCount - 1); } DrawAddFrame(clip, false); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndScrollView(); } else { scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition); EditorGUILayout.BeginVertical(); for (int i = 0; i < clipNumFrames; ++i) { int frameCount = GetFrameCount(clip, i); EditorGUILayout.BeginHorizontal(frameBorderStyle); EditorGUILayout.BeginVertical(); GUILayout.Label(new GUIContent(i.ToString(), "Frame")); // GUILayout.Label(new GUIContent((i / clip.fps).ToString("0.00" + "s"), "Time")); EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(); DrawFrameEditor(clip, i, frameCount); EditorGUILayout.EndVertical(); DrawSpritePreview(clip.frames[i].spriteCollection, clip.frames[i].spriteId); EditorGUILayout.EndHorizontal(); i += (frameCount - 1); } DrawAddFrame(clip, true); EditorGUILayout.EndVertical(); EditorGUILayout.EndScrollView(); } if (deferredFrameOp != null) { deferredFrameOp(clip); deferredFrameOp = null; GUI.changed = true; } }
void DrawFrameEditor(tk2dSpriteAnimationClip clip, int frameId, int frameCount) { var frame = clip.frames[frameId]; tk2dGuiUtility.BeginChangeCheck(); frame.spriteCollection = tk2dSpriteGuiUtility.SpriteCollectionPopup(frame.spriteCollection); if (tk2dGuiUtility.EndChangeCheck()) { frame.spriteId = tk2dSpriteGuiUtility.GetValidSpriteId(frame.spriteCollection, frame.spriteId); PropogateFrameChange(clip, frameId, frameCount, (dest, src) => { dest.spriteCollection = src.spriteCollection; dest.spriteId = src.spriteId; }); } tk2dGuiUtility.BeginChangeCheck(); frame.spriteId = tk2dSpriteGuiUtility.SpriteSelectorPopup(null, frame.spriteId, frame.spriteCollection); if (tk2dGuiUtility.EndChangeCheck()) { PropogateFrameChange(clip, frameId, frameCount, (dest, src) => dest.spriteId = src.spriteId); } if (tk2dPreferences.inst.groupAnimDisplay) { int newFrameCount = EditorGUILayout.Popup(frameCount, GetDurationTableForClip(clip)); if (newFrameCount != frameCount) { if (newFrameCount == 0) { deferredFrameOp = delegate(tk2dSpriteAnimationClip target) { if (frameCount == target.frames.Length) { frameCount--; // don't delete last sprite } if (frameCount > 0) { List <tk2dSpriteAnimationFrame> frames = new List <tk2dSpriteAnimationFrame>(target.frames); frames.RemoveRange(frameId, frameCount); target.frames = frames.ToArray(); } }; } else if (newFrameCount < frameCount) { deferredFrameOp = delegate(tk2dSpriteAnimationClip target) { int toRemove = frameCount - newFrameCount; List <tk2dSpriteAnimationFrame> frames = new List <tk2dSpriteAnimationFrame>(target.frames); frames.RemoveRange(frameId + frameCount - 1 - toRemove, toRemove); target.frames = frames.ToArray(); }; } else if (newFrameCount > frameCount) { deferredFrameOp = delegate(tk2dSpriteAnimationClip target) { int toAdd = newFrameCount - frameCount; List <tk2dSpriteAnimationFrame> frames = new List <tk2dSpriteAnimationFrame>(target.frames); var source = target.frames[frameId + frameCount - 1]; // last valid one var framesToInsert = new List <tk2dSpriteAnimationFrame>(toAdd); for (int j = 0; j < toAdd; ++j) { tk2dSpriteAnimationFrame f = new tk2dSpriteAnimationFrame(); f.CopyFrom(source, false); framesToInsert.Add(f); } frames.InsertRange(frameId + frameCount, framesToInsert); target.frames = frames.ToArray(); }; } } GUILayout.Space(8); } tk2dGuiUtility.BeginChangeCheck(); frame.triggerEvent = EditorGUILayout.Toggle("Trigger", frame.triggerEvent); if (tk2dGuiUtility.EndChangeCheck()) { PropogateFrameChange(clip, frameId, frameCount, (dest, src) => dest.triggerEvent = src.triggerEvent); } if (frame.triggerEvent) { EditorGUI.indentLevel++; tk2dGuiUtility.BeginChangeCheck(); frame.eventInfo = EditorGUILayout.TextField("Info", frame.eventInfo); if (tk2dGuiUtility.EndChangeCheck()) { PropogateFrameChange(clip, frameId, frameCount, (dest, src) => dest.eventInfo = src.eventInfo); } tk2dGuiUtility.BeginChangeCheck(); frame.eventFloat = EditorGUILayout.FloatField("Float", frame.eventFloat); if (tk2dGuiUtility.EndChangeCheck()) { PropogateFrameChange(clip, frameId, frameCount, (dest, src) => dest.eventFloat = src.eventFloat); } tk2dGuiUtility.BeginChangeCheck(); frame.eventInt = EditorGUILayout.IntField("Int", frame.eventInt); if (tk2dGuiUtility.EndChangeCheck()) { PropogateFrameChange(clip, frameId, frameCount, (dest, src) => dest.eventInt = src.eventInt); } GUILayout.Space(8); EditorGUI.indentLevel--; } }