Esempio n. 1
0
        /// <summary>
        /// 绘制单个element
        /// </summary>
        /// <param name="_rect"></param>
        /// <param name="_index"></param>
        /// <param name="_isActive"></param>
        /// <param name="_isFocused"></param>
        private void DrawElementCallBack(Rect _rect, int _index, bool _isActive, bool _isFocused)
        {
            _rect.y     += 2;
            _rect.height = EditorGUIUtility.singleLineHeight;

            State state = stateList[_index];

            _rect.xMax = _rect.xMax / 10.0f;
            GUI.Label(_rect, state.LayerName, EditorStyles.label);
            _rect.xMin  = _rect.xMax;
            _rect.xMax *= 10.0f;

            _rect.xMax = _rect.xMax / 2.5f;
            GUI.Label(_rect, state.StatePath);
            _rect.xMin  = _rect.xMax;
            _rect.xMax *= 2.5f;

            if (state.value.GetType() == typeof(AnimatorState))
            {
                _rect.xMax = _rect.xMax / 1.5f;

                EditorGUI.ObjectField(_rect, state.value, typeof(AnimatorState), false);

                _rect.xMin  = _rect.xMax;
                _rect.xMax *= 1.5f;

                AnimatorState animatorState = (AnimatorState)state.value;

                animatorState.motion = EditorGUI.ObjectField(_rect, animatorState.motion, typeof(Motion), false) as Motion;
            }
            else
            {
                _rect.xMax = _rect.xMax / 1.5f;

                EditorGUI.ObjectField(_rect, state.value, typeof(BlendTree), false);

                _rect.xMin  = _rect.xMax;
                _rect.xMax *= 1.5f;

                BlendTree blendTree = (BlendTree)state.value;

                int index = int.Parse((state.StatePath.Substring(state.StatePath.Length - 3, 3)).Split('[', ']')[1]);

                if (index < blendTree.children.Length)
                {
                    var motion = EditorGUI.ObjectField(_rect, blendTree.children[index].motion, typeof(Motion), false) as Motion;

                    if (motion != blendTree.children[index].motion)
                    {
                        AnimatorCopy.OverrideBlendTree(blendTree, index, motion);
                    }
                }
            }
        }
Esempio n. 2
0
        private void OnEnable()
        {
            animatorCopy = new AnimatorCopy();
            animatorCopy.OnGetConfig();

            serializedObj = new SerializedObject(this);

            reorderableList = new UnityEditorInternal.ReorderableList(stateList, typeof(State), true, true, false, false);

            reorderableList.drawHeaderCallback            = DrawHeaderCallBack;
            reorderableList.drawElementCallback           = DrawElementCallBack;
            reorderableList.drawElementBackgroundCallback = DrawElementBackgroundCallBack;
        }
Esempio n. 3
0
        /// <summary>
        /// 移除motion
        /// </summary>
        public void RemoveMotion()
        {
            if (value.GetType() == typeof(AnimatorState))
            {
                AnimatorState animatorState = (AnimatorState)value;
                animatorState.motion = null;
            }
            else
            {
                BlendTree blendTree = (BlendTree)value;

                int index = int.Parse((statePath.Substring(statePath.Length - 3, 3)).Split('[', ']')[1]);

                AnimatorCopy.OverrideBlendTree(blendTree, index, null);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 关联motion
        /// </summary>
        /// <param name="_prePath"></param>
        /// <param name="_filePath"></param>
        /// <param name="_log"></param>
        /// <returns></returns>
        public bool SetMotion(string _prePath, string _filePath, out string _log)
        {
            if (value == null)
            {
                _log = string.Format("{0}/{1}:value is null", layerName, statePath);

                return(false);
            }

            //string motionName = string.Format("{0}{1}{2}", _prePath, value.name, ".FBX");
            string motionName = string.Format("{0}{1}{2}", _filePath, value.name, ".FBX");

            //Load AnimationClip
            AnimationClip clip = AssetDatabase.LoadAssetAtPath(motionName, typeof(AnimationClip)) as AnimationClip;

            if (clip != null)
            {
                if (value.GetType() == typeof(AnimatorState))
                {
                    ((AnimatorState)value).motion = clip;
                }
                else
                {
                    BlendTree blendTree = (BlendTree)value;
                    int       index     = int.Parse((statePath.Substring(statePath.Length - 3, 3)).Split('[', ']')[1]);

                    AnimatorCopy.OverrideBlendTree(blendTree, index, clip);
                }

                _log = string.Empty;

                return(true);
            }

            _log = string.Format("Can't get AnimationClip by path : {0}{1}", _prePath, motionName);

            return(false);
        }