Exemplo n.º 1
0
    void OnGUI()
    {
        m_Animator = (Animator)EditorGUILayout.ObjectField("Animator", m_Animator, typeof(Animator), true);
        m_AnimType = (ModelImporterAnimationType)EditorGUILayout.EnumPopup("AnimType", m_AnimType);
        if (m_AnimType != ModelImporterAnimationType.Legacy)
        {
            m_AnimType = ModelImporterAnimationType.Generic;
        }

        bool bSet = (m_Animator != null);

        EUtil.PushGUIEnable(bSet);
        if (EUtil.Button("Convert Animation!", bSet ? Color.green : Color.red))
        {
            if (!m_Animator.isHuman)
            {
                EUtil.ShowNotification("The model is not in Humanoid rig!");
                return;
            }

            // save xforms recursively
            m_SavedPose = EUtil.CacheXformData(m_Animator.transform);

            m_Animator.Update(0);
#if !U5
            var ainfos = m_Animator.GetCurrentAnimationClipState(0); //only effect after Update is called
#else
            var ainfos = m_Animator.GetCurrentAnimatorClipInfo(0);   //only effect after Update is called
#endif
            if (ainfos.Length == 0)
            {
                EUtil.ShowNotification("No clip in AnimationController!");
            }
            else
            {
                AnimationClip clip             = ainfos[0].clip;
                string        oldClipAssetPath = AssetDatabase.GetAssetPath(clip);
                string        newClipAssetPath = PathUtil.StripExtension(oldClipAssetPath) + NEW_CLIP_POSTFIX + m_AnimType + ".anim";

                string filePath = EditorUtility.SaveFilePanel("Select export file path",
                                                              Path.GetDirectoryName(newClipAssetPath),
                                                              Path.GetFileNameWithoutExtension(newClipAssetPath),
                                                              "anim");
                if (filePath.Length > 0)
                {
                    filePath = PathUtil.FullPath2ProjectPath(filePath);
                    _ConvertAnim(filePath);
                }
                else
                {
                    EUtil.ShowNotification("Conversion Cancelled...");
                }
            }

            //apply the original pose back
            EUtil.ApplyXformData(m_Animator.transform, m_SavedPose);
        }
        EUtil.PopGUIEnable();
    }
        private void _GUI_AddNewCurve()
        {
            EditorWindow uaw      = (EditorWindow)EUtil.GetUnityAnimationWindow();
            object       uawstate = EUtil.GetUnityAnimationWindowState(uaw);

            m_CurClip = RCall.GetField("UnityEditorInternal.AnimationWindowState",
                                       "m_ActiveAnimationClip", uawstate) as AnimationClip;

            if (m_CurClip == null)
            {
                EditorGUILayout.LabelField("Need an animation clip first...");
                return;
            }

            m_NewPath      = EditorGUILayout.TextField("Path:", m_NewPath);
            m_NewProperty  = EditorGUILayout.TextField("Property:", m_NewProperty);
            m_TypeFullName = EditorGUILayout.TextField("TypeFullName:", m_TypeFullName);
            m_bIsPPtrCurve = EditorGUILayout.Toggle("IsPPtrCurve:", m_bIsPPtrCurve);

            EditorGUILayout.Separator();

            bool bOK = true;

            EUtil.PushGUIColor(Color.red);
            if (string.IsNullOrEmpty(m_NewProperty))
            {
                bOK = false;
                EditorGUILayout.LabelField("Property is not specified");
            }
            if (string.IsNullOrEmpty(m_TypeFullName) || RCall.GetTypeFromString(m_TypeFullName, true) == null)
            {
                bOK = false;
                EditorGUILayout.LabelField(string.Format("No type is found for name: {0}", m_TypeFullName));
            }
            EUtil.PopGUIColor();

            EUtil.PushGUIEnable(bOK);
            {
                if (EUtil.Button("Add New Curve", Color.green))
                {
                    Type tp = RCall.GetTypeFromString(m_TypeFullName);
                    if (m_bIsPPtrCurve)
                    {
                        EditorCurveBinding newBinding = EditorCurveBinding.PPtrCurve(m_NewPath, tp, m_NewProperty);
                        AnimationUtility.SetObjectReferenceCurve(m_CurClip, newBinding, new ObjectReferenceKeyframe[0]);
                    }
                    else
                    {
                        EditorCurveBinding newBinding = EditorCurveBinding.FloatCurve(m_NewPath, tp, m_NewProperty);
                        AnimationUtility.SetEditorCurve(m_CurClip, newBinding, new AnimationCurve());
                    }
                }
            }
            EUtil.PopGUIEnable();
        }
        private void _GUI_EditSingleCurve()
        {
            EditorWindow uaw      = (EditorWindow)EUtil.GetUnityAnimationWindow();
            object       uawstate = EUtil.GetUnityAnimationWindowState(uaw);

            m_CurClip = RCall.GetField("UnityEditorInternal.AnimationWindowState",
                                       "m_ActiveAnimationClip", uawstate) as AnimationClip;

            IList curves = (IList)RCall.GetProp("UnityEditorInternal.AnimationWindowState", "activeCurves", uawstate);

            if (curves.Count != 1)
            {
                EditorGUILayout.LabelField(string.Format("Please select ONE curve, you have currently selected {0} curves", curves.Count));
                return;
            }

            object             oneCurve   = curves[0]; //AnimationWindowCurve
            EditorCurveBinding oneBinding = (EditorCurveBinding)RCall.GetProp("UnityEditorInternal.AnimationWindowCurve", "binding", oneCurve);

            EditorGUILayout.LabelField("Path:");
            EUtil.PushContentColor(Color.yellow);
            EditorGUILayout.SelectableLabel(oneBinding.path);
            EUtil.PopContentColor();

            EditorGUILayout.LabelField("Property:");
            EUtil.PushContentColor(Color.green);
            EditorGUILayout.SelectableLabel(oneBinding.propertyName);
            EUtil.PopContentColor();

            EditorGUILayout.LabelField("IsPPtrCurve:  " + oneBinding.isPPtrCurve.ToString());

            EditorGUILayout.Separator();

            m_NewType = EditorGUILayout.TextField("Type:", m_NewType);
            if (m_NewType.Length == 0)
            {
                m_NewType = oneBinding.type.ToString();
            }

            m_NewPath     = EditorGUILayout.TextField("New Path:", m_NewPath);
            m_NewProperty = EditorGUILayout.TextField("New Property:", m_NewProperty);

            Type newTp = RCall.GetTypeFromString(m_NewType, true);

            EUtil.PushGUIEnable(m_NewProperty.Length > 0 && newTp != null);
            if (EUtil.Button("Apply Change", Color.green))
            {
                Undo.RegisterCompleteObjectUndo(m_CurClip, "Apply Curve Change");
                _ModifyCurveBinding(oneBinding, m_NewPath, m_NewProperty, newTp);
            }
            EUtil.PopGUIEnable();
        }
        private void _GUI_BatchAddPrefix()
        {
            EditorWindow uaw      = (EditorWindow)EUtil.GetUnityAnimationWindow();
            object       uawstate = EUtil.GetUnityAnimationWindowState(uaw);

            m_CurClip = RCall.GetField("UnityEditorInternal.AnimationWindowState",
                                       "m_ActiveAnimationClip", uawstate) as AnimationClip;

            //1. collect the TrPaths from active curves
            List <BindingInfo> bindingInfos = new List <BindingInfo>();

            IList curves = (IList)RCall.GetProp("UnityEditorInternal.AnimationWindowState", "activeCurves", uawstate);

            for (int idx = 0; idx < curves.Count; ++idx)
            {
                object             oneCurve   = curves[idx]; //AnimationWindowCurve
                EditorCurveBinding oneBinding = (EditorCurveBinding)RCall.GetProp("UnityEditorInternal.AnimationWindowCurve", "binding", oneCurve);
                bindingInfos.Add(new BindingInfo(oneBinding, oneCurve));
            }

            //2. display
            EditorGUILayout.LabelField("Selected curves:");
            m_scrollPos = EditorGUILayout.BeginScrollView(m_scrollPos, false, true, GUILayout.Height(200f));
            {
                foreach (var oneInfo in bindingInfos)
                {
                    EditorCurveBinding oneBinding = oneInfo.m_Binding;
                    GUILayout.BeginHorizontal();
                    {
                        EUtil.PushContentColor(Color.yellow);
                        GUILayout.Label(oneBinding.path);
                        EUtil.PopContentColor();
                        EUtil.PushContentColor(Color.green);
                        GUILayout.Label(oneBinding.propertyName);
                        EUtil.PopContentColor();
                    }
                    GUILayout.EndHorizontal();
                }
            }
            EditorGUILayout.EndScrollView();

            //3. apply prefix
            m_Prefix = EditorGUILayout.TextField("Prefix:", m_Prefix);

            EUtil.PushGUIEnable(m_CurClip != null && bindingInfos.Count > 0);
            if (EUtil.Button("Apply Prefix", Color.green))
            {
                _DoApplyPrefix(bindingInfos, m_Prefix);
            }
            EUtil.PopGUIEnable();
        }
        void OnGUI()
        {
            EditorGUI.BeginChangeCheck();
            m_Clip     = (AnimationClip)EditorGUILayout.ObjectField("Compress clip:", m_Clip, typeof(AnimationClip), false);
            m_PosErr   = EditorGUILayout.FloatField(new GUIContent("Position Threshold:", "raising this value could reduce more keys"), m_PosErr);
            m_RotErr   = EditorGUILayout.FloatField(new GUIContent("Rotation Threshold:", "raising this value could reduce more keys"), m_RotErr);
            m_ScaErr   = EditorGUILayout.FloatField(new GUIContent("Scale Threshold:", "raising this value could reduce more keys"), m_ScaErr);
            m_FloatErr = EditorGUILayout.FloatField(new GUIContent("Float Threshold:", "raising this value could reduce more keys"), m_FloatErr);
            m_Verbose  = EditorGUILayout.ToggleLeft("Verbose", m_Verbose);
            if (EditorGUI.EndChangeCheck())
            {
            }

            EUtil.PushGUIEnable(m_Clip != null);
            if (EUtil.Button("Execute!", "Start the work", Color.green, GUILayout.ExpandHeight(true)))
            {
                string newPath = EditorUtility.SaveFilePanelInProject("Save new clip", m_Clip.name + "_optimized", "anim", "Select new optimized clip save location");
                if (!string.IsNullOrEmpty(newPath))
                {
                    string oldPath = AssetDatabase.GetAssetPath(m_Clip);
                    if (oldPath == newPath)
                    {
                        bool bOK = EditorUtility.DisplayDialog("Are you sure?", "You're going to overwrite old animation file", "Go Ahead", "No-No");
                        if (bOK)
                        {
                            var comp = new AnimCompress();
                            comp.Verbose = m_Verbose;
                            comp.ReduceKeyframes(m_Clip, m_PosErr, m_RotErr, m_ScaErr, m_FloatErr);
                        }
                    }
                    else
                    {
                        AnimationClip newClip = AnimationClip.Instantiate(m_Clip) as AnimationClip;
                        if (newClip == null)
                        {
                            Dbg.LogErr("cannot load new clip at path: {0}", newPath);
                            return;
                        }
                        var comp = new AnimCompress();
                        comp.Verbose = m_Verbose;
                        comp.ReduceKeyframes(newClip, m_PosErr, m_RotErr, m_ScaErr, m_FloatErr);

                        newClip.name = Path.GetFileNameWithoutExtension(newPath);
                        EUtil.SaveAnimClip(newClip, newPath);
                    }
                }
            }
            EUtil.PopGUIEnable();
        }
    public void OnGUI()
    {
        m_targetSMR = EditorGUILayout.ObjectField("Main SMR:", m_targetSMR, typeof(SkinnedMeshRenderer), true) as SkinnedMeshRenderer;
        m_fromSMR   = EditorGUILayout.ObjectField("Extra SMR:", m_fromSMR, typeof(SkinnedMeshRenderer), true) as SkinnedMeshRenderer;

        bool  bAllSet = (m_targetSMR != null && m_fromSMR != null);
        Color c       = bAllSet ? Color.green : Color.red;

        EUtil.PushGUIEnable(bAllSet);
        if (EUtil.Button("Share_Skele", c))
        {
            Undo.RecordObject(m_fromSMR, "ShareSkele");
            ShareSkeleton.ShareSkele(m_targetSMR, m_fromSMR);
        }
        EUtil.PopGUIEnable();
    }
            // public method

            #endregion "public method"

            #region "private method"
            // private method

            private void _DrawShapeKeyData(ShapeKeyMorphSO morph, int keyIdx)
            {
                ShapeKeyDataDiff keyData = morph.GetShapeKeyDataDiff(keyIdx);

                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUILayout.LabelField("Weight:", GUILayout.Width(50f));

                    float newWeight = keyData.weight;
                    if (EUtil.FloatField("weight" + keyIdx, ref newWeight)) //only true when use enter to confirm
                    {
                        morph.SetShapeKeyWeight(keyIdx, newWeight);         //this will ensure all keys are sorted
                    }

                    if (EUtil.Button(EditorRes.texSample, "Sample current mesh status as shape key", EditorRes.styleBtnMorphProc, GUILayout.Width(20f)))
                    {
                        morph.SetMeshCurrentDataToShapeKey(keyIdx);
                    }
                    if (EUtil.Button(EditorRes.texApplyToMesh, "Apply this shape key to mesh", EditorRes.styleBtnMorphProc, GUILayout.Width(20f)))
                    {
                        Undo.RecordObject(m_MorphProc, "MorphProc Inspector");
                        m_MorphProc.ResetToBasisShape();
                        m_MorphProc.ApplyOnlyMorphAt(m_MorphIdx, keyData.weight);
                    }
                    if (EUtil.Button(EditorRes.texDelete, "Delete this shape key from this morph", EditorRes.styleBtnMorphProc, GUILayout.Width(20f)))
                    {
                        if (morph.ShapeKeyCnt == 1)
                        {
                            EditorUtility.DisplayDialog("Only one shape key", "Cannot delete shape key when there's no others", "Got it");
                        }
                        else
                        {
                            morph.DelShapeKeyDataDiff(keyIdx);
                        }
                    }
                }
                EditorGUILayout.EndHorizontal();
            }
Exemplo n.º 8
0
        void OnGUI()
        {
            m_SMR = EditorGUILayout.ObjectField(m_SMR, typeof(SkinnedMeshRenderer), true) as SkinnedMeshRenderer;

            bool bValid = (m_SMR != null);

            GUIUtil.PushGUIEnable(bValid);
            if (EUtil.Button(m_bShowing ? "Stop!" : "Run!", Color.white))
            {
                m_bShowing = !m_bShowing;
                if (m_bShowing)
                {
                    SceneView.onSceneGUIDelegate += this.OnSceneGUI;
                }
                else
                {
                    SceneView.onSceneGUIDelegate -= this.OnSceneGUI;
                }

                SceneView.lastActiveSceneView.Repaint();
            }
            GUIUtil.PopGUIEnable();
        }
Exemplo n.º 9
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            AnimatorData mb = target as AnimatorData;

            Dbg.Assert(mb != null, "AnimatorDataEditor.OnInspectorGUI: cannot get target: {0}", target.name);

            EditorGUILayout.HelpBox("If you want to modify the takes list, do it via the Timeline editor", MessageType.Info);

            if (EUtil.Button("Open Timeline Editor", Color.green))
            {
                AMTimeline.ResetWithAnimatorData((AnimatorData)target);
            }

            string playOnStartName = (m_spPlayOnStart.objectReferenceValue != null) ? ((AMTake)m_spPlayOnStart.objectReferenceValue).name : "None";

            EditorGUILayout.LabelField("Play On Start:  " + playOnStartName);

            EUtil.DrawSplitter();

            for (int i = 0; i < m_spTakes.arraySize; ++i)
            {
                var oneTake = m_spTakes.GetArrayElementAtIndex(i);

                GUILayout.BeginHorizontal();
                {
                    if (oneTake != null && oneTake.objectReferenceValue != null)
                    {
                        AMTake takeObj = oneTake.objectReferenceValue as AMTake;
                        EditorGUILayout.LabelField(string.Format("{0}: \"{1} fr, {2} fps\"", takeObj.name, takeObj.numFrames, takeObj.frameRate));
                        if (GUILayout.Button(new GUIContent(ms_inspectTex, "inspect this take's content"), GUILayout.Height(20f), GUILayout.Width(30f)))
                        {
                            Selection.activeObject = takeObj;
                        }
                        //EUtil.PushGUIColor(EditorUtility.IsPersistent(takeObj) ? Color.yellow : Color.green);
                        //if (GUILayout.Button(new GUIContent("S", "save asset to disk"), GUILayout.Width(30f)))
                        //{
                        //    string path = null;
                        //    if (!EditorUtility.IsPersistent(takeObj))
                        //        path = EditorUtility.SaveFilePanelInProject("Save Take", takeObj.name, "asset", "Select asset path");
                        //    else
                        //        path = AssetDatabase.GetAssetPath(takeObj);

                        //    if (!string.IsNullOrEmpty(path))
                        //    {
                        //        takeObj.SaveAsset(mb, path);
                        //        EUtil.ShowNotification("Saved Take at: " + path, 3f);
                        //    }
                        //}
                        //EUtil.PopGUIColor();
                    }
                    else
                    {
                        GUILayout.Label("This slot is null reference");
                    }
                }
                GUILayout.EndHorizontal();
            }

            serializedObject.ApplyModifiedProperties();
        }
Exemplo n.º 10
0
            // public method

            #endregion "public method"

            #region "private method"

            private void _DrawDeformEntry(MorphProc proc, int deformIdx, bool isBasis = true)
            {
                ShapeKeyMorphSO deform = (ShapeKeyMorphSO)m_propDeforms.GetArrayElementAtIndex(deformIdx).objectReferenceValue;

                EditorGUILayout.BeginHorizontal();
                {
                    float newWeight = 0f;

                    // weight
                    if (isBasis)
                    {
                        EUtil.PushGUIEnable(false);
                    }

                    EditorGUI.BeginChangeCheck();
                    newWeight = EditorGUILayout.FloatField(deform.name, m_propAnimWeights[deformIdx].floatValue);
                    if (EditorGUI.EndChangeCheck())
                    {
                        m_propAnimWeights[deformIdx].floatValue = Mathf.Clamp(newWeight, 0, 100f);
                    }

                    if (isBasis)
                    {
                        EUtil.PopGUIEnable();
                    }

                    // after weight
                    if (isBasis)
                    { //the basis
                        GUILayout.Space(20f);
                        if (EUtil.Button("R", "Reset as Basis", Color.green, GUILayout.Width(42f)))
                        {
                            Undo.RecordObject(proc, "MorphProc Inspector");
                            proc.ResetToBasisShape();
                        }
                    }
                    else
                    {
                        if (GUILayout.Button(new GUIContent(m_texDetail, "Edit details of this deform"), m_styleBtn, GUILayout.Width(20f)))
                        {
                            var e = (BaseMorphSOEditor)Editor.CreateEditor(deform);
                            e.m_MorphProcEditor = this;
                            e.m_MorphProc       = proc;
                            e.m_MorphIdx        = deformIdx;
                            EditorEditorWindow.OpenWindowWithEditor(e);
                        }

                        if (GUILayout.Button(new GUIContent(m_texApply, "Apply only this deform 100%"), m_styleBtn, GUILayout.Width(20f)))
                        {
                            Undo.RecordObject(proc, "MorphProc Inspector");
                            proc.ApplyOnlyMorphAt(deformIdx);
                        }

                        if (GUILayout.Button(new GUIContent(m_texDelete, "Delete this deform"), m_styleBtn, GUILayout.Width(20f)))
                        {
                            if (EditorUtility.DisplayDialog("To be or not to be", "Are you sure to delete this Morph?", "Go Ahead", "No No No"))
                            {
                                Undo.RecordObject(proc, "MorphProc Inspector");
                                proc.RemoveShapeKeyMorphAt(deformIdx);
                            }
                        }
                    }
                }
                EditorGUILayout.EndHorizontal();
            }
Exemplo n.º 11
0
    void OnGUI()
    {
        if (EditorApplication.isPlayingOrWillChangePlaymode)
        {
            return;
        }

        bool bIsCutScene = m_evtGoRoot != null;

        EUtil.PushGUIColor(bIsCutScene ? Color.green : Color.red);
        EditorGUILayout.LabelField(string.Format("AnimClip Root: {0}",
                                                 (m_ClipRoot == null ? "null" : m_ClipRoot.name)
                                                 ));
        EUtil.PopGUIColor();


        Color  c;
        String msg;

        if (bIsCutScene)
        {
            if (EUtil.Button("Sync AnimEvents with EventGO", Color.green))
            {
                _MatchEventGOAndAnimEvent();
            }

            if (EUtil.Button("Remove Animation/Animator on decendants", Color.yellow))
            {
                _RemoveAnimCompsOnDecendants();
            }

            if (EUtil.Button("Fix Duplicate Transform Path", Color.white))
            {
                _FixDuplicateTransformPath();
            }

            c   = m_bShowMark4SelectedCurves ? Color.green : Color.red;
            msg = m_bShowMark4SelectedCurves ? "Hide Marks for Selected Curves" : "Show Marks for Selected Curves";
            if (EUtil.Button(msg, c))
            {
                m_bShowMark4SelectedCurves = !m_bShowMark4SelectedCurves;
                SceneView.RepaintAll();
            }
        }
        else
        {
            if (EUtil.Button("New CCRoot", Color.green))
            {
                GameObject newCCRoot = new GameObject();
                newCCRoot.name = "NewCCRoot";
                newCCRoot.AddComponent <CutsceneController>();
                var anim = newCCRoot.AddComponent <Animation>();
                anim.playAutomatically = false;

                Misc.ForceGetGO(EventGOS, newCCRoot);
                Selection.activeGameObject = newCCRoot;
            }

            c   = m_bShowMark4SelectedCurves ? Color.green : Color.red;
            msg = m_bShowMark4SelectedCurves ? "Hide Marks for Selected Curves" : "Show Marks for Selected Curves";
            if (EUtil.Button(msg, c))
            {
                m_bShowMark4SelectedCurves = !m_bShowMark4SelectedCurves;
                SceneView.RepaintAll();
            }
        }
    }
        private void _GUI_ChangePath()
        {
            EditorWindow uaw      = (EditorWindow)EUtil.GetUnityAnimationWindow();
            object       uawstate = EUtil.GetUnityAnimationWindowState(uaw);

            m_CurClip = RCall.GetField("UnityEditorInternal.AnimationWindowState",
                                       "m_ActiveAnimationClip", uawstate) as AnimationClip;

            //1. collect the TrPaths from active curves
            List <EditorCurveBinding> bindingInfos = new List <EditorCurveBinding>();

            IList curves = (IList)RCall.GetProp("UnityEditorInternal.AnimationWindowState", "activeCurves", uawstate);

            if (curves.Count <= 0)
            {
                EditorGUILayout.LabelField("Please Select a Curve first...");
                return;
            }

            EditorCurveBinding theBinding   = (EditorCurveBinding)RCall.GetProp("UnityEditorInternal.AnimationWindowCurve", "binding", curves[0]);
            string             toChangePath = theBinding.path;

            IList allCurves = (IList)RCall.GetProp("UnityEditorInternal.AnimationWindowState", "allCurves", uawstate);

            foreach (var oneUAWCurve in allCurves)
            {
                EditorCurveBinding oneBinding = (EditorCurveBinding)RCall.GetProp("UnityEditorInternal.AnimationWindowCurve", "binding", oneUAWCurve);
                if (oneBinding.path == toChangePath)
                {
                    bindingInfos.Add(oneBinding);
                }
            }

            //2. display
            EditorGUILayout.LabelField("Affected curves:");
            m_scrollPos = EditorGUILayout.BeginScrollView(m_scrollPos, false, true, GUILayout.Height(200f));
            {
                foreach (var oneInfo in bindingInfos)
                {
                    EditorCurveBinding oneBinding = oneInfo;
                    GUILayout.BeginHorizontal();
                    {
                        EUtil.PushContentColor(Color.yellow);
                        GUILayout.Label(oneBinding.path);
                        EUtil.PopContentColor();
                        EUtil.PushContentColor(Color.green);
                        GUILayout.Label(oneBinding.propertyName);
                        EUtil.PopContentColor();
                    }
                    GUILayout.EndHorizontal();
                }
            }
            EditorGUILayout.EndScrollView();

            //3. apply prefix
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("R", GUILayout.Width(20)))
            {
                GUIUtility.keyboardControl = 0;
                m_NewPath = toChangePath;
            }
            m_NewPath = EditorGUILayout.TextField("New Path:", m_NewPath);
            EditorGUILayout.EndHorizontal();

            EUtil.PushGUIEnable(m_CurClip != null && bindingInfos.Count > 0);
            if (EUtil.Button("Change Path!", Color.green))
            {
                _DoChangePath(bindingInfos, m_NewPath);
            }
            EUtil.PopGUIEnable();
        }
        void OnGUI()
        {
            if (!EUtil.IsUnityAnimationWindowOpen())
            {
                EditorGUILayout.LabelField("Animation Window is not open...");
                return;
            }

            // mode switch
            EditorGUILayout.BeginHorizontal();
            {
                EUtil.PushGUIEnable(m_OpMode != OpMode.AddPathPrefixOnMultiCurveBinding);
                if (EUtil.Button("Batch AddPrefix", Color.green))
                {
                    _OnOpModeChange(m_OpMode, OpMode.AddPathPrefixOnMultiCurveBinding);
                    m_OpMode = OpMode.AddPathPrefixOnMultiCurveBinding;
                }
                EUtil.PopGUIEnable();

                EUtil.PushGUIEnable(m_OpMode != OpMode.ChangePath);
                if (EUtil.Button("Change Path", Color.green))
                {
                    _OnOpModeChange(m_OpMode, OpMode.ChangePath);
                    m_OpMode = OpMode.ChangePath;
                }
                EUtil.PopGUIEnable();

                EUtil.PushGUIEnable(m_OpMode != OpMode.EditSingleCurveBinding);
                if (EUtil.Button("Edit Single Curve", Color.green))
                {
                    _OnOpModeChange(m_OpMode, OpMode.EditSingleCurveBinding);
                    m_OpMode = OpMode.EditSingleCurveBinding;
                }
                EUtil.PopGUIEnable();

                EUtil.PushGUIEnable(m_OpMode != OpMode.AddNewCurve);
                if (EUtil.Button("Add New Curve", Color.green))
                {
                    _OnOpModeChange(m_OpMode, OpMode.AddNewCurve);
                    m_OpMode = OpMode.AddNewCurve;
                }
                EUtil.PopGUIEnable();
            }
            EditorGUILayout.EndHorizontal();

            // specific GUI

            switch (m_OpMode)
            {
            case OpMode.AddPathPrefixOnMultiCurveBinding:
            {
                _GUI_BatchAddPrefix();
            }
            break;

            case OpMode.ChangePath:
            {
                _GUI_ChangePath();
            }
            break;

            case OpMode.EditSingleCurveBinding:
            {
                _GUI_EditSingleCurve();
            }
            break;

            case OpMode.AddNewCurve:
            {
                _GUI_AddNewCurve();
            }
            break;

            default:
                Dbg.LogErr("AnimCurvePropEditor.OnGUI: unexpected OpMode: {0}", m_OpMode);
                break;
            }
        }
Exemplo n.º 14
0
        private void _OnGUI_IKPanel_Debug(CCDSolverMB cp)
        {
            // line 1
            GUILayout.BeginHorizontal();
            {
                if (GUILayout.Button(CONT_ZeroAll, EditorStyles.toolbarButton))
                { //zero-out all rotation
                    var solver = cp.GetSolver();
                    var joints = solver.GetJoints();
                    Undo.RecordObjects(joints, "Zero-out IK joints");
                    foreach (var j in joints)
                    {
                        j.localRotation = Quaternion.identity;
                    }
                }
                if (GUILayout.Button(CONT_Reset, EditorStyles.toolbarButton))
                { // return target to endJoint
                    var solver = cp.GetSolver();
                    solver.Target = cp.transform.position;
                    EUtil.RepaintSceneView();
                }
            }
            GUILayout.EndHorizontal();

            // line 2
            GUILayout.BeginHorizontal();
            {
                bool   bStartedStep = m_dbgStepIE != null;
                Color  c            = bStartedStep ? Color.red : Color.green;
                string s            = bStartedStep ? "StopStep" : "StartStep";
                if (EUtil.Button(s, c))
                {
                    var solver = cp.GetSolver();
                    if (!bStartedStep)
                    {
                        m_dbgStepIE = solver.DBGExecute();
                    }
                    else
                    {
                        solver.dbg_interrupt = true;
                        m_dbgStepIE.MoveNext();
                        m_dbgStepIE  = null;
                        bStartedStep = false;
                    }
                }

                EUtil.PushGUIEnable(bStartedStep);
                {
                    if (GUILayout.Button(CONT_Step))
                    {
                        bool bNotOver = m_dbgStepIE.MoveNext();
                        if (!bNotOver)
                        {
                            m_dbgStepIE  = null;
                            bStartedStep = false;
                        }
                    }
                    if (GUILayout.Button(CONT_Continue))
                    {
                        while (m_dbgStepIE.MoveNext() == true)
                        {
                            ;
                        }
                        m_dbgStepIE  = null;
                        bStartedStep = false;
                    }
                }
                EUtil.PopGUIEnable();
            }
            GUILayout.EndHorizontal();
        }
        public override void OnInspectorGUI()
        {
            ConeConstraintMB mb = (ConeConstraintMB)target;

            mb.enabled = EditorGUILayout.Toggle("Enabled", mb.enabled);

            EditorGUI.BeginChangeCheck();
            mb.nextJoint = EditorGUILayout.ObjectField("nextJoint", mb.nextJoint, typeof(Transform), true) as Transform;
            if (EditorGUI.EndChangeCheck())
            {
                EUtil.RepaintSceneView();
            }

            if (mb.nextJoint == null)
            {
                EditorGUILayout.LabelField("Set the nextJoint first...");
                return;
            }
            else
            {
                EUtil.PushGUIEnable(mb.enabled);

                EditorGUILayout.BeginHorizontal();
                {
                    GUILayout.Space(30f);
                    if (EUtil.Button("ReInit", "decide all the parameters with default method", Color.green))
                    {
                        Undo.RecordObject(mb, "AutoInit");
                        mb._AutoSetParameters();
                        EUtil.RepaintSceneView();
                    }
                    GUILayout.Space(30f);
                }
                EditorGUILayout.EndHorizontal();

                // angle limit
                EditorGUI.BeginChangeCheck();
                float newAngleLimit = EditorGUILayout.Slider(CONT_AngleLimit, mb.angleLimit, 0, 180f);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(mb, "Modify Angle Limit");
                    mb.angleLimit = newAngleLimit;
                    EUtil.RepaintSceneView();
                }

                // ref-Axis
                EditorGUI.BeginChangeCheck();
                Vector3 newRefAxis = EUtil.DrawV3P(CONT_RefAxis, mb.refAxis);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(mb, "Modify ref axis");
                    mb.refAxis = newRefAxis;
                    mb.CalcInitData(); //!! recalc the startTwistRot
                    EUtil.RepaintSceneView();
                }

                mb.limitTwist = EditorGUILayout.Toggle(CONT_LimitTwist, mb.limitTwist);
                if (mb.limitTwist)
                {
                    float min = mb.minTwistLimit;
                    float max = mb.maxTwistLimit;
                    EditorGUI.BeginChangeCheck();
                    EUtil.DrawMinMaxSlider("Twist Limits", ref min, ref max, -180f, 180f);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(mb, "Modify twist limits");
                        mb.minTwistLimit = min;
                        mb.maxTwistLimit = max;
                        EUtil.RepaintSceneView();
                    }

                    EditorGUILayout.LabelField("Current twist: " + mb.CalcTwist());
                }

                ms_showDisplaySetting = EditorGUILayout.Foldout(ms_showDisplaySetting, "Display Settings:");
                if (ms_showDisplaySetting)
                {
                    EditorGUI.BeginChangeCheck();
                    ms_markerSize  = EditorGUILayout.FloatField("Marker size", ms_markerSize);
                    ms_markerColor = EditorGUILayout.ColorField("Marker color", ms_markerColor);
                    if (EditorGUI.EndChangeCheck())
                    {
                        EUtil.RepaintSceneView();
                    }
                }

                EUtil.PopGUIEnable();
            }
        }
Exemplo n.º 16
0
        void OnGUI()
        {
            EditorGUI.BeginChangeCheck();
            _bones[(int)Bones.Root] = (Transform)EditorGUILayout.ObjectField(new GUIContent("Root", "the one at topmost with Animator componnet"), _bones[(int)Bones.Root], typeof(Transform), true);
            if (EditorGUI.EndChangeCheck())
            {
                _ClearBonesRefExceptRoot();
                _TryFindBones();
            }

            _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos);
            {
                _refOpen = EditorGUILayout.Foldout(_refOpen, "bones");
                if (_refOpen)
                {
                    for (Bones eBone = (Bones)0; eBone < Bones.END; ++eBone)
                    {
                        Transform t = _bones[(int)eBone];
                        _bones[(int)eBone] = (Transform)EditorGUILayout.ObjectField(eBone.ToString(), t, typeof(Transform), true);
                    }
                }

                _optionOpen = EditorGUILayout.Foldout(_optionOpen, "options");
                if (_optionOpen)
                {
                    _addIKTarget = EditorGUILayout.Toggle(new GUIContent("Add IKTarget", "Add IK Targets for limbs"), _addIKTarget);

                    if (_addIKTarget)
                    {
                        _addFloor = EditorGUILayout.Toggle(new GUIContent("Floor Constraint", "Add Floor constraint on feet"), _addFloor);
                        if (_addFloor)
                        {
                            EditorGUI.indentLevel++;
                            _floorObj = (Transform)EditorGUILayout.ObjectField(new GUIContent("Floor Obj", "the object be taken as floor"), _floorObj, typeof(Transform), true);
                            EditorGUI.indentLevel--;
                        }

                        _addPelvisFollow = EditorGUILayout.Toggle(new GUIContent("Pelvis Follow", "Pelvis position is calculated with two feet"), _addPelvisFollow);
                    }
                }

                bool isAllFound = _IsAllFound();
                EditorGUILayout.HelpBox(isAllFound ? "All bones are found, you might check if the mappings are correct" : "Not all bones are setup, you might want to manually set those left out", MessageType.Info);

                if (_execLog.Length > 0)
                {
                    EditorGUILayout.HelpBox(_execLog.ToString(), MessageType.Info);
                }

                EUtil.DrawSplitter();
                EditorGUILayout.BeginHorizontal();
                {
                    GUILayout.Space(0.1f * position.width);
                    EUtil.PushGUIEnable(_bones[(int)Bones.Root] != null);
                    if (EUtil.Button("Add Constraints", "If not all bones are set up, constraints will be only setup on those qualified", isAllFound ? Color.green : Color.yellow, GUILayout.Height(50f)))
                    {
                        _ExecuteAddConstraints();
                    }
                    if (EUtil.Button("Clear Constraints", "Clear all constraints on qualified joints", Color.white, GUILayout.Height(50f)))
                    {
                        _ExecuteDelConstraints();
                    }
                    EUtil.PopGUIEnable();
                    GUILayout.Space(0.1f * position.width);
                }
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.EndScrollView();
        }
Exemplo n.º 17
0
        public override void OnInspectorGUI()
        {
            CCDSolverMB cp = (CCDSolverMB)target;

            EditorGUI.BeginChangeCheck();

            EConUtil.DrawActiveLine(cp);

            //constraint target
            cp.Target = (Transform)EditorGUILayout.ObjectField("Target Object", cp.Target, typeof(Transform), true);

            EUtil.DrawSplitter();

            EUtil.PushGUIEnable(cp.IsActiveConstraint);
            {
                // reset button
                GUILayout.BeginHorizontal();
                GUILayout.Space(30f);
                if (EUtil.Button("Recollect IKConstraints", "click this when add new IK-constraint on this IK-link", Color.green))
                {
                    cp.GetSolver(true);
                    EUtil.RepaintSceneView();
                }
                GUILayout.Space(30f);
                GUILayout.EndHorizontal();


                // jointList
                if (!m_manualSetJoints)
                {
                    m_autoCollectBoneCount = EditorGUILayout.IntField(CONT_BoneCnt, m_autoCollectBoneCount);
                }
                else
                {
                    var jointList = cp.jointList;
                    Undo.RecordObject(cp, "JointList");
                    for (int i = 0; i < jointList.Count; ++i)
                    {
                        EditorGUILayout.BeginHorizontal();
                        jointList[i] = (Transform)EditorGUILayout.ObjectField(jointList[i], typeof(Transform), true);
                        if (GUILayout.Button(new GUIContent("+", "add new entry")))
                        {
                            jointList.Insert(i, null);
                            GUIUtility.ExitGUI();
                        }
                        if (GUILayout.Button(new GUIContent("-", "delete this entry")))
                        {
                            jointList.RemoveAt(i);
                            GUIUtility.ExitGUI();
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                }

                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button(m_manualSetJoints ? CONT_ManualSetJoints : CONT_AutoSetJoints, EditorStyles.toolbarButton))
                {
                    m_manualSetJoints = !m_manualSetJoints;
                }

                bool isIdentical = _CheckJointListIdentical(cp);
                EUtil.PushBackgroundColor(isIdentical ? Color.white : Color.blue);
                if (GUILayout.Button(new GUIContent("Apply", "Apply the joint list"), EditorStyles.toolbarButton))
                {
                    if (m_manualSetJoints)
                    {
                        if (_CheckManualSetJointList(cp))
                        {
                            cp._RenewInitInfoAndSolver();
                        }
                    }
                    else
                    {
                        cp._RenewByCollectJointsWithBontCount(m_autoCollectBoneCount);
                    }
                    m_autoCollectBoneCount = cp.boneCount;
                }
                EUtil.PopBackgroundColor();

                EditorGUILayout.EndHorizontal();

                EUtil.DrawSplitter();

                // dist thres
                EditorGUI.BeginChangeCheck();
                float newDistThres = EditorGUILayout.FloatField(CONT_DistThres, cp.distThres);
                if (EditorGUI.EndChangeCheck())
                {
                    if (newDistThres > 0f)
                    {
                        Undo.RecordObject(cp, "Set Dist Thres");
                        cp.distThres = newDistThres;
                    }
                }

                cp.useDamp = EditorGUILayout.Toggle(CONT_Damp, cp.useDamp);
                if (cp.useDamp)
                {
                    cp.globalDamp = EditorGUILayout.FloatField("Global damp", cp.globalDamp);
                }

                cp.useTargetRotation = EditorGUILayout.Toggle(CONT_UseTargetRotation, cp.useTargetRotation);
                cp.maxIteration      = EditorGUILayout.IntField(CONT_MaxIteration, cp.maxIteration);

                cp.revertOpt = (CCDSolver.RevertOption)EditorGUILayout.EnumPopup(CONT_RevertOpt, cp.revertOpt);

                m_markerSize.val = Mathf.Max(0, EditorGUILayout.FloatField(CONT_BoneMarkSize, m_markerSize.val));

                EUtil.PushGUIEnable(!cp.Target);
                {
                    if (GUILayout.Button("Control Mode:  " + (cp.Target ? "Target" : m_panel.ToString()), EditorStyles.toolbarButton))
                    {
                        m_panel = (EPanel)((int)(m_panel + 1) % (int)EPanel.END);
                        cp.GetSolver().Target = cp.transform.position;
                    }
                    _OnGUI_IKPanel(cp);
                }
                EUtil.PopGUIEnable();

                // influence
                GUILayout.Space(5f);
                cp.Influence = EUtil.ProgressBar(cp.Influence, 0, 1f, "Influence: {0:F2}");

                //initInfos
                if (Pref.ShowInitInfos)
                {
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("m_initInfos"), true);
                }
            }
            EUtil.PopGUIEnable();

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(cp); //so ConstraintStack.Update can be called in edit-mode
            }
        }
Exemplo n.º 18
0
        void OnGUI()
        {
            if (m_CurAnimator == null)
            {
                GUILayout.Label("Select animator gameobject first !");
                return;
            }
            if (!EUtil.HasAnimatorController(m_CurAnimator))
            {
                GUILayout.Label("The Animator doesn't have AnimatorController set!");
                return;
            }

            var stateInfo = m_CurAnimator.GetCurrentAnimatorStateInfo(0);

            GUILayout.Label(string.Format("Cur: {0}, state: {1}", m_CurAnimator.name, EUtil.GetStateNameHash(stateInfo)));
            float nt  = stateInfo.normalizedTime;
            float len = stateInfo.length;
            float t   = nt * len;

            GUILayout.Label(string.Format("Cur time: nt:{0}, t:{1}", nt, t));

            Event e = Event.current;

            if (e.type == EventType.KeyDown)
            {
                float delta = 0;
                if (e.keyCode == KeyCode.RightArrow)
                {
                    delta = m_step;
                }
                else if (e.keyCode == KeyCode.LeftArrow)
                {
                    delta = -m_step;
                }
                else if (e.keyCode == KeyCode.Home)
                {
                    delta = -t;
                }

                if (!Mathf.Approximately(0, delta))
                {
                    m_CurAnimator.Update(delta);
                    Repaint();
                }
            }

            m_transBool.target = EditorGUILayout.ToggleLeft("Set Param", m_transBool.target);
            if (EditorGUILayout.BeginFadeGroup(m_transBool.faded))
            {
                var allParamNames = new List <string>();
                EUtil.GetAllParameterNames(allParamNames, m_CurAnimator);
                int idx = Mathf.Max(0, allParamNames.IndexOf(m_paramName));
                idx = EditorGUILayout.Popup("paramName", idx, allParamNames.ToArray());
                if (allParamNames.Count > 0)
                {
                    m_paramName = allParamNames[idx];
                }

                m_type = (PType)EditorGUILayout.EnumPopup("type", m_type);
                switch (m_type)
                {
                case PType.Bool: m_bool = EditorGUILayout.Toggle("bool", m_bool); break;

                case PType.Float: m_float = EditorGUILayout.FloatField("float", m_float); break;

                case PType.Int: m_int = EditorGUILayout.IntField("int", m_int); break;
                }
                EUtil.PushGUIEnable(!string.IsNullOrEmpty(m_paramName));
                if (GUILayout.Button("execute"))
                {
                    switch (m_type)
                    {
                    case PType.Bool: m_CurAnimator.SetBool(m_paramName, m_bool); break;

                    case PType.Float: m_CurAnimator.SetFloat(m_paramName, m_float); break;

                    case PType.Int: m_CurAnimator.SetInteger(m_paramName, m_int); break;

                    case PType.Trigger: m_CurAnimator.SetTrigger(m_paramName); break;
                    }
                }
                EUtil.PopGUIEnable();
            }
            EditorGUILayout.EndFadeGroup();

            List <string> allNames = new List <string>();

            EUtil.GetAllStateNames(allNames, m_CurAnimator);
            m_jumpToggle.target = EditorGUILayout.ToggleLeft("jump to", m_jumpToggle.target);
            if (EditorGUILayout.BeginFadeGroup(m_jumpToggle.faded))
            {
                int idx = Mathf.Max(0, allNames.IndexOf(m_stateName));
                idx = EditorGUILayout.Popup("stateName", idx, allNames.ToArray());
                if (allNames.Count > 0)
                {
                    m_stateName = allNames[idx];
                }

                m_fadeTime = Mathf.Max(0, EditorGUILayout.FloatField("fade time", m_fadeTime));
                if (GUILayout.Button("execute"))
                {
                    if (!EUtil.HasState(m_CurAnimator, m_stateName))
                    {
                        Dbg.Log("unknown stateName: {0}", m_stateName);
                    }
                    else
                    {
                        if (m_fadeTime > 0)
                        {
                            m_CurAnimator.CrossFade(m_stateName, m_fadeTime);
                        }
                        else
                        {
                            m_CurAnimator.Play(m_stateName);
                        }
                    }
                }
            }
            EditorGUILayout.EndFadeGroup();

            EUtil.DrawSplitter();
            EUtil.DrawSplitter();

            m_step = EditorGUILayout.Slider("Step", m_step, 0, 1f);

            GUILayout.BeginHorizontal();
            {
                if (GUILayout.Button("<-", GUILayout.Height(40f)))
                {
                    m_CurAnimator.Update(-m_step);
                }
                GUILayout.Space(5f);
                if (GUILayout.Button("->", GUILayout.Height(40f)))
                {
                    m_CurAnimator.Update(m_step);
                }
            }
            GUILayout.EndHorizontal();

            if (EUtil.Button("Rebind", Color.red))
            {
                m_CurAnimator.Rebind();
                m_CurAnimator.Update(0);
            }
        }
        public override void OnInspectorGUI()
        {
            AngleConstraintMB mb = (AngleConstraintMB)target;

            mb.enabled = EditorGUILayout.Toggle("Enabled", mb.enabled);

            EditorGUI.BeginChangeCheck();
            mb.nextJoint = EditorGUILayout.ObjectField("nextJoint", mb.nextJoint, typeof(Transform), true) as Transform;
            if (EditorGUI.EndChangeCheck())
            {
                EUtil.SetDirty(mb);
                EUtil.RepaintSceneView();
            }

            if (mb.nextJoint == null)
            {
                EditorGUILayout.LabelField("Set the nextJoint first...");
                return;
            }
            else
            {
                EUtil.PushGUIEnable(mb.enabled);

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Space(30f);
                    if (EUtil.Button("ReInit", "decide all the parameters with default method", Color.green))
                    {
                        Undo.RecordObject(mb, "ReInit");
                        mb.AutoSetParameters();
                        EUtil.SetDirty(mb);
                        EUtil.RepaintSceneView();
                    }
                    GUILayout.Space(30f);
                }
                GUILayout.EndHorizontal();

                // min/max limit
                float min = mb.minLimit;
                float max = mb.maxLimit;
                EditorGUI.BeginChangeCheck();
                EUtil.DrawMinMaxSlider("Angle Limits", ref min, ref max, -180f, 180f);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(mb, "Modify Angle limits");
                    mb.minLimit = min;
                    mb.maxLimit = max;
                    EUtil.SetDirty(mb);
                    EUtil.RepaintSceneView();
                }

                EditorGUI.BeginChangeCheck();
                Vector3 newRotAxis  = EUtil.DrawV3P(new GUIContent("Rotation Axis", "in parent space, in world space if no parent joint"), mb.rotAxis);
                Vector3 newPrimAxis = EUtil.DrawV3P(new GUIContent("Primary Axis", "in parent space, in world space if no parent joint"), mb.primAxis);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(mb, "Modify Constraint parameters");
                    mb.rotAxis  = newRotAxis;
                    mb.primAxis = newPrimAxis;
                    mb.CalcInitData(); //!! recalc the startLocalRot
                    EUtil.SetDirty(mb);
                    EUtil.RepaintSceneView();
                }

                ms_showDisplaySetting = EditorGUILayout.Foldout(ms_showDisplaySetting, "Display Settings:");
                if (ms_showDisplaySetting)
                {
                    EditorGUI.BeginChangeCheck();
                    ms_markerSize = EditorGUILayout.FloatField("ArcSize", ms_markerSize);
                    ms_arcColor   = EditorGUILayout.ColorField("ArcColor", ms_arcColor);
                    if (EditorGUI.EndChangeCheck())
                    {
                        EUtil.RepaintSceneView();
                    }
                }

                EUtil.PopGUIEnable();
            }
        }
Exemplo n.º 20
0
        void OnGUI()
        {
            object        uawstate;
            AnimationClip clip;
            bool          isReady = _IsAnimationWindowOpenAndWithClip(out uawstate, out clip);

            if (!isReady)
            {
                EditorGUILayout.LabelField("Need to open AnimationWindow with a clip first ... ");
            }
            else
            {
                EditorGUILayout.LabelField("Set the Roots:");
                for (int i = 0; i < m_Roots.Count; ++i)
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        EditorGUI.BeginChangeCheck();
                        var root = (Transform)EditorGUILayout.ObjectField(m_Roots[i], typeof(Transform), true);
                        if (EditorGUI.EndChangeCheck())
                        {
                            m_Roots[i] = root;
                        }
                        if (EUtil.Button("-", "delete entry", Color.red, GUILayout.Width(20f)))
                        {
                            m_Roots.RemoveAt(i);
                            GUIUtility.ExitGUI();
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }

                EditorGUILayout.BeginHorizontal();
                {
                    GUILayout.Space(40f);
                    if (GUILayout.Button("Add Root Entry"))
                    {
                        m_Roots.Add(null);
                    }
                    GUILayout.Space(40f);
                }
                EditorGUILayout.EndHorizontal();

                GUILayout.Space(5f);

                if (GUILayout.Button(m_baking ? "Baking" : "Not Baking", EditorStyles.toolbarButton))
                {
                    m_baking = !m_baking;

                    if (m_baking)
                    {
                        m_Trs.Clear();
                        foreach (var oneRoot in m_Roots)
                        {
                            for (var ie = oneRoot.GetRecurEnumerator(); ie.MoveNext();)
                            {
                                var tr = ie.Current;
                                if (null == m_Trs.Find(x => x.tr == tr))
                                {
                                    var xfdata = XformData2.Create(tr);
                                    m_Trs.Add(xfdata);
                                }
                            }
                        }

                        m_TrsArr = m_Trs.Select(x => x.tr).ToArray();
                        m_uaw    = EUtil.GetUnityAnimationWindow();
                        if (null == m_uaw)
                        {
                            m_baking = false;
                        }
                    }
                }

                if (!m_baking)
                {
                    GUILayout.Space(5f);

                    if (GUILayout.Button(new GUIContent("Compress Angles", "Only use this method on a clips full of keyframes"), EditorStyles.toolbarButton))
                    {
                        _NormalizeRotationsInClip(uawstate, clip);
                    }
                }
            }
        }
Exemplo n.º 21
0
        void OnGUI()
        {
            EditorGUI.BeginChangeCheck();
            m_AnimRoot = EditorGUILayout.ObjectField("AnimatorGO", m_AnimRoot, typeof(Transform), true) as Transform;
            if (EditorGUI.EndChangeCheck())
            {
                if (m_AnimRoot.GetComponent <Animator>() == null &&
                    m_AnimRoot.GetComponent <Animation>() == null)
                {
                    Dbg.LogWarn("The AnimatorGO must has Animation/Animator component!");
                    m_AnimRoot = null;
                }
            }

            EditorGUI.BeginChangeCheck();
            m_Clip = EditorGUILayout.ObjectField("AnimClip", m_Clip, typeof(AnimationClip), false) as AnimationClip;
            if (EditorGUI.EndChangeCheck())
            {
                _GetREs();
                _GenMatchMap();
            }

            m_scrollPos = EditorGUILayout.BeginScrollView(m_scrollPos, GUILayout.MaxHeight(200f));
            {
                List <string> toDel = new List <string>();
                foreach (var entry in m_MatchMap)
                {
                    string leftPath  = entry.Key;
                    string rightPath = entry.Value.path;
                    bool   bFound    = entry.Value.found;

                    GUILayout.BeginHorizontal();
                    {
                        if (EUtil.Button("X", "Remove this entry", Color.red, GUILayout.Width(20)))
                        {
                            toDel.Add(leftPath);
                        }

                        string line;
                        if (bFound)
                        {
                            line = string.Format("{0} <-> {1}", leftPath, rightPath);
                        }
                        else
                        {
                            line = string.Format("{0} -> {1}", leftPath, rightPath);
                        }

                        GUILayout.Label(line);
                    }
                    GUILayout.EndHorizontal();
                }

                foreach (var d in toDel)
                {
                    m_MatchMap.Remove(d);
                }
            }
            EditorGUILayout.EndScrollView();

            {
                m_SymBoneAxis    = (Axis)EditorGUILayout.EnumPopup("Sym Bone Axis", m_SymBoneAxis, GUILayout.MaxWidth(200));
                m_NonSymBoneAxis = (Axis)EditorGUILayout.EnumPopup("Non-Sym Bone Axis", m_NonSymBoneAxis, GUILayout.MaxWidth(200));
            }

            EUtil.PushGUIEnable(m_AnimRoot != null && m_Clip != null);
            if (EUtil.Button("Apply Change!", Color.green))
            {
                string oriPath = AssetDatabase.GetAssetPath(m_Clip);
                //string oriName = Path.GetFileNameWithoutExtension(oriPath);
                string oriDir  = Path.GetDirectoryName(oriPath);
                string newPath = EditorUtility.SaveFilePanelInProject("Save Mirrored clip", m_Clip.name + "_Mirror", "anim", "Select path", oriDir);
                if (!string.IsNullOrEmpty(newPath))
                {
                    _CreateMirrorClip(newPath);
                }
            }
            EUtil.PopGUIEnable();
        }
    private void _OnGUI_SMR()
    {
        m_RootBone = EditorGUILayout.ObjectField(new GUIContent("Top GO", "fill the topmost GameObject of model"), m_RootBone, typeof(Transform), true) as Transform;
        GUIUtil.PushGUIEnable(m_RootBone != null);
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(60f);
            if (EUtil.Button("AutoFind", "Automatically collect all SMR & MF on this model", Color.blue))
            {
                _AutoFindRenderers();
            }
            GUILayout.Space(60f);
            GUILayout.EndHorizontal();
        }
        GUIUtil.PopGUIEnable();

        EUtil.DrawSplitter();

        //SMR
        for (int idx = 0; idx < m_SMRs.Count; ++idx)
        {
            GUILayout.BeginHorizontal();

            if (EUtil.Button("X", "delete", Color.red, GUILayout.Width(30f)))
            {
                m_SMRs.RemoveAt(idx);
                --idx;
                continue;
            }

            Color oc = GUI.backgroundColor;
            GUI.backgroundColor = Color.green;
            m_SMRs[idx]         = EditorGUILayout.ObjectField(m_SMRs[idx], typeof(SkinnedMeshRenderer), true) as SkinnedMeshRenderer;
            GUI.backgroundColor = oc;

            GUILayout.EndHorizontal();
        }

        GUILayout.BeginHorizontal();
        GUILayout.Space(60f);
        if (GUILayout.Button(new GUIContent("Add SMR Entry", "manually add \"Skinned-Mesh Renderer\"")))
        {
            m_SMRs.Add(null);
        }
        GUILayout.Space(60f);
        GUILayout.EndHorizontal();

        EUtil.DrawSplitter();

        //MF
        for (int idx = 0; idx < m_MFs.Count; ++idx)
        {
            GUILayout.BeginHorizontal();
            if (EUtil.Button("X", "delete", Color.red, GUILayout.Width(30f)))
            {
                m_MFs.RemoveAt(idx);
                --idx;
                continue;
            }

            Color oc = GUI.backgroundColor;
            GUI.backgroundColor = Color.yellow;
            m_MFs[idx]          = EditorGUILayout.ObjectField(m_MFs[idx], typeof(MeshFilter), true) as MeshFilter;
            GUI.backgroundColor = oc;

            GUILayout.EndHorizontal();
        }

        GUILayout.BeginHorizontal();
        GUILayout.Space(60f);
        if (GUILayout.Button(new GUIContent("Add MF Entry", "manually add \"Mesh Filter\"")))
        {
            m_MFs.Add(null);
        }
        GUILayout.Space(60f);
        GUILayout.EndHorizontal();

        EUtil.DrawSplitter();

        //export clips
        for (int idx = 0; idx < m_Clips.Count; ++idx)
        {
            GUILayout.BeginHorizontal();
            if (EUtil.Button("X", "delete", Color.red, GUILayout.Width(30f)))
            {
                m_Clips.RemoveAt(idx);
                --idx;
                continue;
            }
            m_Clips[idx] = EditorGUILayout.ObjectField(m_Clips[idx], typeof(AnimationClip), true) as AnimationClip;
            GUILayout.EndHorizontal();
        }

        GUILayout.BeginHorizontal();
        GUILayout.Space(60f);
        if (GUILayout.Button(new GUIContent("Add Clip", "add another animation clip to export")))
        {
            m_Clips.Add(null);
        }
        GUILayout.Space(60f);
        GUILayout.EndHorizontal();

        EUtil.DrawSplitter();

        bool  bHasValidEntry = _HasValidEntry();
        Color c = (bHasValidEntry) ? Color.green : Color.red;

        EUtil.PushBackgroundColor(c);
        GUIUtil.PushGUIEnable(bHasValidEntry);
        GUILayout.BeginHorizontal();
        GUILayout.Space(60f);
        if (GUILayout.Button("Export!"))
        {
            string saveDir  = _GetSaveDirectory();
            string filePath = EditorUtility.SaveFilePanel("Select export file path", saveDir, "anim", "dae");
            if (filePath.Length > 0)
            {
                string recDir = System.IO.Path.GetDirectoryName(filePath);
                _RecordSaveDirectory(recDir);

                SkinnedMeshRenderer[] smrArr = m_SMRs.TakeWhile(x => x != null).ToArray();
                MeshFilter[]          mfArr  = m_MFs.TakeWhile(x => x != null).ToArray();
                m_Clips.RemoveAll(x => x == null);

                DaeExporter exp = new DaeExporter(smrArr, mfArr, m_RootBone);
                exp.Export(m_Clips, filePath);

                AssetDatabase.Refresh();
            }
            else
            {
                EUtil.ShowNotification("Export Cancelled...");
            }
        }
        GUILayout.Space(60f);
        GUILayout.EndHorizontal();
        GUIUtil.PopGUIEnable();
        EUtil.PopBackgroundColor();
    }
Exemplo n.º 23
0
        void OnGUI()
        {
            EditorGUILayout.LabelField("Set the Roots:");
            for (int i = 0; i < m_Roots.Count; ++i)
            {
                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUI.BeginChangeCheck();
                    var root = (Transform)EditorGUILayout.ObjectField(m_Roots[i], typeof(Transform), true);
                    if (EditorGUI.EndChangeCheck())
                    {
                        m_Roots[i] = root;
                    }
                    if (EUtil.Button("-", "delete entry", Color.red, GUILayout.Width(20f)))
                    {
                        m_Roots.RemoveAt(i);
                        GUIUtility.ExitGUI();
                    }
                }
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.BeginHorizontal();
            {
                GUILayout.Space(40f);
                if (GUILayout.Button("Add Root Entry"))
                {
                    m_Roots.Add(null);
                }
                GUILayout.Space(40f);
            }
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(5f);

            if (GUILayout.Button(m_baking ? "Baking" : "Not Baking", EditorStyles.toolbarButton))
            {
                m_baking = !m_baking;

                if (m_baking)
                {
                    m_Trs.Clear();
                    foreach (var oneRoot in m_Roots)
                    {
                        for (var ie = oneRoot.GetRecurEnumerator(); ie.MoveNext();)
                        {
                            m_Trs.Add(ie.Current);
                        }
                    }

                    m_TrsArr = m_Trs.ToArray();
                    m_uaw    = EUtil.GetUnityAnimationWindow();
                    if (null == m_uaw)
                    {
                        m_baking = false;
                    }
                }
            }

            if (!m_baking)
            {
                EditorWindow uaw = (EditorWindow)EUtil.GetUnityAnimationWindow();
                if (uaw == null)
                {
                    EditorGUIUtility.ExitGUI();
                }
                object uawstate = EUtil.GetUnityAnimationWindowState(uaw);
                if (uawstate == null)
                {
                    EditorGUIUtility.ExitGUI();
                }
                var clip = RCall.GetField("UnityEditorInternal.AnimationWindowState",
                                          "m_ActiveAnimationClip", uawstate) as AnimationClip;
                if (clip == null)
                {
                    EditorGUIUtility.ExitGUI();
                }

                GUILayout.Space(5f);

                if (GUILayout.Button(new GUIContent("Compress Angles", "Only use this method on a clips full of keyframes"), EditorStyles.toolbarButton))
                {
                    _NormalizeRotationsInClip(uawstate, clip);
                }
            }
        }
        private void _OnGUI_Started()
        {
            _OnGUI_Started_Toolbar();

            switch (m_EditMode)
            {
            case EditMode.Fixer:
            {
                GUILayout.Space(3f);

                GUILayout.BeginHorizontal(GUILayout.Height(40f));
                {
                    GUILayout.Space(10f);
                    if (GUILayout.Button("Reset", GUILayout.ExpandHeight(true)))
                    {
                        _SetTempPivotToZero();         // call repaint
                    }
                    GUILayout.Space(3f);
                    if (GUILayout.Button("Center", GUILayout.ExpandHeight(true)))
                    {
                        m_PivotPos = _GetCenterPoint();
                        EUtil.RepaintSceneView();
                    }
                    GUILayout.Space(10f);
                }
                GUILayout.EndHorizontal();

                GUILayout.Space(10f);

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Space(10f);
                    if (EUtil.Button("Confirm", "Apply the pivot change to mesh", Color.green, GUILayout.ExpandHeight(true)))
                    {
                        MeshPivotFixer.Apply(m_InEditMF, m_PivotPos, m_PivotRot, m_bInplace);
                        _SetTempPivotToZero();
                        Dbg.Log("Modify Pivot: parameter: {0}, {1}", m_PivotPos, m_PivotRot);
                    }
                    GUILayout.Space(10f);
                }
                GUILayout.EndHorizontal();

                GUILayout.Space(10f);

                m_bInplace = EditorGUILayout.ToggleLeft("Try Edit In-place (no Undo!)", m_bInplace);

                GUILayout.Space(10f);
            }
            break;

            case EditMode.Saver:
            {
                GUILayout.Space(10f);

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Space(10f);
                    if (GUILayout.Button("Save Mesh", GUILayout.ExpandHeight(true)))
                    {
                        EUtil.SaveMeshToAssetDatabase(m_InEditMF.sharedMesh);
                    }
                    GUILayout.Space(10f);
                }
                GUILayout.EndHorizontal();

                GUILayout.Space(10f);
            }
            break;
            }
        }