using System; using UnityEngine; public class StaffRollCtrl : MonoBehaviour { public void Init(StaffRollMgr staffRollMgr, GameObject goPanel) { this.m_mgr = staffRollMgr; this.m_goPanel = goPanel; this.m_goStaffRollViewer = UTY.GetChildObject(this.m_goPanel, "StaffRollViewer", false); this.m_goLogoViewer = UTY.GetChildObject(this.m_goPanel, "LogoViewer", false); this.m_targetScroll = UTY.GetChildObject(this.m_goPanel, "StaffRollViewer/StaffRollUnitParent", false); this.m_targetScroll.transform.localPosition = new Vector2(this.m_targetScroll.transform.localPosition.x, (float)this.moveFromPosY); this.m_goTexture = UTY.GetChildObject(this.m_goPanel, "StaffRollViewer/Texture", false); this.m_listTexture = Resources.LoadAll("SceneStaffRoll/Texture"); this.m_dispTextureTime = (float)(this.durationToScroll / this.m_listTexture.Length) - (this.fadeInTimeTexure + this.fadeOutTimeTexure); this.m_goLogoViewer = UTY.GetChildObject(this.m_goPanel, "LogoViewer", false); this.m_goLogoViewer.SetActive(false); this.ChangeTextureState(StaffRollCtrl.TxetureState.None); } public void OnDestroy() { this.m_goTexture.GetComponent().mainTexture = null; for (int i = 0; i < this.m_listTexture.Length; i++) { Resources.UnloadAsset(this.m_listTexture[i]); } } private void Update() { switch (this.m_currentTextureState) { case StaffRollCtrl.TxetureState.FadeIn: this.FadeIn(); break; case StaffRollCtrl.TxetureState.FadeOut: this.FadeOut(); break; case StaffRollCtrl.TxetureState.Display: this.Display(); break; case StaffRollCtrl.TxetureState.Next: this.Next(); break; case StaffRollCtrl.TxetureState.End: this.End(); break; } } public void DispStaffRollViewer() { this.PlayAnimation(); } private void PlayAnimation() { this.StartScrollStaffRoll(); this.m_goTexture.GetComponent().mainTexture = this.m_listTexture[1]; this.StartTextureAnimation(); } public void StartScrollStaffRoll() { TweenPosition.Begin(this.m_targetScroll, (float)this.durationToScroll, new Vector2(this.m_targetScroll.transform.localPosition.x, (float)this.moveToPosY)); } private void ChangeTextureState(StaffRollCtrl.TxetureState nextState) { this.m_currentTextureState = nextState; } public void StartTextureAnimation() { this.ChangeTextureState(StaffRollCtrl.TxetureState.FadeIn); } protected void FadeIn() { this.ChangeTextureState(StaffRollCtrl.TxetureState.RunnigFade); this.m_tweenTexture = TweenAlpha.Begin(this.m_goTexture, this.fadeInTimeTexure, 1f); EventDelegate.Set(this.m_tweenTexture.onFinished, delegate() { this.ChangeTextureState(StaffRollCtrl.TxetureState.Display); this.m_updateTime = Time.time + this.m_dispTextureTime; }); } private void Display() { if (this.m_updateTime < Time.time) { this.ChangeTextureState(StaffRollCtrl.TxetureState.FadeOut); } } private void FadeOut() { this.ChangeTextureState(StaffRollCtrl.TxetureState.RunnigFade); TweenAlpha tweenAlpha = TweenAlpha.Begin(this.m_goTexture, this.fadeOutTimeTexure, 0f); EventDelegate.Set(tweenAlpha.onFinished, delegate() { this.ChangeTextureState(StaffRollCtrl.TxetureState.Next); }); } private void Next() { Texture2D nextTexture = this.GetNextTexture(); if (nextTexture == null) { this.ChangeTextureState(StaffRollCtrl.TxetureState.End); } else { UITexture component = this.m_goTexture.GetComponent(); component.mainTexture = nextTexture; this.ChangeTextureState(StaffRollCtrl.TxetureState.FadeIn); } } private Texture2D GetNextTexture() { this.m_textureNumber++; if (this.m_listTexture.Length > this.m_textureNumber) { UITexture component = this.m_goTexture.GetComponent(); return this.m_listTexture[this.m_textureNumber]; } return null; } private void End() { this.ChangeTextureState(StaffRollCtrl.TxetureState.None); this.m_mgr.CloseViewerAndPanel(); } public void SetEnd() { this.StopAnimation(); this.End(); } public void StopAnimation() { iTween.Stop(this.m_targetScroll, "move"); if (this.m_tweenTexture != null) { UnityEngine.Object.Destroy(this.m_tweenTexture); } } public void DispLogoViewer() { this.m_currentTextureState = StaffRollCtrl.TxetureState.None; this.m_goStaffRollViewer.SetActive(false); this.m_goLogoViewer.SetActive(true); } [SerializeField] private int durationToScroll; [SerializeField] private int moveFromPosY; [SerializeField] private int moveToPosY; [SerializeField] private float fadeInTimeTexure; [SerializeField] private float fadeOutTimeTexure; private StaffRollCtrl.TxetureState m_currentTextureState = StaffRollCtrl.TxetureState.None; private StaffRollMgr m_mgr; private Texture2D[] m_listTexture; private GameObject m_goPanel; private GameObject m_goLogoViewer; private GameObject m_goStaffRollViewer; private GameObject m_targetScroll; private GameObject m_goTexture; private TweenAlpha m_tweenTexture; private float m_dispTextureTime; private float m_updateTime; private int m_textureNumber; private const string LOAD_TEXTURE_PATH = "SceneStaffRoll/Texture"; private const int FIRST_TEXTURE = 1; private enum TxetureState { FadeIn, FadeOut, Display, RunnigFade, Next, End, None } }