private void Play(string clipName, AnimationOrTween.Direction playDirection) { if (this.mAnim != null) { base.enabled = true; this.mAnim.enabled = false; if (playDirection == AnimationOrTween.Direction.Toggle) { playDirection = (this.mLastDirection == AnimationOrTween.Direction.Forward) ? AnimationOrTween.Direction.Reverse : AnimationOrTween.Direction.Forward; } if (string.IsNullOrEmpty(clipName)) { if (!this.mAnim.isPlaying) { this.mAnim.Play(); } } else if (!this.mAnim.IsPlaying(clipName)) { this.mAnim.Play(clipName); } IEnumerator enumerator = this.mAnim.GetEnumerator(); try { while (enumerator.MoveNext()) { AnimationState current = (AnimationState) enumerator.Current; if (string.IsNullOrEmpty(clipName) || (current.name == clipName)) { float num = Mathf.Abs(current.speed); current.speed = num * ((float) playDirection); if ((playDirection == AnimationOrTween.Direction.Reverse) && (current.time == 0f)) { current.time = current.length; } else if ((playDirection == AnimationOrTween.Direction.Forward) && (current.time == current.length)) { current.time = 0f; } } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable == null) { } disposable.Dispose(); } this.mLastDirection = playDirection; this.mNotify = true; this.mAnim.Sample(); } }
/// <summary> /// 播放动画片段 /// </summary> /// <param name="anim"></param> /// <param name="name"></param> /// <param name="dir"></param> /// <returns></returns> public static AnimationState PlayAnimation(Animation anim, string name, AnimationOrTween.Direction dir) { var state = anim[name]; if (state) { float speed = Mathf.Abs(state.speed); state.speed = speed * (int)dir; if (dir == AnimationOrTween.Direction.Reverse && state.time == 0f) state.time = state.length; else if (dir == AnimationOrTween.Direction.Forward && state.time == state.length) state.time = 0f; //Debug.Log(string.Format(" speed {0},dir ={1},time = {2},length={3}",state.speed,dir,state.time,state.length)); anim.Play(name); anim.Sample(); } return state; }
public static ActiveAnimation Play(Animation anim, string clipName, AnimationOrTween.Direction playDirection, EnableCondition enableBeforePlay, DisableCondition disableCondition) { if (!NGUITools.GetActive(anim.gameObject)) { if (enableBeforePlay != EnableCondition.EnableThenPlay) { return null; } NGUITools.SetActive(anim.gameObject, true); UIPanel[] componentsInChildren = anim.gameObject.GetComponentsInChildren<UIPanel>(); int index = 0; int length = componentsInChildren.Length; while (index < length) { componentsInChildren[index].Refresh(); index++; } } ActiveAnimation component = anim.GetComponent<ActiveAnimation>(); if (component == null) { component = anim.gameObject.AddComponent<ActiveAnimation>(); } component.mAnim = anim; component.mDisableDirection = (AnimationOrTween.Direction) disableCondition; component.onFinished.Clear(); component.Play(clipName, playDirection); return component; }
public static ActiveAnimation Play(Animation anim, string clipName, AnimationOrTween.Direction playDirection) { return Play(anim, clipName, playDirection, EnableCondition.DoNothing, DisableCondition.DoNotDisable); }