void AnimDataEditor(System.Object animCtrlObj, UIAnimData data) { EditorGUILayout.BeginVertical(); { EditorGUILayout.BeginHorizontal(); { E_AnimTarget targetType = (E_AnimTarget)EditorGUILayout.EnumPopup(data.m_targetType); if (data.m_targetType != targetType) { data.m_targetType = targetType; } if (data.m_targetType == E_AnimTarget.GameObject || data.m_targetType == E_AnimTarget.Children || data.m_targetType == E_AnimTarget.AllChildren) { data.m_target = EditorGUILayout.ObjectField(data.m_target, typeof(GameObject), true) as GameObject; } if (GUILayout.Button("Copy")) { SaveTempData <UIAnimData>(data); } if (GUILayout.Button("Paste")) { data.CopyFramesFrom(LoadTempData <UIAnimData>()); } } EditorGUILayout.EndHorizontal(); ListField <UIAnimFrame>("AnimFrame", data, data.m_frames, AnimFrameEditor, ref data.m_extendListView); } EditorGUILayout.EndVertical(); }
public override void Play(System.Action onPlayEnd, float delay) { if (!gameObject.activeInHierarchy) { if (onPlayEnd != null) { onPlayEnd(); } //Debug.Log("[AnimEnd] gameObject inactive"); return; } int maxLengthIndex = -1; if (onPlayEnd != null) { float maxLength = -1f; for (int i = 0; i < m_animDatas.Count; i++) { // if (m_animDatas[i].m_target != null) continue; float curDuration = m_animDatas[i].GetDuration(); if (curDuration > maxLength) { maxLength = curDuration; maxLengthIndex = i; } } if (maxLengthIndex == -1) { if (onPlayEnd != null) { onPlayEnd(); } Debug.Log("[AnimEnd] all targets are inactive"); return; } } for (int i = 0; i < m_animDatas.Count; i++) { UIAnimData animData = m_animDatas[i]; StartCoroutine(PlayAnim(delay, animData, (i == maxLengthIndex) ? onPlayEnd : null)); } m_timeStart = Time.realtimeSinceStartup + delay; }
public void CopyFramesFrom(UIAnimData other) { if (other == null) { return; } for (int i = 0; i < other.m_frames.Count; i++) { if (i < m_frames.Count) { m_frames[i].CopyFrom(other.m_frames[i]); } else { m_frames.Add(other.m_frames[i]); } } }
void FrameFieldEditor(UIAnimData data, UIAnimFrame frame) { if (frame.HasTween(E_TweenType.Position)) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Position"); if (data != null && data.m_target != null && GUILayout.Button("Current")) { frame.m_position = data.m_target.transform.localPosition; } EditorGUILayout.EndHorizontal(); frame.m_position = EditorGUILayout.Vector3Field("", frame.m_position); } if (frame.HasTween(E_TweenType.Rotation)) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Rotation"); if (data != null && data.m_target != null && GUILayout.Button("Current")) { frame.m_rotation = data.m_target.transform.localRotation.eulerAngles; } EditorGUILayout.EndHorizontal(); frame.m_rotation = EditorGUILayout.Vector3Field("", frame.m_rotation); } if (frame.HasTween(E_TweenType.Scale)) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Scale"); if (data != null && data.m_target != null && GUILayout.Button("Current")) { frame.m_scale = data.m_target.transform.localScale; } EditorGUILayout.EndHorizontal(); frame.m_scale = EditorGUILayout.Vector3Field("", frame.m_scale); } if (frame.HasTween(E_TweenType.Color)) { frame.m_color = EditorGUILayout.ColorField("Color", frame.m_color); } if (frame.HasTween(E_TweenType.Alpha)) { frame.m_alpha = EditorGUILayout.FloatField("Alpha", frame.m_alpha); } }
public void Stop() { StopAllCoroutines(); for (int i = 0; i < m_animDatas.Count; i++) { UIAnimData animData = m_animDatas[i]; GameObject[] targets = animData.GetTargets(); if (targets != null) { for (int t = 0; t < targets.Length; t++) { UITweener[] tweeners = targets[t].GetComponents <UITweener>(); foreach (UITweener tweener in tweeners) { tweener.enabled = false; } SpringPosition[] springs = targets[t].GetComponents <SpringPosition>(); foreach (var spring in springs) { spring.enabled = false; } } } for (int j = 0; j < animData.m_frames.Count; j++) { UIAnimFrame curFrame = animData.m_frames[j]; if (curFrame.m_type == E_UIAnimType.SubAnimGroup) { BaseAnimPlayer[] players = curFrame.m_animPlayerGroup.GetComponentsInImmediateChildren <BaseAnimPlayer>(false, Mathf.FloorToInt(curFrame.m_alpha)); for (int k = 0; k < players.Length; k++) { (players[k] as UIAnimController).Stop(); } } } } }
IEnumerator PlayAnim(float delay, UIAnimData animData, System.Action onPlayEnd) { if (delay > 0) { yield return(new WaitForSeconds(delay)); } for (int i = 0; i < animData.m_frames.Count; i++) { UIAnimFrame curFrame = animData.m_frames[i]; switch (curFrame.m_type) { case E_UIAnimType.Empty: { yield return(new WaitForSeconds(animData.m_frames[i].m_duration)); } break; case E_UIAnimType.Set: { GameObject[] targets = animData.GetTargets(); for (int t = 0; t < targets.Length; t++) { if (curFrame.HasTween(E_TweenType.Position)) { SetPosition(targets[t], curFrame.m_position); } if (curFrame.HasTween(E_TweenType.Rotation)) { SetRotation(targets[t], Quaternion.Euler(curFrame.m_rotation)); } if (curFrame.HasTween(E_TweenType.Scale)) { SetScale(targets[t], curFrame.m_scale); } if (curFrame.HasTween(E_TweenType.Color)) { SetColor(targets[t], curFrame.m_color); } if (curFrame.HasTween(E_TweenType.Alpha)) { SetAlpha(targets[t], curFrame.m_alpha); } } } break; case E_UIAnimType.PlaySFX: { //AudioSource audioSrc = AudioManager.ins.PlaySFX(curFrame.m_audioName, Random.Range(curFrame.m_duration, curFrame.m_alpha), curFrame.m_particleParent); //if (audioSrc != null) //{ // float pitch = Random.Range(curFrame.m_scale.x, curFrame.m_scale.y); // audioSrc.pitch = pitch; //} // if (curFrame.m_audioName != null) // SoundMgr.GetSingle().play_se(curFrame.m_audioName); } break; case E_UIAnimType.PlayBGM: //if (string.IsNullOrEmpty(curFrame.m_audioName)) //{ // AudioManager.ins.StopBGM(); //} //else //{ // AudioManager.ins.PlayBGM(curFrame.m_audioName); //} break; case E_UIAnimType.PlayVOX: { //AudioManager.ins.StopAllVOX(); //AudioManager.ins.PlayVOX(curFrame.m_audioName); } break; case E_UIAnimType.AddParticle: { GameObject prefab = Resources.Load(curFrame.m_particlePath) as GameObject; Transform particleTrans = MonoUtil.CreatePrefab(prefab, "particle", curFrame.m_particleParent, curFrame.m_position); if (curFrame.m_particleDestroyAfterPlay) { particleTrans.gameObject.AddComponent <OneShotParticle>(); } } break; case E_UIAnimType.Tween: { bool isTweening = true; bool assignedOnTweenEnd = false; EventDelegate.Callback onTweenEnd = () => { isTweening = false; }; UITweener tw = null; GameObject[] targets = animData.GetTargets(); for (int t = 0; t < targets.Length; t++) { if (curFrame.HasTween(E_TweenType.Position)) { tw = TweenPosition.Begin(targets[t], curFrame.m_duration, curFrame.m_position); tw.method = curFrame.m_method; if (!assignedOnTweenEnd) { assignedOnTweenEnd = true; tw.SetOnFinished(onTweenEnd); } } if (curFrame.HasTween(E_TweenType.Rotation)) { tw = TweenRotation.Begin(targets[t], curFrame.m_duration, Quaternion.Euler(curFrame.m_rotation)); tw.method = curFrame.m_method; if (!assignedOnTweenEnd) { assignedOnTweenEnd = true; tw.SetOnFinished(onTweenEnd); } } if (curFrame.HasTween(E_TweenType.Scale)) { tw = TweenScale.Begin(targets[t], curFrame.m_duration, curFrame.m_scale); tw.method = curFrame.m_method; if (!assignedOnTweenEnd) { assignedOnTweenEnd = true; tw.SetOnFinished(onTweenEnd); } } if (curFrame.HasTween(E_TweenType.Color)) { tw = TweenColor.Begin(targets[t], curFrame.m_duration, curFrame.m_color); tw.method = curFrame.m_method; if (!assignedOnTweenEnd) { assignedOnTweenEnd = true; tw.SetOnFinished(onTweenEnd); } } if (curFrame.HasTween(E_TweenType.Alpha)) { tw = TweenAlpha.Begin(targets[t], curFrame.m_duration, curFrame.m_alpha); tw.method = curFrame.m_method; if (!assignedOnTweenEnd) { assignedOnTweenEnd = true; tw.SetOnFinished(onTweenEnd); } } } while (assignedOnTweenEnd && isTweening) { yield return(null); } } break; case E_UIAnimType.SubAnim: if (curFrame.m_animPlayer != null) { bool isPlaying = true; curFrame.m_animPlayer.Play(() => isPlaying = false, 0f); while (curFrame.m_particleDestroyAfterPlay && isPlaying) { yield return(null); } } break; case E_UIAnimType.SubAnimGroup: { if (curFrame.m_animPlayerGroup != null) { BaseAnimPlayer[] players = curFrame.m_animPlayerGroup.GetComponentsInImmediateChildren <BaseAnimPlayer>(false, Mathf.FloorToInt(curFrame.m_alpha)); if (players != null && players.Length > 0) { if (curFrame.m_duration >= 0f) { float duration = curFrame.m_duration; bool isPlaying = true; float maxLength = 0f; int maxLengthIdx = -1; for (int j = 0; j < players.Length; j++) { if (!players[j].gameObject.activeInHierarchy) { continue; } float curLength = players[j].Length + duration * j; if (curLength > maxLength) { maxLength = curLength; maxLengthIdx = j; } } if (maxLengthIdx == -1) { isPlaying = false; } for (int j = 0; j < players.Length; j++) { if (j == maxLengthIdx) { players[j].Play(() => isPlaying = false, duration * j); } else { players[j].Play(null, duration * j); } } while (curFrame.m_particleDestroyAfterPlay && isPlaying) { yield return(null); } } else { for (int j = 0; j < players.Length; j++) { bool isPlaying = true; players[j].Play(() => isPlaying = false, 0f); while (isPlaying) { yield return(null); } } } } } } break; case E_UIAnimType.EnableBehaviour: if (curFrame.m_behaviour != null) { curFrame.m_behaviour.enabled = curFrame.m_particleDestroyAfterPlay; } else { GameObject[] targets = animData.GetTargets(); for (int t = 0; t < targets.Length; t++) { targets[t].SetActive(curFrame.m_particleDestroyAfterPlay); } } break; case E_UIAnimType.PlayAnimation: if (!string.IsNullOrEmpty(curFrame.m_audioName)) { var animation = animData.m_target.GetComponent <Animation>(); var animator = animData.m_target.GetComponent <Animator>(); if (animation != null) { var clip = animation[curFrame.m_audioName]; clip.speed = 1; if (clip != null && curFrame.m_duration > 0) { clip.speed = clip.length / curFrame.m_duration; } animation.Stop(); animation.Play(curFrame.m_audioName); yield return(new WaitForSeconds(curFrame.m_duration)); } if (animator != null) { animator.Play(curFrame.m_audioName); } } break; case E_UIAnimType.SendEvent: if (!string.IsNullOrEmpty(curFrame.m_audioName)) { EventManager.Instance.SendEvent(curFrame.m_audioName); } break; default: break; } } if (onPlayEnd != null) { onPlayEnd(); } }