Unity 获取Animation,Animator,SkeletonAnimation的状态
Animation#region//控制Animation的播放 private void onAnimationGui()//(GameObject obj) { Animation animation = gameObject.transform.GetComponentInChildren<Animation>(); // Animator animator = obj.transform.GetComponentInChildren<Animator>(); int count = 0; if(animation.gameObject.transform.parent.gameObject.activeSelf) { foreach(AnimationState _state in animation) { if (GUI.Button(new Rect(Vector2.up * 60*(count+1), new Vector2(150, 50)), "Play"+_state.name)) { if(null != _state) { animation.enabled = true; animation.Play(_state.name); Debug.Log("当前播放的是"+animation.name+"--------------"+_state.name+"----动画"); } } count += 1; Debug.Log("clips.lenght=======333333333333333333333333333333333333333333=====animation"+animation); } if (GUI.Button(new Rect(Vector2.up * 60*(count+1), new Vector2(150, 50)), "重置Reset")) { gameObject.transform.localPosition = originPos; Debug.Log("重置回初始状态"); } Debug.Log("clips.lenght=======44444444444444444444444444444444444444444444444444====="); setScaleController(count +2,animation.gameObject); Debug.Log("clips.lenght=======44444444444444444444444444444444444444444444444444====="); } } #endregionAnimator
#region//控制Animator的播放 private void onAnimatorGui()//(GameObject obj) { Animator animator = gameObject.transform.GetComponentInChildren<Animator>(); // Animator animator = obj.transform.GetComponentInChildren<Animator>(); if(animator.gameObject.transform.parent.gameObject.activeSelf) { AnimationClip[] clips = animator.runtimeAnimatorController.animationClips; for(int i = 0;i<clips.Length;i++) { //根据动画名字 添加对应的动画按钮 if (GUI.Button(new Rect(Vector2.up * 60*(i+1), new Vector2(150, 50)), "Play"+clips.name)) { // GUI.GUIStyle.fontSize = 60; if(null != animator) { animator.enabled = true; animator.Play(clips.name); } } } if (GUI.Button(new Rect(Vector2.up * 60*(clips.Length+1), new Vector2(150, 50)), "重置Reset")) { gameObject.transform.localPosition = originPos; Debug.Log("重置回初始状态"); } setScaleController(clips.Length,animator.gameObject); Debug.Log("clips.lenght=======44444444444444444444444444444444444444444444444444====="); } } #endregionSkeletonAnimation
#region 控制spine的播放 private void onSpineGui() { SkeletonAnimation spineAni = gameObject.transform.GetComponentInChildren<SkeletonAnimation>(); int count = 0; if(spineAni.gameObject.transform.parent.gameObject.activeSelf) { var aa = spineAni.skeleton.data.Animations.ToArray(); for(int i = 0;i<aa.Length;i++) { if (GUI.Button(new Rect(Vector2.up * 60*(count+1), new Vector2(150, 50)), "Play"+aa.name)) { if(null != spineAni) { spineAni.GetComponent<SkeletonAnimation>().enabled = true; spineAni.state.SetAnimation(0, aa.name, true); Debug.Log("当前播放的是"+spineAni.GetComponent<SkeletonAnimation>().name+"--------------"+aa.name+"----动画"); } } count += 1; } if (GUI.Button(new Rect(Vector2.up * 60*(count+1), new Vector2(150, 50)), "重置Reset")) { gameObject.transform.localPosition = originPos; Debug.Log("重置回初始状态"); } setScaleController(count +2,spineAni.gameObject); } } #endregion
页:
[1]