예제 #1
0
        void OnGUI()
        {
            AMTimeline.loadSkin(ref skin, ref cachedSkinName, position);
            if (aData == null)
            {
                AMTimeline.MessageBox("Animator requires an AnimatorData component in your scene. Launch Animator to add the component.", AMTimeline.MessageBoxType.Warning);
                return;
            }

            //AMTake curTake = aData.getCurrentTake();

            GUIStyle styleArea = new GUIStyle(GUI.skin.scrollView);

            styleArea.padding = new RectOffset(4, 4, 4, 4);
            GUILayout.BeginArea(new Rect(0f, 0f, position.width, position.height), styleArea);
            //GUILayout.Label("Take: " + curTake.name + " of "+aData.gameObject.name + " "+curTake.GetHashCode());
            GUILayout.Label("Loop");
            GUILayout.Space(2f);
            GUILayout.BeginHorizontal(GUI.skin.box);
            EditorGUIUtility.labelWidth = 50f; EditorGUIUtility.fieldWidth = 100f;
            loopCount = EditorGUILayout.IntField("Count", loopCount);
            if (loopCount < 0)
            {
                loopCount = -1;
            }
            loopMode = (LoopType)EditorGUILayout.EnumPopup("Mode", loopMode);
            GUILayout.EndHorizontal();

            AMEditorUtil.ResetDisplayControls();

            GUILayout.Space(2f);
            //pausePreviousTake = EditorGUILayout.Toggle("Pause Prev. Take", pausePreviousTake);

            GUILayout.Space(4f);
            bool loopBackFrameEnabled = loopCount < 0;

            GUI.enabled = loopBackFrameEnabled;
            GUILayout.BeginHorizontal();
            loopBackFrameCheck = EditorGUILayout.Toggle(loopBackFrameCheck, GUILayout.Width(12f));
            GUI.enabled        = loopBackFrameEnabled && loopBackFrameCheck;
            loopBackFrame      = EditorGUILayout.IntSlider("Loop Back To Frame", loopBackFrame, 1, totalFrames);
            GUILayout.EndHorizontal();
            GUI.enabled = true;
            GUILayout.Space(6f);
            GUILayout.Label("End Frame Padding");
            GUILayout.Space(2f);
            GUI.enabled     = !loopBackFrameEnabled || !loopBackFrameCheck || loopBackFrame < 0;
            endFramePadding = EditorGUILayout.IntField(endFramePadding, GUI.skin.textField, GUILayout.Width(position.width - 10f - 12f));
            if (endFramePadding < 0)
            {
                endFramePadding = 0;
            }
            GUI.enabled = true;
            GUILayout.Space(2f);
            GUILayout.Label("Frame Rate (Fps)");
            GUILayout.Space(2f);
            frameRate = EditorGUILayout.IntField(frameRate, GUI.skin.textField, GUILayout.Width(position.width - 10f - 12f));
            if (frameRate <= 0)
            {
                frameRate = 1;
            }
            GUILayout.Space(7f);
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Apply"))
            {
                saveChanges = true;
                this.Close();
            }
            if (GUILayout.Button("Cancel"))
            {
                saveChanges = false;
                this.Close();
            }
            GUILayout.EndHorizontal();
            GUILayout.EndArea();
        }
예제 #2
0
        // Use this for initialization
        void OnGUI()
        {
            AMTimeline.loadSkin(ref skin, ref cachedSkinName, position);
            GUIStyle padding = new GUIStyle();

            padding.padding = new RectOffset(4, 4, 4, 4);
            GUILayout.BeginVertical(padding);
            AMEditorUtil.ResetDisplayControls();
            GUILayout.BeginHorizontal();
            GUILayout.Label(newReference.Count + " possible duplicate" + (newReference.Count > 1 ? "s" : "") + " found:");
            GUILayout.FlexibleSpace();
            GUILayout.Label("Keep: ");
            if (GUILayout.Button("All", GUILayout.Width(width_button_action)))
            {
                for (int i = 0; i < actions.Count; i++)
                {
                    actions[i] = 0;
                }
            }
            if (GUILayout.Button("New", GUILayout.Width(width_button_action)))
            {
                for (int i = 0; i < actions.Count; i++)
                {
                    actions[i] = 1;
                }
            }
            if (GUILayout.Button("Previous", GUILayout.Width(width_button_action)))
            {
                for (int i = 0; i < actions.Count; i++)
                {
                    actions[i] = 2;
                }
            }
            GUILayout.Space(18f);
            GUILayout.EndHorizontal();
            GUILayout.Space(4f);
            GUIStyle styleScrollView = new GUIStyle(GUI.skin.scrollView);

            styleScrollView.normal.background = GUI.skin.GetStyle("GroupElementBG").onNormal.background;
            styleScrollView.padding           = new RectOffset(0, 0, 4, 4);
            scrollPos = GUILayout.BeginScrollView(scrollPos, false, true, GUI.skin.horizontalScrollbar, GUI.skin.verticalScrollbar, styleScrollView);

            int maxGameObjects = Mathf.CeilToInt((position.height - 62f) / height_gameobject);

            maxGameObjects = Mathf.Clamp(maxGameObjects, 0, newReference.Count);
            int FirstIndex = Mathf.FloorToInt(scrollPos.y / height_gameobject) - 1;

            FirstIndex = Mathf.Clamp(FirstIndex, 0, newReference.Count);
            int LastIndex = FirstIndex + maxGameObjects;

            LastIndex = Mathf.Clamp(LastIndex, 0, newReference.Count);
            if (LastIndex - FirstIndex < maxGameObjects)
            {
                FirstIndex = Mathf.Clamp(LastIndex - maxGameObjects, 0, newReference.Count);
            }

            for (int i = 0; i < newReference.Count; i++)
            {
                if (newReference.Count > maxGameObjects && (i < FirstIndex || i > LastIndex))
                {
                    GUILayout.Space(height_gameobject);
                    continue;
                }
                GUILayout.BeginHorizontal(GUILayout.Height(height_gameobject));
                GUILayout.Label("New: ", GUILayout.Width(40f));
                GUI.enabled = false;
                EditorGUILayout.ObjectField(newReference[i], typeof(GameObject), true, GUILayout.Width(width_object_field));
                GUI.enabled = true;
                GUILayout.Label("Prev: ", GUILayout.Width(40f));
                // do not allow null values
                GameObject go = (GameObject)EditorGUILayout.ObjectField(oldReference[i], typeof(GameObject), true, GUILayout.Width(width_object_field));
                if (go)
                {
                    oldReference[i] = go;
                }
                GUILayout.FlexibleSpace();
                bool keepBoth = actions[i] == 0;
                keepBoth = GUILayout.Toggle(keepBoth, "");
                GUILayout.BeginVertical();
                GUILayout.Space(height_label_offset);
                GUILayout.Label("Both", GUILayout.Width(width_toggle_label));
                GUILayout.EndVertical();
                bool keepFirst = actions[i] == 1;
                keepFirst = GUILayout.Toggle(keepFirst, "");
                GUILayout.BeginVertical();
                GUILayout.Space(height_label_offset);
                GUILayout.Label("New", GUILayout.Width(width_toggle_label));
                GUILayout.EndVertical();
                bool keepSecond = actions[i] == 2;
                keepSecond = GUILayout.Toggle(keepSecond, "");
                GUILayout.BeginVertical();
                GUILayout.Space(height_label_offset);
                GUILayout.Label("Prev.", GUILayout.Width(width_toggle_label));
                GUILayout.EndVertical();
                GUILayout.EndHorizontal();
                // set action
                if (keepBoth && actions[i] != 0)
                {
                    actions[i] = 0;
                }
                else if (keepFirst && actions[i] != 1)
                {
                    actions[i] = 1;
                }
                else if (keepSecond && actions[i] != 2)
                {
                    actions[i] = 2;
                }
            }
            GUILayout.EndScrollView();
            GUILayout.Space(4f);
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Apply"))
            {
                saveChanges();
            }
            if (GUILayout.Button("Cancel"))
            {
                this.Close();
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
        }
예제 #3
0
        void OnGUI()
        {
            AMTimeline.loadSkin(ref skin, ref cachedSkinName, position);
            if (aData == null)
            {
                AMTimeline.MessageBox("Animator requires an AnimatorData component in your scene. Launch Animator to add the component.", AMTimeline.MessageBoxType.Warning);
                return;
            }
            if (!oData)
            {
                oData = AMOptionsFile.loadFile();
            }
            GUILayout.BeginHorizontal();
            #region tab selection
            //GUI.DrawTexture(new Rect(0f,0f,120f,position.height),GUI.skin.GetStyle("GroupElementBG")/*GUI.skin.GetStyle("GroupElementBG").onNormal.background*/);
            GUIStyle styleTabSelectionBG = new GUIStyle(GUI.skin.GetStyle("GroupElementBG"));
            styleTabSelectionBG.normal.background = EditorStyles.toolbar.normal.background;
            GUILayout.BeginVertical(/*GUI.skin.GetStyle("GroupElementBG")*/ styleTabSelectionBG, GUILayout.Width(121f));
            AMEditorUtil.ResetDisplayControls();
            GUIStyle styleTabButton = new GUIStyle(EditorStyles.toolbarButton);
            styleTabButton.fontSize             = 12;
            styleTabButton.fixedHeight          = 30;
            styleTabButton.onNormal.background  = styleTabButton.onActive.background;
            styleTabButton.onFocused.background = null;
            styleTabButton.onHover.background   = null;
            tabIndex = GUILayout.SelectionGrid(tabIndex, tabNames, 1, styleTabButton);
            GUILayout.EndVertical();
            #endregion
            #region options
            GUILayout.BeginVertical();
            AMEditorUtil.ResetDisplayControls();

            GUIStyle styleArea = new GUIStyle(GUI.skin.textArea);
            scrollView = GUILayout.BeginScrollView(scrollView, styleArea);
            List <string> takeNames = getTakeNames();

            GUIStyle styleTitle = new GUIStyle(GUI.skin.label);
            styleTitle.fontSize  = 20;
            styleTitle.fontStyle = FontStyle.Bold;

            // tab title
            GUILayout.BeginHorizontal();
            GUILayout.Space(width_indent);
            GUILayout.Label(tabNames[tabIndex], styleTitle);
            GUILayout.EndHorizontal();
            GUILayout.Space(10f);

            #region general
            if (tabIndex == (int)tabType.General)
            {
                List <string> takeNamesWithNone = new List <string>(takeNames);
                takeNamesWithNone.Insert(0, "None");

                // gizmo size
                GUILayout.BeginHorizontal();
                GUILayout.Space(width_indent);
                GUILayout.BeginVertical(GUILayout.Height(26f), GUILayout.Width(80f));
                GUILayout.FlexibleSpace();
                GUILayout.Label("Gizmo size", GUILayout.Width(80f));
                GUILayout.FlexibleSpace();
                GUILayout.EndVertical();

                float newGizmoSize = GUILayout.HorizontalSlider(oData.gizmo_size, 0f, 0.1f, GUILayout.ExpandWidth(true));
                if (oData.gizmo_size != newGizmoSize)
                {
                    oData.gizmo_size             = newGizmoSize;
                    AnimatorTimeline.e_gizmoSize = newGizmoSize;
                    GUIUtility.keyboardControl   = 0;
                    EditorUtility.SetDirty(oData);
                }

                GUILayout.BeginVertical(GUILayout.Height(26f), GUILayout.Width(75f));
                GUILayout.FlexibleSpace();
                newGizmoSize = EditorGUILayout.FloatField(oData.gizmo_size, GUI.skin.textField, GUILayout.Width(75f));
                if (oData.gizmo_size != newGizmoSize)
                {
                    oData.gizmo_size             = newGizmoSize;
                    AnimatorTimeline.e_gizmoSize = newGizmoSize;
                    EditorUtility.SetDirty(oData);
                }

                GUILayout.FlexibleSpace();
                GUILayout.EndVertical();
                GUILayout.EndHorizontal();
                // pixel/unit default
                GUILayout.BeginHorizontal();
                GUILayout.Space(width_indent);
                EditorGUIUtility.labelWidth = 250.0f;
                float ppu = EditorGUILayout.FloatField("Pixel/Unit Default", oData.pixelPerUnitDefault);
                if (ppu <= 0.001f)
                {
                    ppu = 0.001f;
                }
                if (oData.pixelPerUnitDefault != ppu)
                {
                    oData.pixelPerUnitDefault = ppu;
                    // save
                    EditorUtility.SetDirty(oData);
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(4.0f);
                // dynamic max frames
                GUILayout.BeginHorizontal();
                GUILayout.Space(width_indent);
                EditorGUIUtility.labelWidth = 100.0f;
                var lastFieldWidth = EditorGUIUtility.fieldWidth;
                EditorGUIUtility.fieldWidth = 50.0f;
                int fpp = EditorGUILayout.IntField("Frames/Page", oData.framesPerPage);
                if (fpp < 15)
                {
                    fpp = 15;
                }
                if (oData.framesPerPage != fpp)
                {
                    oData.framesPerPage = fpp;
                    // save
                    EditorUtility.SetDirty(oData);
                }

                int mp = EditorGUILayout.IntField("Max Page", oData.maxPage);
                if (mp < 1)
                {
                    mp = 1;
                }
                if (oData.maxPage != mp)
                {
                    oData.maxPage = mp;
                    // save
                    EditorUtility.SetDirty(oData);
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(4.0f);
                EditorGUIUtility.fieldWidth = lastFieldWidth;
                // sprite drag/drop fps
                GUILayout.BeginHorizontal();
                GUILayout.Space(width_indent);
                EditorGUIUtility.labelWidth = 250.0f;
                int nfps = EditorGUILayout.IntField("Sprite Insert Frame/Second", oData.spriteInsertFramePerSecond);
                if (nfps <= 0)
                {
                    nfps = 1;
                }
                if (oData.spriteInsertFramePerSecond != nfps)
                {
                    oData.spriteInsertFramePerSecond = nfps;
                    // save
                    EditorUtility.SetDirty(oData);
                }
                GUILayout.EndHorizontal();
                // time instead of frame numbers
                GUILayout.BeginHorizontal();
                GUILayout.Space(width_indent);
                GUILayout.BeginVertical(GUILayout.Height(26f));
                GUILayout.FlexibleSpace();
                GUILayout.Label("Show time instead of frame numbers");
                GUILayout.FlexibleSpace();
                GUILayout.EndVertical();
                if (oData.setTimeNumbering(GUILayout.Toggle(oData.time_numbering, "")))
                {
                    // save
                    EditorUtility.SetDirty(oData);
                }
                GUILayout.EndHorizontal();
                // scrubby zoom cursor
                GUILayout.BeginHorizontal();
                GUILayout.Space(width_indent);
                GUILayout.BeginVertical(GUILayout.Height(26f));
                GUILayout.FlexibleSpace();
                GUILayout.Label("Scrubby zoom cursor");
                GUILayout.FlexibleSpace();
                GUILayout.EndVertical();
                if (oData.setScrubbyZoomCursor(GUILayout.Toggle(oData.scrubby_zoom_cursor, "")))
                {
                    // save
                    EditorUtility.SetDirty(oData);
                }
                GUILayout.EndHorizontal();
                // scrubby zoom slider
                GUILayout.BeginHorizontal();
                GUILayout.Space(width_indent);
                GUILayout.BeginVertical(GUILayout.Height(26f));
                GUILayout.FlexibleSpace();
                GUILayout.Label("Scrubby zoom slider");
                GUILayout.FlexibleSpace();
                GUILayout.EndVertical();
                if (oData.setScrubbyZoomSlider(GUILayout.Toggle(oData.scrubby_zoom_slider, "")))
                {
                    // save
                    EditorUtility.SetDirty(oData);
                }
                GUILayout.EndHorizontal();
                // show warning for lost references

                /*GUILayout.BeginHorizontal();
                 *  GUILayout.Space(width_indent);
                 *  GUILayout.BeginVertical(GUILayout.Height(26f));
                 *      GUILayout.FlexibleSpace();
                 *      GUILayout.Label ("Show warning for lost references");
                 *      GUILayout.FlexibleSpace();
                 *  GUILayout.EndVertical();
                 *  if(oData.setShowWarningForLostReferences(GUILayout.Toggle(oData.showWarningForLostReferences,""))) {
                 *      // save
                 *      EditorUtility.SetDirty(oData);
                 *  }
                 * GUILayout.EndHorizontal();*/
                // ignore minimum window size warning
                GUILayout.BeginHorizontal();
                GUILayout.Space(width_indent);
                GUILayout.BeginVertical(GUILayout.Height(26f));
                GUILayout.FlexibleSpace();
                GUILayout.Label("Ignore minimum window size warning");
                GUILayout.FlexibleSpace();
                GUILayout.EndVertical();
                if (oData.setIgnoreMinimumSizeWarning(GUILayout.Toggle(oData.ignoreMinSize, "")))
                {
                    // save
                    EditorUtility.SetDirty(oData);
                }
                GUILayout.EndHorizontal();
                // show frames for collapsed tracks
                GUILayout.BeginHorizontal();
                GUILayout.Space(width_indent);
                GUILayout.BeginVertical(GUILayout.Height(26f));
                GUILayout.FlexibleSpace();
                GUILayout.Label("Show frames for collapsed tracks");
                GUILayout.FlexibleSpace();
                GUILayout.EndVertical();
                if (oData.setShowFramesForCollapsedTracks(GUILayout.Toggle(oData.showFramesForCollapsedTracks, "")))
                {
                    // save
                    EditorUtility.SetDirty(oData);
                }
                GUILayout.EndHorizontal();
                // disable timeline actions
                GUILayout.BeginHorizontal();
                GUILayout.Space(width_indent);
                GUILayout.BeginVertical(GUILayout.Height(26f));
                GUILayout.FlexibleSpace();
                GUILayout.Label("Hide Timeline Actions (May increase editor performance)");
                GUILayout.FlexibleSpace();
                GUILayout.EndVertical();
                if (oData.setDisableTimelineActions(GUILayout.Toggle(oData.disableTimelineActions, "")))
                {
                    // save
                    EditorUtility.SetDirty(oData);
                    AMTimeline.recalculateNumFramesToRender();
                }
                GUILayout.EndHorizontal();
                // disable timeline actions tooltip
                if (oData.disableTimelineActions)
                {
                    GUI.enabled = false;
                }
                GUILayout.BeginHorizontal();
                GUILayout.Space(width_indent);
                GUILayout.BeginVertical(GUILayout.Height(26f));
                GUILayout.FlexibleSpace();
                GUILayout.Label("Enable Timeline Actions tooltip");
                GUILayout.FlexibleSpace();
                GUILayout.EndVertical();
                if (oData.disableTimelineActions)
                {
                    GUILayout.Toggle(false, "");
                }
                else
                {
                    if (oData.setDisableTimelineActionsTooltip(!GUILayout.Toggle(!oData.disableTimelineActionsTooltip, "")))
                    {
                        // save
                        EditorUtility.SetDirty(oData);
                    }
                }
                GUILayout.EndHorizontal();
            }
            #endregion
            #region quick add
            else if (tabIndex == (int)tabType.QuickAdd)
            {
                AMEditorUtil.ResetDisplayControls();
                GUILayout.Space(3f);
                GUILayout.BeginHorizontal();
                GUILayout.Space(width_indent);
                GUILayout.Label("Combinations");
                GUILayout.EndHorizontal();
                if (oData.quickAdd_Combos == null)
                {
                    oData.quickAdd_Combos = new List <List <int> >();
                }
                for (int j = 0; j < oData.quickAdd_Combos.Count; j++)
                {
                    GUILayout.Space(3f);
                    GUILayout.BeginHorizontal();
                    GUILayout.Space(width_indent);
                    for (int i = 0; i < oData.quickAdd_Combos[j].Count; i++)
                    {
                        if (oData.setQuickAddCombo(j, i, EditorGUILayout.Popup(oData.quickAdd_Combos[j][i], AMTimeline.TrackNames, GUILayout.Width(80f))))
                        {
                            oData.flatten_quickAdd_Combos();
                            EditorUtility.SetDirty(oData);
                        }
                        if (i < oData.quickAdd_Combos[j].Count - 1)
                        {
                            GUILayout.Label("+");
                        }
                    }
                    GUILayout.FlexibleSpace();
                    if (oData.quickAdd_Combos[j].Count > 0)
                    {
                        if (GUILayout.Button("-", GUILayout.Width(20f), GUILayout.Height(20f)))
                        {
                            oData.quickAdd_Combos[j].RemoveAt(oData.quickAdd_Combos[j].Count - 1);
                            if (oData.quickAdd_Combos[j].Count == 0)
                            {
                                oData.quickAdd_Combos.RemoveAt(j);
                                j--;
                            }
                            oData.flatten_quickAdd_Combos();
                            EditorUtility.SetDirty(oData);
                        }
                    }
                    if (GUILayout.Button("+", GUILayout.Width(20f), GUILayout.Height(20f)))
                    {
                        oData.quickAdd_Combos[j].Add((int)AMTimeline.Track.Translation);
                        oData.flatten_quickAdd_Combos();
                        EditorUtility.SetDirty(oData);
                    }
                    GUILayout.EndHorizontal();
                }
                GUILayout.Space(3f);
                GUILayout.BeginHorizontal();
                if (oData.quickAdd_Combos.Count <= 0)
                {
                    GUILayout.Space(width_indent);
                    GUILayout.Label("Click '+' to add a new combination");
                }
                GUILayout.FlexibleSpace();
                // new combo
                if (GUILayout.Button("+", GUILayout.Width(20f), GUILayout.Height(20f)))
                {
                    oData.quickAdd_Combos.Add(new List <int> {
                        (int)AMTimeline.Track.Translation
                    });
                    oData.flatten_quickAdd_Combos();
                    EditorUtility.SetDirty(oData);
                }
                GUILayout.EndHorizontal();
            }
            #endregion
            #region import / export
            else if (tabIndex == (int)tabType.ImportExport)
            {
                GUIStyle labelRight = new GUIStyle(GUI.skin.label);
                labelRight.alignment = TextAnchor.MiddleRight;
                GUILayout.Space(10f);
                GUILayout.BeginHorizontal(GUILayout.Width(300f));
                GUILayout.Space(width_indent);
                GUILayout.BeginVertical();
                GUILayout.Space(1f);
                GUILayout.Label("Take(s):", labelRight, GUILayout.Width(55f));
                GUILayout.EndVertical();
                GUILayout.BeginVertical();
                GUILayout.Space(1f);
                if (GUILayout.Button("Import", GUILayout.Width(60f)))
                {
                    //TODO: undo "Import Take(s)"
                    string importTakesPath = EditorUtility.OpenFilePanel("Import Take(s)", "Assets/", "unity");
                    if (importTakesPath != "")
                    {
                        AMTakeImport.openAdditiveAndDeDupe(importTakesPath);
                    }
                }
                GUILayout.EndVertical();
                GUILayout.BeginVertical();
                GUILayout.Space(1f);
                if (GUILayout.Button("Export:", GUILayout.Width(60f)))
                {
                    if (!exportAllTakes)
                    {
                        AMTakeExport.take = aData.GetTake(takeNames[exportTakeIndex]);
                    }
                    else
                    {
                        AMTakeExport.take = null;
                    }
                    //AMTakeExport.aData = aData;
                    //EditorWindow.GetWindow (typeof (AMTakeExport)).ShowUtility();
                    EditorWindow windowExport = ScriptableObject.CreateInstance <AMTakeExport>();
                    windowExport.ShowUtility();
                }
                GUILayout.EndVertical();
                GUILayout.BeginVertical();
                exportAllTakes = (GUILayout.Toggle(!exportAllTakes, "") ? false : exportAllTakes);
                GUILayout.EndVertical();
                GUILayout.BeginVertical();
                GUILayout.Space(4f);
                setExportTakeIndex(EditorGUILayout.Popup(exportTakeIndex, takeNames.ToArray(), GUILayout.Width(100f)));
                GUILayout.EndVertical();
                GUILayout.BeginVertical();
                exportAllTakes = (GUILayout.Toggle(exportAllTakes, "") ? true : exportAllTakes);
                GUILayout.EndVertical();
                GUILayout.BeginVertical();
                GUILayout.Space(2f);
                GUILayout.Label("All Takes");
                GUILayout.EndVertical();

                GUILayout.EndHorizontal();
                GUILayout.Space(3f);
                GUILayout.BeginHorizontal();
                GUILayout.Space(width_indent);
                GUILayout.Label("Options:", labelRight, GUILayout.Width(55f));
                if (GUILayout.Button("Import", GUILayout.Width(60f)))
                {
                    //TODO: undo for "Import Options"
                    string importOptionsPath = EditorUtility.OpenFilePanel("Import Options", "Assets/Animator", "unitypackage");
                    if (importOptionsPath != "")
                    {
                        AssetDatabase.ImportPackage(importOptionsPath, true);
                        this.Close();
                    }
                }
                if (GUILayout.Button("Export", GUILayout.Width(60f)))
                {
                    AMOptionsFile.export();
                }
                GUILayout.EndHorizontal();
            }
            #endregion
            #region about
            else if (tabIndex == (int)tabType.About)
            {
                GUILayout.Space(3f);

                string message = "Animator v" + version + ", Originally by Abdulla Ameen (c) 2012.  Modified by David Dionisio under the Creative Commons Attribution-NonCommercial 3.0 Unported License.\n\nPlease have a look at the documentation if you need help, or e-mail [email protected] for further assistance.";
                message += "\n\nHOTween by Daniele Giardini\n\nAdditional code contributions by:\nQuick Fingers, Eric Haines";
                GUIStyle styleInfo = new GUIStyle(GUI.skin.label);
                GUILayout.BeginHorizontal();
                GUILayout.Space(5);
                styleInfo.wordWrap = true;
                GUILayout.Label(message, styleInfo);
                GUILayout.EndHorizontal();
            }
            #endregion
            GUILayout.EndScrollView();
            GUILayout.EndVertical();
            #endregion
            GUILayout.EndHorizontal();
        }
예제 #4
0
        public override void OnInspectorGUI()
        {
            AnimatorData anim = target as AnimatorData;

            GUILayout.BeginVertical();

            //meta
            AnimatorMeta curMeta = aData.meta;
            AnimatorMeta newMeta = EditorGUILayout.ObjectField(new GUIContent("Meta", "Use data from the reference AnimatorMeta. Note: All modifications to the animation will be saved to the Meta."), curMeta, typeof(AnimatorMeta), false) as AnimatorMeta;

            if (curMeta != newMeta)
            {
                bool doIt = true;
                if (curMeta == null)
                {
                    doIt = EditorUtility.DisplayDialog("Set Meta", "Setting the Meta will replace the current animation data, proceed?", "Yes", "No");
                }

                if (doIt)
                {
                    aData.RegisterUndo("Set Meta", true);
                    aData.MetaSet(newMeta, false);
                }
            }

            MetaCommand metaComm = MetaCommand.None;

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            GUI.backgroundColor = Color.green;

            GUI.enabled = PrefabUtility.GetPrefabType(aData.gameObject) != PrefabType.Prefab && aData.metaCanSavePrefabInstance;
            if (GUILayout.Button("Save", GUILayout.Width(100f)))
            {
                metaComm = MetaCommand.Save;
            }

            GUI.enabled = true;
            if (GUILayout.Button("Save As...", GUILayout.Width(100f)))
            {
                metaComm = MetaCommand.SaveAs;
            }

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            GUI.backgroundColor = Color.red;

            GUI.enabled = PrefabUtility.GetPrefabType(aData.gameObject) != PrefabType.Prefab && aData.metaCanSavePrefabInstance;
            if (GUILayout.Button("Revert", GUILayout.Width(100f)))
            {
                metaComm = MetaCommand.Revert;
            }

            GUI.backgroundColor = Color.white;

            GUI.enabled = PrefabUtility.GetPrefabType(aData.gameObject) != PrefabType.Prefab && aData.meta;
            if (GUILayout.Button(new GUIContent("Break", "This will copy all data from AnimatorMeta to this AnimatorData, and then removes the reference to AnimatorMeta."), GUILayout.Width(100f)))
            {
                metaComm = MetaCommand.Instantiate;
            }
            GUI.enabled = true;

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            AMEditorUtil.DrawSeparator();
            //

            List <AMTakeData> takes        = aData.takes;
            string            playTakeName = aData.defaultTakeName;
            int playTakeInd = 0;

            if (!string.IsNullOrEmpty(playTakeName))
            {
                for (int i = 0; i < takes.Count; i++)
                {
                    if (takes[i].name == aData.defaultTakeName)
                    {
                        playTakeInd = i + 1;
                        break;
                    }
                }
            }

            GenerateTakeLabels();
            int newPlayTakeInd = EditorGUILayout.IntPopup("Play On Start", playTakeInd, mTakeLabels, null);

            if (newPlayTakeInd != playTakeInd)
            {
                aData.RegisterUndo("Set Play On Start", false);
                aData.defaultTakeName = newPlayTakeInd <= 0 ? "" : takes[newPlayTakeInd - 1].name;
            }

            bool isglobal = GUILayout.Toggle(aData.isGlobal, "Global");

            if (aData.isGlobal != isglobal)
            {
                aData.RegisterUndo("Set Global", false);
                aData.isGlobal = isglobal;
                if (isglobal)
                {
                    //uncheck isGlobal to any other animator data on scene
                    AnimatorData[] anims = FindObjectsOfType <AnimatorData>();
                    for (int i = 0; i < anims.Length; i++)
                    {
                        if (!aData.IsDataMatch(anims[i]) && anims[i].isGlobal)
                        {
                            anims[i].isGlobal = false;
                        }
                    }
                }
            }

            anim.sequenceLoadAll       = GUILayout.Toggle(anim.sequenceLoadAll, "Build All Sequence On Start");
            anim.sequenceKillWhenDone  = GUILayout.Toggle(anim.sequenceKillWhenDone, "Kill Sequence When Done");
            anim.playOnEnable          = GUILayout.Toggle(anim.playOnEnable, "Play On Enable");
            anim.onDisableAction       = (AnimatorData.DisableAction)EditorGUILayout.EnumPopup("On Disable", anim.onDisableAction);
            anim.updateType            = (DG.Tweening.UpdateType)EditorGUILayout.EnumPopup("Update", anim.updateType);
            anim.updateTimeIndependent = EditorGUILayout.Toggle("Time Independent", anim.updateTimeIndependent);

            if (PrefabUtility.GetPrefabType(aData.gameObject) != PrefabType.Prefab)
            {
                AMTimeline timeline = AMTimeline.window;

                if (timeline != null && aData == timeline.aData)
                {
                    if (GUILayout.Button("Deselect"))
                    {
                        timeline.aData = null;
                        timeline.Repaint();

                        if (Selection.activeGameObject == aData.gameObject)
                        {
                            Selection.activeGameObject = null;
                        }
                    }
                }
                else
                {
                    if (GUILayout.Button("Edit Timeline"))
                    {
                        if (timeline != null)
                        {
                            timeline.aData = aData;
                            timeline.Repaint();
                        }
                        else
                        {
                            EditorWindow.GetWindow(typeof(AMTimeline));
                        }
                    }
                }
            }

            //display missings
            string[] missings = aData.target.GetMissingTargets();
            if (missings != null && missings.Length > 0)
            {
                AMEditorUtil.DrawSeparator();
                mMissingsFoldout = EditorGUILayout.Foldout(mMissingsFoldout, string.Format("Missing Targets [{0}]", missings.Length));
                if (mMissingsFoldout)
                {
                    for (int i = 0; i < missings.Length; i++)
                    {
                        GUILayout.Label(missings[i]);
                    }
                }

                //fix missing targets
                if (GUILayout.Button("Generate Missing Targets"))
                {
                    aData.target.GenerateMissingTargets(missings);
                }
            }

            GUILayout.EndVertical();

            switch (metaComm)
            {
            case MetaCommand.Save:
                aData.MetaSaveInstantiate();
                GUI.changed = true;
                break;

            case MetaCommand.SaveAs:
                string path = EditorUtility.SaveFilePanelInProject("Save AnimatorMeta", aData.name + ".prefab", "prefab", "Please enter a file name to save the animator data to");
                if (!string.IsNullOrEmpty(path))
                {
                    GameObject metago = new GameObject("_meta");
                    metago.AddComponent <AnimatorMeta>();
                    UnityEngine.Object pref       = PrefabUtility.CreateEmptyPrefab(path);
                    GameObject         metagopref = PrefabUtility.ReplacePrefab(metago, pref);
                    UnityEngine.Object.DestroyImmediate(metago);
                    aData.MetaSet(metagopref.GetComponent <AnimatorMeta>(), true);
                }
                break;

            case MetaCommand.Revert:
                if (EditorUtility.DisplayDialog("Revert Animator Meta", "Are you sure?", "Yes", "No"))
                {
                    aData.RegisterUndo("Revert Animator Meta", true);
                    GameObject prefabGO = PrefabUtility.GetPrefabParent(aData.meta.gameObject) as GameObject;
                    aData.MetaSet(prefabGO ? prefabGO.GetComponent <AnimatorMeta>() : null, false);
                    GUI.changed = true;
                }
                break;

            case MetaCommand.Instantiate:
                //warning if there are missing targets
                bool doIt = true;
                if (missings != null && missings.Length > 0)
                {
                    doIt = EditorUtility.DisplayDialog("Break Animator Meta", "There are missing targets, some keys will be removed. Do you want to proceed?", "Yes", "No");
                }
                if (doIt)
                {
                    aData.RegisterUndo("Break Animator Meta", false);
                    aData.MetaSet(null, true);
                    aData.currentTakeInd = 0;
                    GUI.changed          = true;
                }
                break;
            }

            if (GUI.changed)
            {
                if (AMTimeline.window)
                {
                    AMTimeline.window.Repaint();
                }
            }
        }
예제 #5
0
        void OnGUI()
        {
            AMTimeline.loadSkin(ref skin, ref cachedSkinName, position);
            if (aData == null)
            {
                AMTimeline.MessageBox("Animator requires an AnimatorData component in your scene. Launch Animator to add the component.", AMTimeline.MessageBoxType.Warning);
                return;
            }

            if (!mTrack)
            {
                return;
            }

            Renderer render = mTrack.GetTarget(aData.target) as Renderer;

            if (!render)
            {
                AMTimeline.MessageBox("Assign a Renderer to the track first.", AMTimeline.MessageBoxType.Warning);
                return;
            }

            //select material
            Material[] mats = render.sharedMaterials;

            string[] matNames = new string[mats.Length];
            int[]    matInds  = new int[mats.Length];
            for (int i = 0; i < mats.Length; i++)
            {
                matNames[i] = mats[i].name;
                matInds[i]  = i;
            }

            //grab track info
            int      matInd         = Mathf.Clamp(mTrack.materialIndex, 0, mats.Length - 1);
            Material matOverride    = mTrack.materialOverride;
            string   shaderProperty = mTrack.property;

            //material select
            matInd = EditorGUILayout.IntPopup("Material", matInd, matNames, matInds);

            //material override select
            matOverride = EditorGUILayout.ObjectField("Material Override", matOverride, typeof(Material), false) as Material;

            Material mat = matOverride ? matOverride : mats[matInd];

            //grab material info
            string[] shaderPropertyNames, shaderPropertyDetails;
            AMMaterialTrack.ValueType[] shaderPropertyTypes;
            int[] shaderPropertyInds;
            GetPropertyInfos(mat, out shaderPropertyNames, out shaderPropertyDetails, out shaderPropertyTypes, out shaderPropertyInds);

            int shaderPropertyInd = -1;

            AMMaterialTrack.ValueType shaderPropertyType = mTrack.propertyType;

            for (int i = 0; i < shaderPropertyNames.Length; i++)
            {
                if (shaderProperty == shaderPropertyNames[i])
                {
                    shaderPropertyInd = i;

                    //special case for texture offset and scale
                    if (shaderPropertyTypes[i] == AMMaterialTrack.ValueType.TexEnv && i + 2 < shaderPropertyNames.Length)
                    {
                        if (shaderPropertyType == shaderPropertyTypes[i + 1])
                        {
                            shaderPropertyInd += 1;
                        }
                        else if (shaderPropertyType == shaderPropertyTypes[i + 2])
                        {
                            shaderPropertyInd += 2;
                        }
                    }
                    break;
                }
            }

            if (shaderPropertyInd == -1)
            {
                shaderPropertyInd = 0;
            }

            AMEditorUtil.DrawSeparator();

            //shader property select
            shaderPropertyInd = EditorGUILayout.IntPopup("Property", shaderPropertyInd, shaderPropertyDetails, shaderPropertyInds);

            shaderProperty     = shaderPropertyNames[shaderPropertyInd];
            shaderPropertyType = shaderPropertyTypes[shaderPropertyInd];

            //check for change
            if (mTrack.materialIndex != matInd || mTrack.materialOverride != matOverride || mTrack.property != shaderProperty || mTrack.propertyType != shaderPropertyType)
            {
                Undo.RecordObject(mTrack, "Material Track Property Change");

                mTrack.materialIndex    = matInd;
                mTrack.materialOverride = matOverride;
                mTrack.property         = shaderProperty;
                mTrack.propertyType     = shaderPropertyType;
            }
        }