void FixAllAnims()
        {
            foreach (NFAnimaStateType myCode in Enum.GetValues(typeof(NFAnimaStateType)))
            {
                bool b = false;
                for (int i = 0; i < mData.AnimationSkillList.Count; i++)
                {
                    if (mData.AnimationSkillList[i].Type == myCode)
                    {
                        b = true;
                        break;
                    }
                }

                if (!b)
                {
                    AnimationSkillStruct _ass = new AnimationSkillStruct();
                    _ass.Type      = myCode;
                    _ass.IsFoldout = true;

                    _ass.EffectStructList   = new List <EffectStruct>();
                    _ass.AudioStructList    = new List <AudioStruct>();
                    _ass.BulletStructList   = new List <BulletStruct>();
                    _ass.DamageStructList   = new List <DamageStruct>();
                    _ass.MovementStructList = new List <MovementStruct>();
                    _ass.CameraStructList   = new List <CameraStruct>();
                    mData.AnimationSkillList.Add(_ass);
                }
            }

            for (int i = mData.AnimationSkillList.Count - 1; i >= 0; i--)
            {
                bool b = false;
                foreach (NFAnimaStateType myCode in Enum.GetValues(typeof(NFAnimaStateType)))
                {
                    if (mData.AnimationSkillList[i].Type == myCode)
                    {
                        b = true;
                        break;
                    }
                }

                if (!b)
                {
                    mData.AnimationSkillList.RemoveAt(i);
                }
            }

            AnimatorController ctrl;

            if (mAnimator.runtimeAnimatorController == null)
            {
                //根据最新信息重建新的controller
                String strPath = AssetDatabase.GetAssetPath(mAnimator.avatar);
                ctrl = AnimatorController.CreateAnimatorControllerAtPath(strPath + ".controller");
                mAnimator.runtimeAnimatorController = ctrl;
                AnimatorController.SetAnimatorController(mAnimator, ctrl);
            }
            else
            {
                ctrl = (AnimatorController)mAnimator.runtimeAnimatorController;
            }

            AnimatorStateMachine state_machine = ctrl.layers[0].stateMachine;

            for (int i = 0; i < mData.AnimationSkillList.Count; i++)
            {
                AnimationSkillStruct _ass = mData.AnimationSkillList[i];
                String        strClipPath = AssetDatabase.GetAssetPath(_ass.AnimationClip);
                AnimationClip anim        = AssetDatabase.LoadAssetAtPath(strClipPath, typeof(AnimationClip)) as AnimationClip;

                //Debug.Log(_ass.AnimationClip.name + " " + strClipPath);
                var objs = AssetDatabase.LoadAllAssetsAtPath(strClipPath);
                foreach (var o in objs)
                {
                    if (o is AnimationClip && _ass.AnimationClip.name == o.name)
                    {
                        Debug.Log(o.name + " is clip " + _ass.AnimationClip.name);
                        anim = o as AnimationClip;
                    }
                }

                if (anim == null)
                {
                    //didn't set a animation we will set idle as the default animation
                    //we don't need to do this as if we do like this there will run out a bug (cann't swap the same animation)

                    /*
                     * for (int index = 0; index < mData.AnimationSkillList.Count; index++)
                     * {
                     *  AnimationSkillStruct tempAss = mData.AnimationSkillList[index];
                     *  if (tempAss.Type == NFAnimaStateType.Idle)
                     *  {
                     *      _ass.AnimationClip = tempAss.AnimationClip;
                     *      break;
                     *  }
                     * }
                     */
                }

                bool bFind = false;
                for (int j = 0; j < state_machine.states.Length; j++)
                {
                    ChildAnimatorState childAnimatorState = state_machine.states[j];
                    if (childAnimatorState.state.name == _ass.Type.ToString())
                    {
                        bFind = true;
                        childAnimatorState.state.motion = anim;
                        childAnimatorState.state.speed  = _ass.fSpeed;
                        break;
                    }
                }

                if (!bFind)
                {
                    AnimatorState state = state_machine.AddState(_ass.Type.ToString());
                    state.motion = anim;
                    state.speed  = _ass.fSpeed;
                }
            }

            /*
             *          AnimatorState[] intArray2 = new AnimatorState[100];
             *
             *          foreach (NFAnimaStateType myCode in Enum.GetValues(typeof(NFAnimaStateType)))
             *          {
             *                  AnimatorState state = state_machine.AddState(myCode.ToString());
             *
             *  intArray2[(int)myCode] = state;
             *          }
             *
             *
             * AnimatorState runState = intArray2[(int)NFAnimaStateType.Run];
             * AnimatorState IdleState = intArray2[(int)NFAnimaStateType.Idle];
             *
             * runState.AddTransition(IdleState);
             * IdleState.AddTransition(runState);
             */

            string prefabPath = "/Prefabs/Object/" + mASC.gameObject.name;

            PrefabUtility.ApplyObjectOverride(mASC.gameObject, prefabPath, InteractionMode.AutomatedAction);
        }
        void DrawAnimation()
        {
            if (mData.AnimationSkillList == null)
            {
                return;
            }

            for (int i = 0; i < mData.AnimationSkillList.Count; i++)
            {
                EditorGUILayout.Space();

                AnimationSkillStruct _ass = mData.AnimationSkillList[i];
                if (_ass.Type == NFAnimaStateType.NONE)
                {
                    continue;
                }

                if (_ass.IsFoldout)
                {
                    EditorGUILayout.BeginVertical(EditorStyles.helpBox);

                    _ass.fCurTime = EditorGUILayout.Slider(_ass.Type.ToString(), _ass.fCurTime, 0f, _ass.fTime);
                    if (_ass.fCurTime > 0)
                    {
                        for (int j = 0; j < mData.AnimationSkillList.Count; j++)
                        {
                            if (i != j)
                            {
                                mData.AnimationSkillList[j].fCurTime = 0f;
                            }
                        }

                        m_CurrentTime  = _ass.fCurTime / _ass.fTime;
                        mManulPlayType = _ass.Type;
                    }

                    _ass.fSpeed = EditorGUILayout.FloatField("Play Speed:", _ass.fSpeed);

                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button("Play"))
                    {
                        //mASC.SetAnimator(mASC.GetComponent<Animator>());
                        _ass.fCurTime  = 0f;
                        m_CurrentTime  = 0f;
                        mManulPlayType = NFAnimaStateType.NONE;
                        mPlayType      = _ass.Type;
                        mASC.PlayAnimaState(mPlayType, -1);
                    }

                    if (GUILayout.Button("Stop"))
                    {
                        _ass.fCurTime  = 0f;
                        m_CurrentTime  = 0f;
                        mManulPlayType = NFAnimaStateType.NONE;
                        mPlayType      = NFAnimaStateType.Idle;
                        mASC.PlayAnimaState(NFAnimaStateType.Idle, -1);

                        for (int j = 0; j < mData.AnimationSkillList.Count; j++)
                        {
                            mData.AnimationSkillList[j].fCurTime = 0f;
                        }
                    }

                    EditorGUILayout.EndHorizontal();

                    _ass.AnimationClip = (AnimationClip)EditorGUILayout.ObjectField("AnimaitonClip:", _ass.AnimationClip, typeof(AnimationClip), true);

                    EditorGUILayout.BeginHorizontal();
                    if (_ass.AnimationClip == null)
                    {
                        _ass.fTime = 1f;
                    }
                    else
                    {
                        _ass.fTime = _ass.AnimationClip.length / _ass.fSpeed;
                    }
                    EditorGUILayout.LabelField("NextAnima After:", _ass.fTime.ToString());
                    _ass.NextType = (NFAnimaStateType)EditorGUILayout.EnumPopup(_ass.NextType);

                    EditorGUILayout.EndHorizontal();



                    mData.AnimationSkillList[i] = _ass;

                    //添加特效与删除片断
                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button("ADD EFFECT"))
                    {
                        EffectStruct _es = new EffectStruct();
                        _es.LifeTime  = 3;
                        _es.isFoldout = true;
                        mData.AnimationSkillList[i].EffectStructList.Add(_es);
                    }
                    if (GUILayout.Button("ADD Audio"))
                    {
                        AudioStruct _es = new AudioStruct();
                        _es.LifeTime  = 3;
                        _es.isFoldout = true;
                        mData.AnimationSkillList[i].AudioStructList.Add(_es);
                    }
                    if (GUILayout.Button("ADD Bullet"))
                    {
                        BulletStruct _es = new BulletStruct();
                        _es.isFoldout = true;
                        mData.AnimationSkillList[i].BulletStructList.Add(_es);
                    }



                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button("ADD Damage"))
                    {
                        DamageStruct _es = new DamageStruct();
                        _es.isFoldout = true;
                        mData.AnimationSkillList[i].DamageStructList.Add(_es);
                    }

                    if (GUILayout.Button("ADD Movement"))
                    {
                        MovementStruct _es = new MovementStruct();
                        _es.isFoldout = true;
                        mData.AnimationSkillList[i].MovementStructList.Add(_es);
                    }

                    if (GUILayout.Button("ADD Camera"))
                    {
                        CameraStruct _es = new CameraStruct();
                        _es.isFoldout = true;
                        mData.AnimationSkillList[i].CameraStructList.Add(_es);
                    }

                    EditorGUILayout.EndHorizontal();

                    if (mData.AnimationSkillList.Count > 0)
                    {
                        DrawEffect(i);
                        DrawAudio(i);
                        DrawMovement(i);
                        DrawDamage(i);
                        DrawBullet(i);
                        DrawCamera(i);
                    }
                    EditorGUILayout.EndVertical();
                }
            }
        }
Example #3
0
        public int PlayAnimaState(NFAnimaStateType eAnimaType, int index, bool force = false)
        {
            foreach (GameObject go in effectList)
            {
                if (go != null)
                {
                    Destroy(go);
                }
            }

            effectList.Clear();

            if (eAnimaType == NFAnimaStateType.Idle)
            {
                float f = Random.Range(0, 100);
                if (f < 15.0f)
                {
                    for (int i = 0; i < mxSkillData.AnimationSkillList.Count; ++i)
                    {
                        AnimationSkillStruct xAnimationSkillStruct = mxSkillData.AnimationSkillList[i];
                        if (xAnimationSkillStruct.Type == NFAnimaStateType.Idle1)
                        {
                            if (xAnimationSkillStruct.AnimationClip != null)
                            {
                                eAnimaType = NFAnimaStateType.Idle1;
                                break;
                            }
                        }
                    }
                }
                else if (f < 30.0f)
                {
                    for (int i = 0; i < mxSkillData.AnimationSkillList.Count; ++i)
                    {
                        AnimationSkillStruct xAnimationSkillStruct = mxSkillData.AnimationSkillList[i];
                        if (xAnimationSkillStruct.Type == NFAnimaStateType.Idle1)
                        {
                            if (xAnimationSkillStruct.AnimationClip != null)
                            {
                                eAnimaType = NFAnimaStateType.Idle2;
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                if (eAnimaType == meLastPlayID && !force)
                {
                    return(-1);
                }
            }

            if (mBodyIdent == null)
            {
                mBodyIdent = GetComponent <NFBodyIdent>();
                if (mBodyIdent.xRenderObject)
                {
                    mAnimator = mBodyIdent.xRenderObject.GetComponent <Animator>();
                }
            }

            mxAnimationEvent.OnEndAnimaEvent(this.gameObject, meLastPlayID, index);

            meLastPlayID = eAnimaType;

            mxAnimationEvent.OnStartAnimaEvent(this.gameObject, eAnimaType, index);

            for (int i = 0; i < mxSkillData.AnimationSkillList.Count; ++i)
            {
                AnimationSkillStruct xAnimationSkillStruct = mxSkillData.AnimationSkillList[i];
                if (xAnimationSkillStruct.Type == eAnimaType)
                {
                    if (mBodyIdent.xRenderObject)
                    {
                        mBodyIdent.xRenderObject.gameObject.SetActive(xAnimationSkillStruct.visible);
                    }

                    if (xAnimationSkillStruct.AnimationClip != null)
                    {
                        //mAnimator.Play(eAnimaType.ToString());
                        if (mAnimator)
                        {
                            mAnimator.CrossFade(eAnimaType.ToString(), 0.1f);
                        }
                    }
                    else
                    {
                        //continue;
                        //Debug.LogWarning(eAnimaType.ToString() + " The AnimationClip is null!");
                        //UnityEditor.EditorUtility.DisplayDialog ("Warning", "The AnimationClip is null!", "OK", "Cancel");
                    }

                    foreach (EffectStruct es in xAnimationSkillStruct.EffectStructList)
                    {
                        if (es.Effect != null)
                        {
                            es.Index = index;
                            StartCoroutine(WaitPlayEffect(es));
                        }
                    }
                    foreach (AudioStruct es in xAnimationSkillStruct.AudioStructList)
                    {
                        if (es.Audio != null)
                        {
                            es.Index = index;
                            StartCoroutine(WaitPlayAudio(es));
                        }
                    }

                    foreach (BulletStruct es in xAnimationSkillStruct.BulletStructList)
                    {
                        if (es.Bullet != null)
                        {
                            es.Index = index;
                            StartCoroutine(WaitPlayBullet(es));
                        }
                    }

                    foreach (MovementStruct es in xAnimationSkillStruct.MovementStructList)
                    {
                        es.Index = index;
                        StartCoroutine(WaitPlayMovement(es));
                    }

                    if (xAnimationSkillStruct.ActiveStructList.Count > 0)
                    {
                        foreach (ActiveStruct es in xAnimationSkillStruct.ActiveStructList)
                        {
                            es.Index = index;
                            StartCoroutine(WaitPlayActive(es));
                        }
                    }

                    if (xAnimationSkillStruct.DamageStructList.Count > 0)
                    {
                        foreach (DamageStruct es in xAnimationSkillStruct.DamageStructList)
                        {
                            es.Index = index;
                            StartCoroutine(WaitPlayDamage(es));
                        }
                    }
                    else
                    {
                        // no bullet
                        if (xAnimationSkillStruct.BulletStructList.Count <= 0)
                        {
                            for (int j = 0; j < EnemyList.Count; ++j)
                            {
                                if (EnemyList[j] != null)
                                {
                                    mxAnimationEvent.NoDamageEvent(this.gameObject, EnemyList[j], eAnimaType, index);
                                }
                            }
                        }
                    }

                    foreach (CameraStruct es in xAnimationSkillStruct.CameraStructList)
                    {
                        es.Index = index;
                        StartCoroutine(WaitPlayCamera(es));
                    }

                    if (xAnimationSkillStruct.Type != NFAnimaStateType.Idle)
                    {
                        if (xAnimationSkillStruct.AnimationClip)
                        {
                            if (!xAnimationSkillStruct.AnimationClip.isLooping)
                            {
                                StartCoroutine(WaitPlayNextAnim(xAnimationSkillStruct.fTime, xAnimationSkillStruct.NextType, -1));
                            }
                        }
                        else if (xAnimationSkillStruct.Type != xAnimationSkillStruct.NextType)
                        {
                            StartCoroutine(WaitPlayNextAnim(xAnimationSkillStruct.fTime, xAnimationSkillStruct.NextType, -1));
                        }
                    }

                    //get time
                    if (eAnimaType != NFAnimaStateType.Idle)
                    {
                    }

                    break;
                }
            }

            return(index);
        }