public static void MakeFromAnimationClip(MenuCommand a_cmd)
        {
            AnimationClip clip = (AnimationClip)a_cmd.context;

            MxMAnimationClipComposite mxmClip = ScriptableObject.CreateInstance <MxMAnimationClipComposite>();

            mxmClip.SetPrimaryAnim(clip);

            string path = AssetDatabase.GetAssetPath(Selection.activeObject);

            if (path == "")
            {
                path = "Assets";
            }
            else if (Path.GetExtension(path) != "")
            {
                path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), "");
            }

            string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(path + "/" + clip.name + "_MxMComp.asset");

            AssetDatabase.CreateAsset(mxmClip, assetPathAndName);

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            EditorUtility.FocusProjectWindow();
            Selection.activeObject = mxmClip;
        }
Пример #2
0
        public void ApplySettings(int a_settingsToApply)
        {
            SerializedProperty spCompositeList = m_spCategory.FindPropertyRelative("Composites");

            if (spCompositeList != null)
            {
                for (int i = 0; i < spCompositeList.arraySize; ++i)
                {
                    SerializedProperty spComposite = spCompositeList.GetArrayElementAtIndex(i);

                    if (spComposite != null)
                    {
                        MxMAnimationClipComposite composite = spComposite.objectReferenceValue as MxMAnimationClipComposite;

                        if (composite != null)
                        {
                            SerializedObject soClipComposite = new SerializedObject(composite);

                            switch (a_settingsToApply)
                            {
                            case 0:     //Require Tags
                            {
                                SerializedProperty spRequireTags = soClipComposite.FindProperty("GlobalTags");
                                spRequireTags.intValue = m_spRequireTags.intValue;
                            }
                            break;

                            case 1:     //Favour Tags
                            {
                                SerializedProperty spFavourTags = soClipComposite.FindProperty("GlobalFavourTags");
                                spFavourTags.intValue = m_spFavourTags.intValue;
                            }
                            break;

                            case 2:     //All Settings
                            {
                                SerializedProperty spIgnoreEdges           = soClipComposite.FindProperty("IgnoreEdges");
                                SerializedProperty spExtrapolateTrajectory = soClipComposite.FindProperty("ExtrapolateTrajectory");
                                SerializedProperty spFlattenTrajectory     = soClipComposite.FindProperty("FlattenTrajectory");
                                SerializedProperty spRuntimeSplicing       = soClipComposite.FindProperty("RuntimeSplicing");
                                SerializedProperty spRequireTags           = soClipComposite.FindProperty("GlobalTags");
                                SerializedProperty spFavourTags            = soClipComposite.FindProperty("GlobalFavourTags");

                                spIgnoreEdges.boolValue           = m_spIgnoreEdges.boolValue;
                                spFlattenTrajectory.boolValue     = m_spFlattenTrajectory.boolValue;
                                spRuntimeSplicing.boolValue       = m_spRuntimeSplicing.boolValue;
                                spExtrapolateTrajectory.boolValue = m_spExtrapolate.boolValue;
                                spFavourTags.intValue             = m_spFavourTags.intValue;
                                spRequireTags.intValue            = m_spRequireTags.intValue;
                            }
                            break;
                            }

                            soClipComposite.ApplyModifiedProperties();
                        }
                    }
                }
            }
        }
        public static void SetData(MxMAnimationClipComposite a_data)
        {
            if (a_data != null)
            {
                m_data = a_data;
                m_data.VerifyData();

                m_data.GenerateRootLookupTable();

                m_soData = new SerializedObject(m_data);

                m_spPrimaryClip = m_soData.FindProperty("PrimaryClip");
                m_spBeforeClips = m_soData.FindProperty("BeforeClips");
                m_spAfterClips  = m_soData.FindProperty("AfterClips");

                m_spLooping               = m_soData.FindProperty("Looping");
                m_spIgnoreEdges           = m_soData.FindProperty("IgnoreEdges");
                m_spExtrapolateTrajectory = m_soData.FindProperty("ExtrapolateTrajectory");
                m_spFlattenTrajectory     = m_soData.FindProperty("FlattenTrajectory");
                m_spRuntimeSplicing       = m_soData.FindProperty("RuntimeSplicing");

                m_spGlobalTags       = m_soData.FindProperty("GlobalTags");
                m_spGlobalFavourTags = m_soData.FindProperty("GlobalFavourTags");
                m_spTagTracks        = m_soData.FindProperty("TagTracks");
                m_spEvents           = m_soData.FindProperty("Events");

                m_spTargetPreProcessData = m_soData.FindProperty("m_targetPreProcessData");
                m_spTargetAnimModule     = m_soData.FindProperty("m_targetAnimModule");
                m_spTargetPrefab         = m_soData.FindProperty("m_targetPrefab");

                if (m_spTargetPreProcessData.objectReferenceValue != null)
                {
                    if (m_spTargetPrefab.objectReferenceValue == null)
                    {
                        SerializedProperty spTargetPrefab = m_spTargetPreProcessData.FindPropertyRelative("m_targetPrefab");

                        if (spTargetPrefab != null && spTargetPrefab.objectReferenceValue != null)
                        {
                            m_spTargetPrefab.objectReferenceValue = spTargetPrefab.objectReferenceValue;
                            m_soData.ApplyModifiedPropertiesWithoutUndo();
                        }
                    }
                }

                MxMSettings settings = MxMSettings.Instance();
                if (settings != null)
                {
                    settings.ActiveComposite = a_data;
                }

                if (MxMTaggingWindow.Exists())
                {
                    MxMTaggingWindow.Inst().SetTarget(a_data);
                }
            }
        }
        //===========================================================================================

        /**
         *  @brief
         *
         *********************************************************************************************/
        public static void SetData(MxMAnimationClipComposite a_data)
        {
            if (a_data == null)
            {
                return;
            }

            m_compositeData = a_data;
            MxMAnimationClipCompositeWindow.SetData(m_compositeData);
            m_nextAnimType = EMxMAnimtype.Composite;
        }
        public static bool OpenAssetEditor(int a_instanceID, int a_line)
        {
            MxMAnimationClipComposite data = EditorUtility.InstanceIDToObject(
                a_instanceID) as MxMAnimationClipComposite;

            if (data != null)
            {
                data.ValidateBaseData();
                MxMAnimConfigWindow.ShowWindow();
                MxMAnimConfigWindow.SetData(data);

                return true;
            }

            return false;
        }
        public CompositeCategory(CompositeCategory a_copy, ScriptableObject a_parentObj)
        {
            CatagoryName = a_copy.CatagoryName;
            Composites   = new List <MxMAnimationClipComposite>(a_copy.Composites.Count + 1);

            IgnoreEdges_default       = a_copy.IgnoreEdges_default;
            Extrapolate_default       = a_copy.Extrapolate_default;
            FlattenTrajectory_default = a_copy.FlattenTrajectory_default;
            RuntimeSplicing_default   = a_copy.RuntimeSplicing_default;
            RequireTags_default       = a_copy.RequireTags_default;
            FavourTags_default        = a_copy.FavourTags_default;

            foreach (MxMAnimationClipComposite sourceComposite in a_copy.Composites)
            {
                MxMAnimationClipComposite newComposite = ScriptableObject.CreateInstance <MxMAnimationClipComposite>();
                newComposite.CopyData(sourceComposite);
                newComposite.name      = sourceComposite.name;
                newComposite.hideFlags = HideFlags.HideInHierarchy;

                MxMPreProcessData targetPreProcess = a_parentObj as MxMPreProcessData;
                AnimationModule   targetAnimModule = a_parentObj as AnimationModule;

                if (targetPreProcess != null)
                {
                    newComposite.TargetPreProcess = targetPreProcess;
                    newComposite.TargetAnimModule = null;
                }
                else if (targetAnimModule != null)
                {
                    newComposite.TargetPreProcess = null;
                    newComposite.TargetAnimModule = targetAnimModule;
                }

                EditorUtility.SetDirty(newComposite);

                if (a_parentObj != null)
                {
                    AssetDatabase.AddObjectToAsset(newComposite, a_parentObj);
                }

                Composites.Add(newComposite);
            }
        }
        public void OnGUI(Rect a_position)
        {
            if (m_data == null)
            {
                MxMSettings settings = MxMSettings.Instance();
                if (settings != null)
                {
                    m_data = settings.ActiveComposite;

                    if (m_data != null)
                    {
                        SetData(m_data);
                    }
                }
            }

            if (m_data != null)
            {
                Rect  viewRect      = new Rect(0f, 18f, a_position.width, a_position.height - 36f);
                float requiredWidth = (m_data.AnimAfterClips.Count + m_data.AnimBeforeClips.Count + 2) * (s_animSlotSizeSmall + s_animSlotSpacing) + (s_animSlotSize + s_animSlotSpacing);

                if (requiredWidth > a_position.width)
                {
                    Rect scrollRect = new Rect((a_position.width - requiredWidth) / 2f, 18f, Mathf.Max(requiredWidth, a_position.width), a_position.height - 36f);
                    m_scrollPosition = GUI.BeginScrollView(viewRect, m_scrollPosition, scrollRect);
                }

                Rect baseAnimRect = new Rect(a_position.width / 2f - s_animSlotSize / 2f,
                                             a_position.height / 2f - s_animSlotSize / 2f,
                                             s_animSlotSize, s_animSlotSize);

                ManageSlot(baseAnimRect, m_data.PrimaryClip, "\n\n\nPrimary Anim");

                if (m_data.BeforeClips == null)
                {
                    m_data.BeforeClips = new List <AnimationClip>();
                }

                if (m_data.AfterClips == null)
                {
                    m_data.AfterClips = new List <AnimationClip>();
                }

                if (m_data.PrimaryClip != null)
                {
                    if (!m_spLooping.boolValue)
                    {
                        Rect slotRect = new Rect(a_position.width / 2f + s_animSlotSize / 2f + s_animSlotSpacing,
                                                 a_position.height / 2f - s_animSlotSizeSmall / 2f,
                                                 s_animSlotSizeSmall, s_animSlotSizeSmall);

                        for (int i = 0; i < m_data.AfterClips.Count + 1; ++i)
                        {
                            ManageSlot(slotRect, i < m_data.AfterClips.Count ? m_data.AfterClips[i] : null,
                                       "\n\nAfter\nAnim", EAnimType.Future, i);

                            slotRect.x += s_animSlotSizeSmall + s_animSlotSpacing;
                        }

                        slotRect = new Rect(a_position.width / 2f - s_animSlotSize / 2f - s_animSlotSpacing - s_animSlotSizeSmall,
                                            a_position.height / 2f - s_animSlotSizeSmall / 2f,
                                            s_animSlotSizeSmall, s_animSlotSizeSmall);

                        for (int i = 0; i < m_data.BeforeClips.Count + 1; ++i)
                        {
                            ManageSlot(slotRect, i < m_data.BeforeClips.Count ? m_data.BeforeClips[i] : null,
                                       "\n\nBefore\nAnim", EAnimType.Past, i);

                            slotRect.x -= s_animSlotSizeSmall + s_animSlotSpacing;
                        }
                    }

                    Rect settingsRect = new Rect(baseAnimRect.x - s_animSlotSpacing / 2f,
                                                 baseAnimRect.y + baseAnimRect.height + 10f,
                                                 baseAnimRect.width + s_animSlotSpacing,
                                                 baseAnimRect.height * 2f);

                    DrawSettings(settingsRect);
                }

                Event evt = Event.current;

                if (evt.isKey && evt.keyCode == KeyCode.Delete)
                {
                    switch (evt.keyCode)
                    {
                    case KeyCode.Delete:
                    {
                        //Manage delete key
                        switch (m_selectionType)
                        {
                        case EAnimType.Current:
                        {
                            m_spPrimaryClip.objectReferenceValue = null;

                            m_data.ClearRootLookupTable();
                        }
                        break;

                        case EAnimType.Future:
                        {
                            if (m_selectionId < m_spAfterClips.arraySize)
                            {
                                if (m_spAfterClips.GetArrayElementAtIndex(m_selectionId) != null)
                                {
                                    m_spAfterClips.DeleteArrayElementAtIndex(m_selectionId);
                                }

                                m_spAfterClips.DeleteArrayElementAtIndex(m_selectionId);
                            }
                        }
                        break;

                        case EAnimType.Past:
                        {
                            if (m_selectionId < m_spBeforeClips.arraySize)
                            {
                                if (m_spBeforeClips.GetArrayElementAtIndex(m_selectionId) != null)
                                {
                                    m_spBeforeClips.DeleteArrayElementAtIndex(m_selectionId);
                                }

                                m_spBeforeClips.DeleteArrayElementAtIndex(m_selectionId);
                            }
                        }
                        break;
                        }
                    }
                    break;

                    case KeyCode.RightArrow:
                    {
                        NextComposite();
                    }
                    break;

                    case KeyCode.LeftArrow:
                    {
                        LastComposite();
                    }
                    break;
                    }



                    m_selectionType = EAnimType.None;
                    m_selectionId   = 0;

                    MxMAnimConfigWindow.Inst().Repaint();
                }
                if (requiredWidth > a_position.width)
                {
                    GUI.EndScrollView();
                }


                EditorGUILayout.BeginVertical();
                EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.Height(20f), GUILayout.ExpandWidth(true));
                if (GUILayout.Button(new GUIContent("Open Timeline"), EditorStyles.toolbarButton))
                {
                    MxMTaggingWindow.ShowWindow();
                }

                if (GUILayout.Button(new GUIContent("Locate Asset"), EditorStyles.toolbarButton))
                {
                    if (m_spTargetPreProcessData.objectReferenceValue != null)
                    {
                        EditorGUIUtility.PingObject(m_spTargetPreProcessData.objectReferenceValue);
                    }

                    if (m_spTargetAnimModule.objectReferenceValue != null)
                    {
                        EditorGUIUtility.PingObject(m_spTargetAnimModule.objectReferenceValue);
                    }
                }

                GUILayout.FlexibleSpace();

                if (GUILayout.Button(EditorGUIUtility.IconContent("back").image, EditorStyles.toolbarButton))
                {
                    LastComposite();
                }

                if (GUILayout.Button(EditorGUIUtility.IconContent("forward").image, EditorStyles.toolbarButton))
                {
                    NextComposite();
                }

                GUILayout.Space(5f);

                if (GUILayout.Button(new GUIContent("Locate Animation"), EditorStyles.toolbarButton))
                {
                    switch (m_selectionType)
                    {
                    case EAnimType.None:
                    case EAnimType.Current:
                    {
                        if (m_spPrimaryClip.objectReferenceValue != null)
                        {
                            EditorGUIUtility.PingObject(m_spPrimaryClip.objectReferenceValue);
                        }
                    }
                    break;

                    case EAnimType.Future:
                    {
                        if (m_selectionId < m_spAfterClips.arraySize)
                        {
                            SerializedProperty spCLip = m_spAfterClips.GetArrayElementAtIndex(m_selectionId);

                            if (spCLip != null && spCLip.objectReferenceValue != null)
                            {
                                EditorGUIUtility.PingObject(spCLip.objectReferenceValue);
                            }
                        }
                    }
                    break;

                    case EAnimType.Past:
                    {
                        if (m_selectionId < m_spBeforeClips.arraySize)
                        {
                            SerializedProperty spCLip = m_spBeforeClips.GetArrayElementAtIndex(m_selectionId);

                            if (spCLip != null && spCLip.objectReferenceValue != null)
                            {
                                EditorGUIUtility.PingObject(spCLip.objectReferenceValue);
                            }
                        }
                    }
                    break;
                    }
                }

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

                EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.Height(20f), GUILayout.ExpandWidth(true));
                EditorGUI.BeginDisabledGroup(true);
                if (m_spTargetPreProcessData.objectReferenceValue != null)
                {
                    EditorGUILayout.ObjectField(m_spTargetPreProcessData, GUILayout.Width(300f));
                }
                else
                {
                    EditorGUILayout.ObjectField(m_spTargetAnimModule, GUILayout.Width(300f));
                }

                GUILayout.FlexibleSpace();

                EditorGUILayout.ObjectField(m_spTargetPrefab, GUILayout.Width(300f));

                EditorGUI.EndDisabledGroup();

                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();


                if (m_soData != null)
                {
                    m_soData.ApplyModifiedProperties();
                }
            }
            else
            {
                GUILayout.Space(18f);
                EditorGUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                EditorGUILayout.LabelField("No Composite Selected.", EditorStyles.boldLabel);
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();
            }
        }
        public void CopyData(MxMAnimationClipComposite a_copy)
        {
            PrimaryClip = a_copy.PrimaryClip;
            BeforeClips = new List<AnimationClip>(a_copy.BeforeClips);
            AfterClips = new List<AnimationClip>(a_copy.AfterClips);

            Looping= a_copy.Looping;
            IgnoreEdges = a_copy.IgnoreEdges;
            ExtrapolateTrajectory = a_copy.ExtrapolateTrajectory;
            FlattenTrajectory = a_copy.FlattenTrajectory;
            RuntimeSplicing = a_copy.RuntimeSplicing;
            UseSpeedMods = a_copy.UseSpeedMods;

            GlobalTags = a_copy.GlobalTags;
            GlobalFavourTags = a_copy.GlobalFavourTags;

            TagTracks = new List<TagTrack>(a_copy.TagTracks.Count + 1);
            foreach(TagTrack track in a_copy.TagTracks)
            {
                TagTracks.Add(new TagTrack(track));
            }

            for (int i = 0; i < a_copy.TagTracks.Count; ++i)
            {
                TagTracks.Add(new TagTrack(a_copy.TagTracks[i]));
            }

            FavourTagTracks = new List<TagTrack>(a_copy.FavourTagTracks.Count + 1);
            foreach(TagTrack track  in a_copy.FavourTagTracks)
            {
                FavourTagTracks.Add(new TagTrack(track));
            }

            UserBoolTracks = new List<TagTrackBase>(a_copy.UserBoolTracks.Count + 1);
            foreach(TagTrackBase track in a_copy.UserBoolTracks)
            {
                UserBoolTracks.Add(new TagTrackBase(track));
            }

            Events = new List<EventMarker>(a_copy.Events.Count + 1);
            foreach(EventMarker marker in a_copy.Events)
            {
                Events.Add(new EventMarker(marker));
            }

            m_targetPreProcessData = a_copy.m_targetPreProcessData;
            m_targetAnimModule = a_copy.m_targetAnimModule;
            m_targetPrefab = a_copy.m_targetPrefab;

            PoseList = null;

            LeftFootStepTrack = new FootStepTagTrack(a_copy.LeftFootStepTrack);
            RightFootStepTrack = new FootStepTagTrack(a_copy.RightFootStepTrack);
            WarpPositionTrack = new TagTrackBase(a_copy.WarpPositionTrack);
            WarpRotationTrack = new TagTrackBase(a_copy.WarpRotationTrack);
            EnableRootMotionTrack = new TagTrackBase(a_copy.EnableRootMotionTrack);
            PoseFavourTrack = new FloatTagTrack(a_copy.PoseFavourTrack);
            WarpTrajLatTrack = new TagTrackBase(a_copy.WarpTrajLatTrack);
            WarpTrajLongTrack = new TagTrackBase(a_copy.WarpTrajLongTrack);

            MotionModifier = new MotionModifyData(a_copy.MotionModifier, this);
        }