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; } } 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; } } if (!b) { mData.AnimationSkillList.RemoveAt(i); } } String strPath = AssetDatabase.GetAssetPath(mASD.GetComponent <Animator> ().avatar); AnimatorController ctrl = AnimatorController.CreateAnimatorControllerAtPath(strPath + ".controller"); AnimatorStateMachine state_machine = ctrl.layers[0].stateMachine; mASD.GetComponent <Animator> ().runtimeAnimatorController = ctrl; foreach (NFAnimaStateType myCode in Enum.GetValues(typeof(NFAnimaStateType))) { AnimatorState state = state_machine.AddState(myCode.ToString()); } }
public int PlayAnimaState(NFAnimaStateType eAnimaType, Vector3 v) { if (meLastPlayID == eAnimaType) { return(-1); } mxAnimationEvent.OnEndAnimaEvent(this.gameObject, meLastPlayID, mnSkillIndex); mnSkillIndex++; mxAnimationEvent.OnStartAnimaEvent(this.gameObject, eAnimaType, mnSkillIndex); for (int i = 0; i < mxSkillData.AnimationSkillList.Count; ++i) { AnimationSkillStruct xAnimationSkillStruct = mxSkillData.AnimationSkillList [i]; if (xAnimationSkillStruct.Type == eAnimaType) { if (xAnimationSkillStruct.AnimationClip != null) { mAnimator.Play(eAnimaType.ToString(), 0); } else { UnityEditor.EditorUtility.DisplayDialog("Warning", "The AnimationClip is null!", "OK", "Cancel"); } foreach (EffectStruct es in xAnimationSkillStruct.EffectStructList) { if (es.Effect != null) { es.index = mnSkillIndex; StartCoroutine(WaitPlayEffect(es)); } } foreach (AudioStruct es in xAnimationSkillStruct.AudioStructList) { if (es.Audio != null) { es.index = mnSkillIndex; StartCoroutine(WaitPlayAudio(es)); } } foreach (BulletStruct es in xAnimationSkillStruct.BulletStructList) { if (es.Bullet != null) { es.index = mnSkillIndex; StartCoroutine(WaitPlayBullet(es, v)); } } foreach (MovementStruct es in xAnimationSkillStruct.MovementStructList) { es.index = mnSkillIndex; StartCoroutine(WaitPlayMovement(es)); } if (xAnimationSkillStruct.BulletStructList.Count <= 0) { foreach (DamageStruct es in xAnimationSkillStruct.DamageStructList) { es.index = mnSkillIndex; StartCoroutine(WaitPlayDamage(es)); } } foreach (CameraStruct es in xAnimationSkillStruct.CameraStructList) { es.index = mnSkillIndex; StartCoroutine(WaitPlayCamera(es)); } meLastPlayID = eAnimaType; //get time if (eAnimaType != NFAnimaStateType.Idle) { StartCoroutine(WaitPlayNextAnim(xAnimationSkillStruct.fTime, xAnimationSkillStruct.NextType)); } } } return(mnSkillIndex); }
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.IsFoldout) { EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUILayout.LabelField(_ass.Type.ToString()); if (GUILayout.Button("Preview")) { mASD.PlayAnimaState(_ass.Type); } _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; } EditorGUILayout.LabelField("NextAnima After:", _ass.fTime.ToString()); _ass.NextType = (NFAnimaStateType)EditorGUILayout.EnumPopup(_ass.NextType); EditorGUILayout.EndHorizontal(); AnimatorController ctl = (AnimatorController)mASD.GetComponent <Animator> ().runtimeAnimatorController; if (ctl != null) { AnimatorStateMachine state_machine = ctl.layers[0].stateMachine; for (int j = 0; j < state_machine.states.Length; ++j) { if (state_machine.states [j].state.name == _ass.Type.ToString()) { String strPath = AssetDatabase.GetAssetPath(_ass.AnimationClip); AnimationClip anim = AssetDatabase.LoadAssetAtPath(strPath, typeof(AnimationClip)) as AnimationClip; state_machine.states [j].state.motion = anim; break; } } } 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(); } } }