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

            MxMAnimationIdleSet idleSet = ScriptableObject.CreateInstance <MxMAnimationIdleSet>();

            idleSet.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 + "_MxMIdleSet.asset");

            AssetDatabase.CreateAsset(idleSet, assetPathAndName);

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            EditorUtility.FocusProjectWindow();
            Selection.activeObject = idleSet;
        }
        public static void SetData(MxMAnimationIdleSet a_data)
        {
            if (a_data != null)
            {
                m_data = a_data;

                m_data.VerifyData();

                m_soData = new SerializedObject(m_data);

                m_spPrimaryClip     = m_soData.FindProperty("PrimaryClip");
                m_spSecondaryClips  = m_soData.FindProperty("SecondaryClips");
                m_spTransitionClips = m_soData.FindProperty("TransitionClips");
                m_spTags            = m_soData.FindProperty("Tags");
                m_spFavourTags      = m_soData.FindProperty("FavourTags");
                m_spMinLoops        = m_soData.FindProperty("MinLoops");
                m_spMaxLoops        = m_soData.FindProperty("MaxLoops");

                m_spTargetPreProcessData  = m_soData.FindProperty("m_targetPreProcessData");
                m_spTargetAnimationModule = m_soData.FindProperty("m_targetAnimModule");

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

                if (MxMTaggingWindow.Exists())
                {
                    MxMTaggingWindow.Inst().SetTarget(a_data);
                }
            }
        }
Exemplo n.º 3
0
        //============================================================================================
        /**
        *  @brief 
        *         
        *********************************************************************************************/
        public void CopyPreProcessData(MxMPreProcessData a_preProcessData)
        {
            m_overrideTagModule = a_preProcessData.OverrideTagModule;
            m_overrideEventModule = a_preProcessData.OverrideEventModule;
            m_overrideConfigModule = a_preProcessData.OverrideConfigModule;

            List<CompositeCategory> sourceCategories = a_preProcessData.CompositeCategories;
            m_compositeCategories = new List<CompositeCategory>(sourceCategories.Count + 1);

            foreach (CompositeCategory sourceCategory in sourceCategories)
            {
                CompositeCategory newCategory = new CompositeCategory(sourceCategory, this);
                m_compositeCategories.Add(newCategory);
            }

            List<MxMAnimationIdleSet> sourceIdleSets = a_preProcessData.AnimationIdleSets;
            m_animIdleSets = new List<MxMAnimationIdleSet>(sourceIdleSets.Count + 1);

            foreach(MxMAnimationIdleSet sourceIdleSet in sourceIdleSets)
            {
                MxMAnimationIdleSet newIdleSet = ScriptableObject.CreateInstance<MxMAnimationIdleSet>();
                newIdleSet.CopyData(sourceIdleSet);
                newIdleSet.name = sourceIdleSet.name;
                newIdleSet.hideFlags = HideFlags.HideInHierarchy;
                newIdleSet.TargetAnimModule = this;
                newIdleSet.TargetPreProcess = null;

                EditorUtility.SetDirty(newIdleSet);

                AssetDatabase.AddObjectToAsset(newIdleSet, this);

                m_animIdleSets.Add(newIdleSet);
            }

            List<MxMBlendSpace> sourceBlendSpaces = a_preProcessData.BlendSpaces;
            m_blendSpaces = new List<MxMBlendSpace>(sourceBlendSpaces.Count + 1);

            foreach(MxMBlendSpace sourceBlendSpace in sourceBlendSpaces)
            {
                MxMBlendSpace newBlendSpace = ScriptableObject.CreateInstance<MxMBlendSpace>();
                newBlendSpace.CopyData(sourceBlendSpace);
                newBlendSpace.name = sourceBlendSpace.name;
                newBlendSpace.hideFlags = HideFlags.HideInHierarchy;
                newBlendSpace.TargetAnimModule = this;
                newBlendSpace.TargetPreProcess = null;

                EditorUtility.SetDirty(newBlendSpace);

                AssetDatabase.AddObjectToAsset(newBlendSpace, this);

                m_blendSpaces.Add(newBlendSpace);
            }

            EditorUtility.SetDirty(this);
        }
        //===========================================================================================

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

            m_idleSetData = a_data;
            MxMAnimationIdleSetWindow.SetData(m_idleSetData);
            m_nextAnimType = EMxMAnimtype.IdleSet;
        }
        public static bool OpenAssetEditor(int a_instanceId, int a_line)
        {
            MxMAnimationIdleSet data = EditorUtility.InstanceIDToObject(
                a_instanceId) as MxMAnimationIdleSet;

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

                return true;
            }
            
            return false;
        }
        public void CopyData(MxMAnimationIdleSet a_copy)
        {
            PrimaryClip = a_copy.PrimaryClip;
            SecondaryClips = new List<AnimationClip>(a_copy.SecondaryClips);
            TransitionClips = new List<AnimationClip>(a_copy.TransitionClips);
            Tags = a_copy.Tags;
            FavourTags = a_copy.FavourTags;
            MinLoops = a_copy.MinLoops;
            MaxLoops = a_copy.MaxLoops;

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

            PoseList = null;
        }
        public void OnGUI(Rect a_position)
        {
            if (m_data == null)
            {
                MxMSettings settings = MxMSettings.Instance();
                if (settings != null)
                {
                    m_data = settings.ActiveIdleSet;

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

            if (m_data != null)
            {
                Rect  viewRect      = new Rect(0f, 0f, a_position.width, a_position.height);
                float requiredWidth = (Mathf.Max(m_data.TransitionClips.Count, m_data.SecondaryClips.Count) + 1) * (s_animSlotSizeSmall + 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 - 18f);
                    m_scrollPosition = GUI.BeginScrollView(viewRect, m_scrollPosition, scrollRect);
                }

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

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

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

                if (m_data.PrimaryClip != null)
                {
                    Rect slotRect = new Rect(a_position.width / 2f - s_animSlotSizeSmall / 2f - (m_data.TransitionClips.Count
                                                                                                 * (s_animSlotSizeSmall + s_animSlotSpacing)) / 2f,
                                             baseAnimRect.y - s_animSlotSizeSmall - s_animSlotSpacing,
                                             s_animSlotSizeSmall, s_animSlotSizeSmall);


                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(Mathf.Max(m_data.TransitionClips.Count, m_data.SecondaryClips.Count) * (s_animSlotSizeSmall + s_animSlotSpacing));
                    EditorGUILayout.EndHorizontal();


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

                        slotRect.x += s_animSlotSizeSmall + s_animSlotSpacing;
                    }


                    slotRect = new Rect(a_position.width / 2f - s_animSlotSizeSmall / 2f - (m_data.SecondaryClips.Count
                                                                                            * (s_animSlotSizeSmall + s_animSlotSpacing)) / 2f,
                                        baseAnimRect.y + s_animSlotSize + s_animSlotSpacing,
                                        s_animSlotSizeSmall, s_animSlotSizeSmall);

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

                        slotRect.x += s_animSlotSizeSmall + s_animSlotSpacing;
                    }

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

                    DrawSettings(settingsRect);
                }


                Event evt = Event.current;

                if (evt.isKey && evt.keyCode == KeyCode.Delete)
                {
                    switch (m_selectionType)
                    {
                    case EAnimType.Primary:
                    {
                        m_spPrimaryClip.objectReferenceValue = null;
                    }
                    break;

                    case EAnimType.Secondary:
                    {
                        if (m_selectionId < m_spSecondaryClips.arraySize)
                        {
                            if (m_spSecondaryClips.GetArrayElementAtIndex(m_selectionId).objectReferenceValue != null)
                            {
                                m_spSecondaryClips.DeleteArrayElementAtIndex(m_selectionId);
                            }

                            m_spSecondaryClips.DeleteArrayElementAtIndex(m_selectionId);
                        }
                    }
                    break;

                    case EAnimType.Transition:
                    {
                        if (m_selectionId < m_spTransitionClips.arraySize)
                        {
                            if (m_spTransitionClips.GetArrayElementAtIndex(m_selectionId).objectReferenceValue != null)
                            {
                                m_spTransitionClips.DeleteArrayElementAtIndex(m_selectionId);
                            }

                            m_spTransitionClips.DeleteArrayElementAtIndex(m_selectionId);
                        }
                    }
                    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));

                GUILayout.Space(3f);

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

                GUILayout.Space(a_position.width - 190f);

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

                        case EAnimType.Secondary:
                        {
                            if (m_spSecondaryClips.arraySize > m_selectionId)
                            {
                                SerializedProperty spAnim = m_spSecondaryClips.GetArrayElementAtIndex(m_selectionId);

                                if (spAnim != null && spAnim.objectReferenceValue != null)
                                {
                                    EditorGUIUtility.PingObject(spAnim.objectReferenceValue);
                                }
                                else
                                {
                                    if (m_spPrimaryClip.objectReferenceValue != null)
                                    {
                                        EditorGUIUtility.PingObject(m_spPrimaryClip.objectReferenceValue);
                                    }
                                }
                            }
                        }
                        break;

                        case EAnimType.Transition:
                        {
                            if (m_spTransitionClips.arraySize > m_selectionId)
                            {
                                SerializedProperty spAnim = m_spTransitionClips.GetArrayElementAtIndex(m_selectionId);

                                if (spAnim != null && spAnim.objectReferenceValue != null)
                                {
                                    EditorGUIUtility.PingObject(spAnim.objectReferenceValue);
                                }
                                else
                                {
                                    if (m_spPrimaryClip.objectReferenceValue != null)
                                    {
                                        EditorGUIUtility.PingObject(m_spPrimaryClip.objectReferenceValue);
                                    }
                                }
                            }
                        }
                        break;
                        }
                    }
                    else
                    {
                        if (m_spPrimaryClip.objectReferenceValue != null)
                        {
                            EditorGUIUtility.PingObject(m_spPrimaryClip.objectReferenceValue);
                        }
                    }
                }


                if (m_soData != null)
                {
                    m_soData.ApplyModifiedProperties();
                }
            }
            else
            {
                GUILayout.Space(18f);
                EditorGUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                EditorGUILayout.LabelField("No Idle Set Selected.", EditorStyles.boldLabel);
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();
            }
        }