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();
                }
            }
        }
Example #2
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;
            }
        }