/// <summary> /// 指定动画播放 /// </summary> /// <param name="part"></param> /// <param name="target_state"></param> /// <returns></returns> bool PlayAnimationImpl(string part, uint target_state) { string animation_name = DBMainmapAnimation.Instance.GetAnimationName(part, target_state); if (string.IsNullOrEmpty(animation_name)) { GameDebug.LogError("[PlayAnimationEx]mainmap animation is invalid,part:" + part); return(false); } AnimationEventBridge animationi_event = null; if (!mDelayBehaviours.TryGetValue(part, out animationi_event)) { GameDebug.LogError("[PlayAnimationEx]mainmap animation has not animationi_event,part:" + part); return(false); } byte wait_state = 100; mWidgetStates.TryGetValue(part, out wait_state); if (wait_state != 100) // 其他动画正在播放 { // 播放动画并设置延时处理 var animation = mAnimations[part]; string wait_animation_name = DBMainmapAnimation.Instance.GetAnimationName(part, wait_state); animation[wait_animation_name].speed = 10.0f; // 进行加速处理 return(false); } animationi_event.gameObject.SetActive(true); mWidgetStates[part] = (byte)target_state; // 播放动画并设置延时处理 var anim = mAnimations[part]; var animation_state = anim[animation_name]; if (animation_state == null || animation_state.clip == null) { Debug.LogError(string.Format("part: {0}, target_state: {1} , animation: {2} is invalid.", part, target_state, animation_name)); OnPlayAnimationEnd(string.Format("{0}~{1}", part, target_state)); return(false); } var animation_clip = animation_state.clip; if (animation_clip.events != null) { for (int j = 0; j < animation_clip.events.Length; ++j) { animation_clip.events[j] = null; } animation_clip.events = null; } AnimationEvent ent = new AnimationEvent(); ent.time = animation_state.length; ent.functionName = "PlayAnimationEnd"; ent.stringParameter = string.Format("{0}~{1}", part, target_state); animation_clip.AddEvent(ent); animationi_event.onPlayAnimationEnd = OnPlayAnimationEnd; animation_state.speed = 1.0f; anim.Play(animation_name); return(true); }
/// <summary> /// 执行动画播放的协程,需要等待上一次的动画播放完毕 /// </summary> /// <param name="part"></param> /// <param name="target_state"></param> /// <returns></returns> IEnumerator PlayAnimationEx(string part, uint target_state, byte wait_index) { string animation_name = DBMainmapAnimation.Instance.GetAnimationName(part, target_state); if (string.IsNullOrEmpty(animation_name)) { GameDebug.LogError("[PlayAnimationEx]mainmap animation is invalid,part:" + part); yield break; } AnimationEventBridge animation_event = null; if (!mDelayBehaviours.TryGetValue(part, out animation_event)) { GameDebug.LogError("[PlayAnimationEx]mainmap animation has not animationi_event,part:" + part); yield break; } // 等待其他动画播放完毕 byte wait_state = 100; while (true) { mWidgetStates.TryGetValue(part, out wait_state); if (wait_state != 100) // 没有其他的动画在播放或者播放完成 { yield return(null); } else { break; } } // 必须按顺序等待 while (true) { LinkedList <byte> wait_list = mWidgetWaitList[part]; if (wait_list.Count != 0 && wait_list.First.Value != wait_index) { yield return(null); // 等待上一次的动画播放完毕 byte wait_next_state = 100; while (true) { mWidgetStates.TryGetValue(part, out wait_next_state); if (wait_next_state != 100) // 没有其他的动画在播放或者播放完成 { yield return(null); } else { break; } } } else { if (wait_list.Count != 0) { wait_list.RemoveFirst(); } break; } } animation_event.gameObject.SetActive(true); mWidgetStates[part] = (byte)target_state; // 播放过程中,状态设置为200 // 播放动画并设置延时处理 var anim = mAnimations[part]; var animation_state = anim[animation_name]; if (animation_state == null || animation_state.clip == null) { Debug.LogError(string.Format("part: {0}, target_state: {1} , animation: {2} is invalid.", part, target_state, animation_name)); OnPlayAnimationEnd(string.Format("{0}~{1}", part, target_state)); yield break; } var animation_clip = animation_state.clip; if (animation_clip.events != null) { for (int j = 0; j < animation_clip.events.Length; ++j) { animation_clip.events[j] = null; } animation_clip.events = null; } AnimationEvent ent = new AnimationEvent(); ent.time = animation_state.length; ent.functionName = "PlayAnimationEnd"; ent.stringParameter = string.Format("{0}~{1}", part, target_state); animation_clip.AddEvent(ent); animation_event.onPlayAnimationEnd = OnPlayAnimationEnd; animation_state.speed = 1.0f; anim.Play(animation_name); }