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_RoutimeShowAnimation;
|
|
[SerializeField] Effect[] m_PersistentEffect;
|
[SerializeField] Effect[] m_RoutimeShowEffect;
|
|
[SerializeField] CreateRoleHeroPlatform m_Platform;
|
[SerializeField] ActorShadowCaster m_Shadow;
|
|
CreateRoleTimeLine showTimeLine = new CreateRoleTimeLine();
|
|
public State state { get; private set; }
|
|
List<SFXController> sfxControllers = new List<SFXController>();
|
|
public void DoRoutineShow()
|
{
|
m_Shadow.gameObject.SetActive(false);
|
m_Platform.transform.localEulerAngles = new Vector3(0, 180, 0);
|
m_Platform.ForbidSeconds(m_RoutimeShowAnimation.delay + m_RoutimeShowAnimation.duration);
|
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.gameObject.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);
|
}
|
|
var animator = model.GetComponent<Animator>();
|
animator.Play(m_RoutimeShowAnimation.animation);
|
});
|
|
showTimeLine.AddNone(m_RoutimeShowAnimation.delay+0.1f, () =>
|
{
|
if (m_EnterPictureType == EnterPictureType.OutIn)
|
{
|
m_Shadow.gameObject.SetActive(true);
|
m_Shadow.Cast(model.transform);
|
}
|
});
|
|
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<CreateRoleWin>();
|
});
|
|
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;
|
public float duration;
|
}
|
|
[System.Serializable]
|
public struct Effect
|
{
|
public int id;
|
public float delay;
|
}
|
|
public enum EnterPictureType
|
{
|
Stand,
|
OutIn,
|
}
|
|
public enum State
|
{
|
Idle,
|
EnterShow,
|
RoutimeShow,
|
}
|
|
}
|