示例#1
0
    public override void OnInspectorGUI()
    {
        //base.OnInspectorGUI();

        CharacterAnimation character_animation = (CharacterAnimation)target;

#if SH_ASSETBUNDLE
        if (m_Prefab != null)
        {
            if (m_Prefab.PrefabState == false)
            {
                Debug.LogFormat("[{0}] CreateImport", m_Prefab.name);
                string skin = null;
                if (character_animation.CurrentSkin != null && character_animation.CurrentSkin.Asset != null)
                {
                    skin = character_animation.CurrentSkin.Asset.name;
                }
                character_animation.CreateImport();
                if (string.IsNullOrEmpty(skin) == false)
                {
                    character_animation.SetSkin(skin);
                }
            }
        }
#endif

        EditorGUILayout.BeginHorizontal();  // whole

#if SH_ASSETBUNDLE
        if (!EditorUtility.IsPersistent(character_animation))
        {
            if (GUILayout.Button("Create Import"))
            {
                character_animation.CreateImport();
                CheckAnimations();
            }
        }
#endif

        if (GUILayout.Button(string.Format("Idle Mode({0})", character_animation.GetIdleRotation())))
        {
            character_animation.SetIdleMode();
        }
        if (GUILayout.Button("Battle Mode"))
        {
            character_animation.SetBattleMode();
        }

        EditorGUILayout.EndHorizontal();  // whole


        if (character_animation.Animation == null)
        {
            return;
        }

        if (s_Animations == null || character_animation.Animation.GetClipCount() != s_Animations.Length)
        {
            CheckAnimations();
        }

        EditorGUILayout.BeginVertical();  // whole
        EditorGUILayout.Separator();

        character_animation.CheckDefaultState();

//        if (EditorApplication.isPlaying)
        {
            if (s_Util.SeparatorToolbarFold("Debug", null))
            {
                if (character_animation != null && character_animation.CurrentState != null)
                {
                    EditorGUILayout.LabelField(string.Format("{0} : {1}/{2}", character_animation.CurrentState.name, character_animation.PlaybackTime, character_animation.CurrentState.length));
                }
                else
                {
                    EditorGUILayout.LabelField("none");
                }
                if (character_animation.RootBone != null)
                {
                    if (character_animation.CurrentMoveState != null)
                    {
                        EditorGUILayout.LabelField(string.Format("RootBonePos : {0} / {1} ({2:p}), Move : {3}", character_animation.RootBonePos, character_animation.CurrentMoveState.length, character_animation.RootBonePos.x / character_animation.CurrentMoveState.length, character_animation.MoveValue));
                    }
                }
                if (character_animation.FxBone != null && character_animation.CurrentFxState != null)
                {
                    EditorGUILayout.LabelField(string.Format("FxBonePos : {0} / {1} ({2:p}), MoveFx : {3}", character_animation.FxBonePos, character_animation.CurrentFxState.fixed_length, character_animation.FxBonePos.x / character_animation.CurrentFxState.length, character_animation.MoveValueFx));
                    EditorGUILayout.LabelField(string.Format("FxBones : {0}", character_animation.FxBone.localPosition));
                }
                EditorGUILayout.Toggle("IsUIMode", character_animation.IsUIMode);
                EditorUtility.SetDirty((MonoBehaviour)character_animation);
            }
        }

        //        if (EditorApplication.isPlaying == false)
        {
            //if (EditorApplication.isPlaying == false)
            OnInspectorSkin(character_animation);
            OnInspectorPlay(character_animation);

            if (character_animation.MoveStates == null)
            {
                character_animation.MoveStates = new CharacterAnimation.MoveState[0];
            }
            if (character_animation.FxStates == null)
            {
                character_animation.FxStates = new CharacterAnimation.FxState[0];
            }
        }

        if (GUILayout.Button("Play Head"))
        {
            character_animation.PlayHead();
        }

        bool fold_move = s_Util.SeparatorToolbarFold("MoveStates", string.Format("Move States ({0})", character_animation.MoveStates.Length), false, false);
        if (GUILayout.Button("Refresh", EditorStyles.toolbarButton))
        {
            character_animation.RefreshMove(true);
        }
        s_Util.EndToolbar();

        if (fold_move == true)
        {
            foreach (CharacterAnimation.MoveState state in character_animation.MoveStates)
            {
                EditorGUILayout.BeginHorizontal();

                bool fold = false;
                if (fold_movestate.TryGetValue(state.name, out fold) == false)
                {
                    fold_movestate.Add(state.name, fold);
                }

                bool fold_new = GUILayout.Toggle(fold, state.name, "Foldout");
                if (fold_new != fold)
                {
                    fold_movestate.Remove(state.name);
                    fold_movestate.Add(state.name, fold_new);
                }

                bool new_enabled = GUILayout.Toggle(state.enabled, "");
                if (new_enabled != state.enabled)
                {
                    state.enabled = new_enabled;
                    character_animation.SetMoveState(true);
                }
                EditorGUIUtility.labelWidth = 60f;
                EditorGUILayout.LabelField("Length", state.length.ToString());
                state.fixed_length = EditorGUILayout.FloatField("Fixed", state.fixed_length);
                if (GUILayout.Button("Get"))
                {
                    state.fixed_length = state.length;
                }
                EditorGUIUtility.labelWidth = 0f;
                EditorGUILayout.EndHorizontal();

                if (fold_new == true)
                {
                    EditorCurveBinding bind = new EditorCurveBinding();
                    bind.path         = "Root";
                    bind.type         = typeof(Transform);
                    bind.propertyName = "m_LocalPosition.x";

                    AnimationClip  clip = character_animation.Animation[state.name].clip;
                    AnimationCurve data = AnimationUtility.GetEditorCurve(clip, bind);
                    foreach (var key in data.keys)
                    {
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Space(20f);
                        EditorGUILayout.LabelField(string.Format("{0} ({1})", key.time * clip.frameRate, key.time.ToString()), key.value.ToString());
                        EditorGUILayout.EndHorizontal();
                    }
                }
            }
        }

        int  enable_fx_count = character_animation.FxStates.Count(s => s.enabled);
        bool fold_fx         = s_Util.SeparatorToolbarFold("FxStates", string.Format("Fx States ({0}/{1})", enable_fx_count, character_animation.FxStates.Length), false, false);
        if (GUILayout.Button("Refresh", EditorStyles.toolbarButton))
        {
            character_animation.RefreshFx(true);
        }
        s_Util.EndToolbar();

        if (fold_fx == true)
        {
            foreach (CharacterAnimation.FxState state in character_animation.FxStates)
            {
                EditorGUILayout.BeginHorizontal();

                bool fold = false;
                if (fold_fxstate.TryGetValue(state.name, out fold) == false)
                {
                    fold_fxstate.Add(state.name, fold);
                }

                if (state.SubBoneNames == null)
                {
                    state.SubBoneNames = new string[0];
                }

                state.CheckBone(character_animation.transform);

                bool fold_new = GUILayout.Toggle(fold, string.Format("{0} ({1}/{2})", state.name, state.SubBones.Count(b => b != null), state.SubBones.Count), "Foldout");
                if (fold_new != fold)
                {
                    fold_fxstate.Remove(state.name);
                    fold_fxstate.Add(state.name, fold_new);
                }

                bool new_enabled = GUILayout.Toggle(state.enabled, "");
                if (new_enabled != state.enabled)
                {
                    state.enabled = new_enabled;
                    character_animation.SetFxState(true);
                }
                EditorGUIUtility.labelWidth = 60f;
                EditorGUILayout.LabelField("Length", state.length.ToString());
                state.fixed_length = EditorGUILayout.FloatField("Fixed", state.fixed_length);
                if (GUILayout.Button("Get"))
                {
                    state.fixed_length = state.length;
                }
                EditorGUIUtility.labelWidth = 0f;
                EditorGUILayout.EndHorizontal();

                if (fold_new == true)
                {
                    int remove_index = -1;
                    for (int bone_index = 0; bone_index < state.SubBoneNames.Length; ++bone_index)
                    {
                        EditorGUILayout.BeginHorizontal();
                        if (GUILayout.Button("-", GUILayout.Width(22f)))
                        {
                            remove_index = bone_index;
                        }
                        Transform new_bone = EditorGUILayout.ObjectField("SubBone", state.SubBones[bone_index], typeof(Transform), true) as Transform;
                        if (new_bone != state.SubBones[bone_index])
                        {
                            state.SubBones[bone_index]     = new_bone;
                            state.SubBoneNames[bone_index] = CoreUtility.GetHierachy(new_bone, character_animation.transform);
                            EditorUtility.SetDirty((MonoBehaviour)character_animation);
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    if (remove_index != -1)
                    {
                        List <string> temp_list = new List <string>(state.SubBoneNames);
                        temp_list.RemoveAt(remove_index);
                        state.SubBoneNames = temp_list.ToArray();
                    }

                    EditorGUI.indentLevel = 2;
                    {
                        Transform new_bone = EditorGUILayout.ObjectField("SubBone", null, typeof(Transform), true) as Transform;
                        if (new_bone != null)
                        {
                            Array.Resize <string>(ref state.SubBoneNames, state.SubBoneNames.Length + 1);
                            state.SubBoneNames[state.SubBoneNames.Length - 1] = CoreUtility.GetHierachy(new_bone, character_animation.transform);
                            EditorUtility.SetDirty((MonoBehaviour)character_animation);
                        }
                    }
                    EditorGUI.indentLevel = 0;

                    EditorCurveBinding bind = new EditorCurveBinding();
                    bind.path         = "fx_bone";
                    bind.type         = typeof(Transform);
                    bind.propertyName = "m_LocalPosition.x";

                    AnimationClip  clip = character_animation.Animation[state.name].clip;
                    AnimationCurve data = AnimationUtility.GetEditorCurve(clip, bind);
                    foreach (var key in data.keys)
                    {
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Space(20f);
                        EditorGUILayout.LabelField(string.Format("{0} ({1})", key.time * clip.frameRate, key.time.ToString()), key.value.ToString());
                        EditorGUILayout.EndHorizontal();
                    }
                }
            }
        }

        loop_state_list.OnInspectorGUI();

        EditorGUILayout.EndVertical();    // whole

        if (GUI.changed)
        {
            EditorUtility.SetDirty((MonoBehaviour)character_animation);
        }
    }
    public override void OnInspectorGUI()
    {
        //base.OnInspectorGUI();

        CharacterCutScene character_animation = (CharacterCutScene)target;

        EditorGUILayout.BeginHorizontal();  // whole

        if (!EditorUtility.IsPersistent(character_animation))
        {
            if (GUILayout.Button("Create Import"))
            {
                character_animation.CreateImport();
                CheckAnimations();
            }
        }

        EditorGUILayout.EndHorizontal();  // whole


        if (character_animation.Animation == null)
        {
            return;
        }

        if (s_Animations == null || character_animation.Animation.GetClipCount() != s_Animations.Length)
        {
            CheckAnimations();
        }

        EditorGUILayout.BeginVertical();  // whole
        EditorGUILayout.Separator();

        //        if (EditorApplication.isPlaying)
        {
            if (s_Util.SeparatorToolbarFold("Debug", null))
            {
                if (character_animation != null && character_animation.CurrentState != null)
                {
                    EditorGUILayout.LabelField(string.Format("{0} : {1}/{2}", character_animation.CurrentState.name, character_animation.PlaybackTime, character_animation.CurrentState.length));
                }
                else
                {
                    EditorGUILayout.LabelField("none");
                }
                EditorUtility.SetDirty((MonoBehaviour)character_animation);
            }
        }

        //        if (EditorApplication.isPlaying == false)
        {
            OnInspectorPlay(character_animation);
        }

        EditorGUILayout.EndVertical();    // whole

        if (GUI.changed)
        {
            EditorUtility.SetDirty((MonoBehaviour)character_animation);
        }
    }