Exemple #1
0
        public override void OnInspectorGUI()
        {
            Undo.RecordObject(Target, Target.name);

            EditorGUI.BeginDisabledGroup(Target.Baking);

            if (Utility.GUIButton("Load Animations", UltiDraw.DarkGrey, UltiDraw.White))
            {
                Target.LoadAnimations();
            }

            Utility.SetGUIColor(UltiDraw.Grey);
            using (new EditorGUILayout.VerticalScope("Box")) {
                Utility.ResetGUIColor();
                EditorGUILayout.IntField("Animations", Target.Animations.Length);
                for (int i = 0; i < Target.Animations.Length; i++)
                {
                    Target.Import[i] = EditorGUILayout.Toggle(Target.Animations[i].name, Target.Import[i]);
                }
            }
            EditorGUI.EndDisabledGroup();
            Target.Skeleton    = (Actor)EditorGUILayout.ObjectField("Skeleton", Target.Skeleton, typeof(Actor), true);
            Target.Retarget    = (Actor)EditorGUILayout.ObjectField("Retarget", Target.Retarget, typeof(Actor), true);
            Target.Source      = EditorGUILayout.TextField("Source", Target.Source);
            Target.Destination = EditorGUILayout.TextField("Destination", Target.Destination);
            Target.Speed       = EditorGUILayout.FloatField("Speed", Target.Speed);
            Target.Framerate   = EditorGUILayout.IntField("Framerate", Target.Framerate);
            Target.Smoothing   = EditorGUILayout.IntField("Smoothing", Target.Smoothing);
            Target.Demo        = EditorGUILayout.Toggle("Demo", Target.Demo);

            EditorGUILayout.BeginHorizontal();
            if (Target.Corrections.Length != Target.Skeleton.Bones.Length)
            {
                Target.Corrections = new Vector3[Target.Skeleton.Bones.Length];
            }
            if (Target.Mapping.Length != Target.Skeleton.Bones.Length)
            {
                Target.Mapping = new int[Target.Skeleton.Bones.Length];
            }
            if (Target.Delta.Length != Target.Skeleton.Bones.Length)
            {
                Target.Delta = new Vector3[Target.Skeleton.Bones.Length];
            }
            if (Utility.GUIButton("Detect Mapping", UltiDraw.DarkGrey, UltiDraw.White))
            {
                Target.DetectMapping();
            }
            if (Utility.GUIButton("Compute Delta", UltiDraw.DarkGrey, UltiDraw.White))
            {
                Target.ComputeDelta();
            }
            EditorGUILayout.EndHorizontal();

            string[] skeletonNames = Target.Skeleton.GetBoneNames();
            string[] retargetNames = Target.Retarget.GetBoneNames();
            for (int i = 0; i < Target.Skeleton.Bones.Length; i++)
            {
                Utility.SetGUIColor(Target.Corrections[i] != Vector3.zero ? UltiDraw.Cyan : UltiDraw.Grey);
                using (new EditorGUILayout.VerticalScope("Box")) {
                    Utility.ResetGUIColor();
                    EditorGUILayout.BeginHorizontal();
                    EditorGUI.BeginDisabledGroup(true);
                    EditorGUILayout.TextField(skeletonNames[i]);
                    EditorGUI.EndDisabledGroup();
                    Target.Mapping[i] = EditorGUILayout.Popup(Target.Mapping[i], retargetNames);
                    EditorGUILayout.EndHorizontal();
                    Target.Delta[i]       = EditorGUILayout.Vector3Field("Delta", Target.Delta[i]);
                    Target.Corrections[i] = EditorGUILayout.Vector3Field("Correction", Target.Corrections[i]);
                }
            }

            if (!Target.Baking)
            {
                if (Utility.GUIButton("Bake", UltiDraw.DarkGrey, UltiDraw.White))
                {
                    Target.StartCoroutine(Target.Bake());
                }
            }
            else
            {
                EditorGUI.DrawRect(new Rect(EditorGUILayout.GetControlRect().x, EditorGUILayout.GetControlRect().y, Target.GetNormalizedTimestamp() * EditorGUILayout.GetControlRect().width, 25f), UltiDraw.Cyan.Transparent(0.75f));
                EditorGUILayout.LabelField("Animation: " + Target.Current.name);
                EditorGUILayout.LabelField("Recorded Samples: " + Target.Samples.Count);
                EditorGUILayout.LabelField("Recorded Time: " + Target.GetRecordedTime());
                EditorGUILayout.LabelField("Recording FPS: " + Target.GetRecordingFPS());
                if (Utility.GUIButton("Stop", UltiDraw.DarkGrey, UltiDraw.White))
                {
                    Target.Abort();
                }
            }

            if (GUI.changed)
            {
                EditorUtility.SetDirty(Target);
            }
        }
        public override void OnInspectorGUI()
        {
            Undo.RecordObject(Target, Target.name);

            Target.Setup();

            EditorGUI.BeginDisabledGroup(Target.Baking);

            EditorGUILayout.BeginHorizontal();
            if (Utility.GUIButton("Add Animation", UltiDraw.DarkGrey, UltiDraw.White))
            {
                ArrayExtensions.Expand(ref Target.Animations);
            }
            if (Utility.GUIButton("Remove Animation", UltiDraw.DarkGrey, UltiDraw.White))
            {
                ArrayExtensions.Shrink(ref Target.Animations);
            }
            EditorGUILayout.EndHorizontal();
            for (int i = 0; i < Target.Animations.Length; i++)
            {
                Object o = (Object)EditorGUILayout.ObjectField("Animation " + (i + 1), Target.Animations[i], typeof(Object), true);
                if (Target.Animations[i] != o)
                {
                    if (AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPath(o), typeof(AnimationClip)) != null)
                    {
                        Target.Animations[i] = o;
                    }
                    else
                    {
                        Target.Animations[i] = null;
                    }
                }
            }

            EditorGUILayout.BeginHorizontal();
            if (Utility.GUIButton("Add Refinement", UltiDraw.DarkGrey, UltiDraw.White))
            {
                ArrayExtensions.Add(ref Target.Refinements, new Refinement());
            }
            if (Utility.GUIButton("Remove Refinement", UltiDraw.DarkGrey, UltiDraw.White))
            {
                ArrayExtensions.Shrink(ref Target.Refinements);
            }
            EditorGUILayout.EndHorizontal();
            for (int i = 0; i < Target.Refinements.Length; i++)
            {
                Utility.SetGUIColor(UltiDraw.Grey);
                using (new EditorGUILayout.VerticalScope("Box")) {
                    Utility.ResetGUIColor();
                    EditorGUILayout.BeginHorizontal();
                    Target.Refinements[i].TargetBone = Mathf.Clamp(EditorGUILayout.IntField("Refinement " + (i + 1) + " Target Bone", Target.Refinements[i].TargetBone), 0, Target.GetActor().Bones.Length - 1);
                    EditorGUILayout.LabelField(Target.Retarget.Bones[Target.Refinements[i].TargetBone].GetName());
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.BeginHorizontal();
                    if (Utility.GUIButton("Add Reference", UltiDraw.DarkGrey, UltiDraw.White))
                    {
                        ArrayExtensions.Expand(ref Target.Refinements[i].ReferenceBones);
                    }
                    if (Utility.GUIButton("Remove Referece", UltiDraw.DarkGrey, UltiDraw.White))
                    {
                        ArrayExtensions.Shrink(ref Target.Refinements[i].ReferenceBones);
                    }
                    EditorGUILayout.EndHorizontal();
                    for (int j = 0; j < Target.Refinements[i].ReferenceBones.Length; j++)
                    {
                        EditorGUILayout.BeginHorizontal();
                        Target.Refinements[i].ReferenceBones[j] = Mathf.Clamp(EditorGUILayout.IntField("Reference " + (j + 1), Target.Refinements[i].ReferenceBones[j]), 0, Target.GetActor().Bones.Length - 1);
                        EditorGUILayout.LabelField(Target.Retarget.Bones[Target.Refinements[i].ReferenceBones[j]].GetName());
                        EditorGUILayout.EndHorizontal();
                    }
                }
            }

            EditorGUI.EndDisabledGroup();

            Target.Retarget    = (Actor)EditorGUILayout.ObjectField("Retarget", Target.Retarget, typeof(Actor), true);
            Target.Destination = EditorGUILayout.TextField("Destination", Target.Destination);
            Target.Speed       = EditorGUILayout.FloatField("Speed", Target.Speed);
            Target.Framerate   = EditorGUILayout.IntField("Framerate", Target.Framerate);

            Utility.SetGUIColor(UltiDraw.Grey);
            using (new EditorGUILayout.VerticalScope("Box")) {
                Utility.ResetGUIColor();
                for (int i = 0; i < Target.Mapping.Length; i++)
                {
                    Utility.SetGUIColor(Target.Corrections[i].magnitude != 0f ? UltiDraw.Cyan : UltiDraw.Grey);
                    Target.Corrections[i] = EditorGUILayout.Vector3Field(Target.GetActor().Bones[i].GetName() + " <-> " + Target.Retarget.Bones[i].GetName(), Target.Corrections[i]);
                    Utility.ResetGUIColor();
                }
            }

            if (!Target.Baking)
            {
                if (Utility.GUIButton("Bake", UltiDraw.DarkGrey, UltiDraw.White))
                {
                    Target.StartCoroutine(Target.Bake());
                }
            }
            else
            {
                EditorGUI.DrawRect(new Rect(EditorGUILayout.GetControlRect().x, EditorGUILayout.GetControlRect().y, Target.GetNormalizedTimestamp() * EditorGUILayout.GetControlRect().width, 25f), UltiDraw.Cyan.Transparent(0.75f));
                EditorGUILayout.LabelField("Animation: " + Target.Current.name);
                EditorGUILayout.LabelField("Recorded Samples: " + Target.Samples.Count);
                EditorGUILayout.LabelField("Recorded Time: " + Target.GetRecordedTime());
                EditorGUILayout.LabelField("Recording FPS: " + Target.GetRecordingFPS());
                if (Utility.GUIButton("Stop", UltiDraw.DarkGrey, UltiDraw.White))
                {
                    Target.Abort();
                }
            }

            if (GUI.changed)
            {
                EditorUtility.SetDirty(Target);
            }
        }