Ejemplo n.º 1
0
        void DrawFrameInspector()
        {
            GUILayout.Label("Frame", EditorStyles.largeLabel, GUILayout.ExpandWidth(true));

            FrameGroup fg = frameGroups[timelineEditor.CurrentState.selectedFrame];

            tk2dSpriteGuiUtility.SpriteSelector(fg.spriteCollection, fg.spriteId, spriteChangedCallbackInstance, fg);

            int numFrames = EditorGUILayout.IntField("Frames", fg.frames.Count);

            if (numFrames != fg.frames.Count && numFrames > 0)
            {
                if (fg.SetFrameCount(numFrames))
                {
                    RecalculateFrames();
                    Repaint();
                }
            }

            float time0 = fg.frames.Count / clip.fps;
            float time  = EditorGUILayout.FloatField("Time", time0);

            if (time != time0)
            {
                int frameCount = Mathf.Max(1, (int)Mathf.Ceil(time * clip.fps));
                if (fg.SetFrameCount(frameCount))
                {
                    RecalculateFrames();
                    Repaint();
                }
            }

            // Tools
            GUILayout.Space(8);
            GUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(" ");
            GUILayout.BeginVertical();
            bool changed = false;

            foreach (tk2dEditor.SpriteAnimationEditor.AnimOperator animOp in animOps)
            {
                changed = animOp.OnFrameGroupInspectorGUI(clip, frameGroups, timelineEditor.CurrentState);
                if ((animOp.AnimEditOperations & tk2dEditor.SpriteAnimationEditor.AnimEditOperations.ClipContentChanged) != tk2dEditor.SpriteAnimationEditor.AnimEditOperations.None)
                {
                    RecalculateFrames();
                    changed = true;
                }
            }
            if (changed)
            {
                Repaint();
            }
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
        }
        void DrawFrameInspector()
        {
            GUILayout.Label("Frame", EditorStyles.largeLabel, GUILayout.ExpandWidth(true));

            FrameGroup fg            = frameGroups[timelineEditor.CurrentState.selectedFrame];
            bool       spriteChanged = false;

            tk2dSpriteCollectionData newCollection = tk2dSpriteGuiUtility.SpriteCollectionPopup("Collection", fg.spriteCollection, true, fg.spriteId);

            if (newCollection != fg.spriteCollection)
            {
                fg.spriteCollection = newCollection;
                if (fg.spriteId < 0 || fg.spriteId >= fg.spriteCollection.Count ||
                    !fg.spriteCollection.inst.spriteDefinitions[fg.spriteId].Valid)
                {
                    fg.spriteId = fg.spriteCollection.FirstValidDefinitionIndex;
                }
                spriteChanged = true;
            }

            if (fg.spriteCollection != null)
            {
                int spriteId = tk2dSpriteGuiUtility.SpriteSelectorPopup("Sprite", fg.spriteId, fg.spriteCollection);
                if (spriteId != fg.spriteId)
                {
                    fg.spriteId   = spriteId;
                    spriteChanged = true;
                }
            }

            int numFrames = EditorGUILayout.IntField("Frames", fg.frames.Count);

            if (numFrames != fg.frames.Count && numFrames > 0)
            {
                if (fg.SetFrameCount(numFrames))
                {
                    RecalculateFrames();
                    Repaint();
                }
            }

            float time0 = fg.frames.Count / clip.fps;
            float time  = EditorGUILayout.FloatField("Time", time0);

            if (time != time0)
            {
                int frameCount = Mathf.Max(1, (int)Mathf.Ceil(time * clip.fps));
                if (fg.SetFrameCount(frameCount))
                {
                    RecalculateFrames();
                    Repaint();
                }
            }

            if (spriteChanged)
            {
                foreach (tk2dSpriteAnimationFrame frame in fg.frames)
                {
                    frame.spriteCollection = fg.spriteCollection;
                    frame.spriteId         = fg.spriteId;
                    RecalculateFrames();
                }
            }

            // Tools
            GUILayout.Space(8);
            GUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(" ");
            GUILayout.BeginVertical();
            bool changed = false;

            foreach (tk2dEditor.SpriteAnimationEditor.AnimOperator animOp in animOps)
            {
                changed = animOp.OnFrameGroupInspectorGUI(clip, frameGroups, timelineEditor.CurrentState);
                if ((animOp.AnimEditOperations & tk2dEditor.SpriteAnimationEditor.AnimEditOperations.ClipContentChanged) != tk2dEditor.SpriteAnimationEditor.AnimEditOperations.None)
                {
                    RecalculateFrames();
                    changed = true;
                }
            }
            if (changed)
            {
                Repaint();
            }
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
        }