using System.Collections; using System.Collections.Generic; using UnityEngine; using Snxxz.UI; public class CreateRoleBehaviour : MonoBehaviour { [SerializeField] int m_Job; [SerializeField] float m_Scale = 1; [SerializeField] EnterPictureType m_EnterPictureType; [SerializeField] ShowAnimation m_EnterShowAnimation; [SerializeField] ShowAnimation m_RoutimeShowAnimation; [SerializeField] Effect[] m_PersistentEffect; [SerializeField] Effect[] m_EnterShowEffect; [SerializeField] Effect[] m_RoutimeShowEffect; [SerializeField] CreateRoleHeroPlatform m_Platform; [SerializeField] ActorShadowCaster m_Shadow; CreateRoleTimeLine showTimeLine = new CreateRoleTimeLine(); public State state { get; private set; } List sfxControllers = new List(); public void DoEnterShow() { CreateRoleManager.Instance.LoadModel(m_Job, (bool ok, UnityEngine.Object @object) => { if (ok) { var model = @object as GameObject; model.transform.SetParentEx(m_Platform.transform, Vector3.zero, Quaternion.identity, Vector3.one * m_Scale); m_Shadow.Cast(model.transform); model.SetActive(true); ReleaseEffects(); state = State.EnterShow; showTimeLine.ClearNode(); foreach (var effect in m_PersistentEffect) { showTimeLine.AddNone(effect.delay, () => { PlayEffect(model.transform, effect); }); } foreach (var effect in m_EnterShowEffect) { showTimeLine.AddNone(effect.delay, () => { PlayEffect(model.transform, effect); }); } showTimeLine.AddNone(m_EnterShowAnimation.delay, () => { var animator = model.GetComponent(); animator.Play(m_EnterShowAnimation.animation); }); showTimeLine.AddNone(5f, () => { WindowCenter.Instance.Open(); }); showTimeLine.OnComplete(() => { state = State.Idle; }); showTimeLine.Begin(); } }); } public void DoRoutineShow() { CreateRoleManager.Instance.LoadModel(m_Job, (bool ok, UnityEngine.Object @object) => { if (ok) { var model = @object as GameObject; model.transform.SetParentEx(m_Platform.transform, Vector3.zero, Quaternion.identity, Vector3.one * m_Scale); switch (m_EnterPictureType) { case EnterPictureType.OutIn: model.SetActive(false); break; case EnterPictureType.Stand: model.SetActive(true); m_Shadow.Cast(model.transform); break; } ReleaseEffects(); state = State.RoutimeShow; showTimeLine.ClearNode(); showTimeLine.AddNone(m_RoutimeShowAnimation.delay, () => { if (m_EnterPictureType == EnterPictureType.OutIn) { model.SetActive(true); m_Shadow.Cast(model.transform); } var animator = model.GetComponent(); animator.Play(m_RoutimeShowAnimation.animation); }); foreach (var effect in m_PersistentEffect) { showTimeLine.AddNone(effect.delay, () => { PlayEffect(model.transform, effect); }); } foreach (var effect in m_RoutimeShowEffect) { showTimeLine.AddNone(effect.delay, () => { PlayEffect(model.transform, effect); }); } showTimeLine.AddNone(2f, () => { WindowCenter.Instance.Open(); }); showTimeLine.OnComplete(() => { state = State.Idle; }); showTimeLine.Begin(); } }); } public void Dispose() { showTimeLine.Dispose(); ReleaseEffects(); } private void PlayEffect(Transform model, Effect effect) { var config = EffectConfig.Get(effect.id); Transform parent = null; if (!string.IsNullOrEmpty(config.nodeName)) { parent = model.transform.GetChildTransformDeeply(config.nodeName); } else { parent = model.transform; } sfxControllers.Add(SFXPlayUtility.Instance.Play(effect.id, parent)); } public void ReleaseEffects() { for (var i = sfxControllers.Count - 1; i >= 0; i--) { SFXPlayUtility.Instance.Release(sfxControllers[i]); } sfxControllers.Clear(); } [System.Serializable] public struct ShowAnimation { public string animation; public float delay; } [System.Serializable] public struct Effect { public int id; public float delay; } public enum EnterPictureType { Stand, OutIn, } public enum State { Idle, EnterShow, RoutimeShow, } }