123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- using System;
- using com.workman.cm3d2.scene.dailyEtc;
- using UnityEngine;
- public abstract class BasePanelMgr : MonoBehaviour
- {
- public abstract void Init();
- public void SetDurationToFadeIn(float duration)
- {
- this.durationToFadeIn_ = duration;
- }
- public void SetDurationToFadeOut(float duration)
- {
- this.durationToFadeOut_ = duration;
- }
- protected virtual void SetFadeTargetPanel()
- {
- }
- protected virtual void OpenPanel()
- {
- }
- protected virtual void OpenPanel(string openType)
- {
- }
- protected virtual void ClosePanel()
- {
- }
- protected virtual void BeforeFadeOut()
- {
- }
- protected virtual void BeforeFadeIn()
- {
- }
- private float durationToFadeIn
- {
- get
- {
- return this.durationToFadeIn_;
- }
- }
- private float durationToFadeOut
- {
- get
- {
- return this.durationToFadeOut_;
- }
- }
- protected virtual void Start()
- {
- GameObject f_goParent = GameObject.Find("/UI Root");
- GameObject childObject = UTY.GetChildObject(f_goParent, "Manager", false);
- if (childObject != null)
- {
- this.sceneMgr = childObject.GetComponent<SceneMgr>();
- }
- this.SetDurationToFadeIn(0.25f);
- this.SetDurationToFadeOut(0.25f);
- this.ChangeFadeState(BasePanelMgr.FadeState.None);
- }
- private void ChangeFadeState(BasePanelMgr.FadeState fadeState)
- {
- this.currentFadeState = fadeState;
- }
- protected T GetManager<T>() where T : BasePanelMgr
- {
- return this.sceneMgr.GetManager<T>();
- }
- public void BaseInit()
- {
- this.Init();
- this.SetFadeTargetPanel();
- }
- public void BaseOpenPanel()
- {
- this.BeforeOpen();
- BasePanelMgr.isOpen = true;
- this.OpenPanel();
- this.FadeInPanel();
- }
- public void BaseOpenPanel(string openType)
- {
- this.BeforeOpen();
- BasePanelMgr.isOpen = true;
- this.OpenPanel(openType);
- this.FadeInPanel();
- }
- public void BaseClosePanel()
- {
- this.BeforeClose();
- BasePanelMgr.isOpen = false;
- this.ClosePanel();
- this.FadeOutPanel();
- }
- public void BaseClosePanel(Action OnFinished)
- {
- this.BeforeClose();
- BasePanelMgr.isOpen = false;
- this.ClosePanel();
- this.FadeOutPanel(OnFinished);
- }
- public void BaseClosePanel<T>(Action<T> OnFinished, T param)
- {
- this.BeforeClose();
- BasePanelMgr.isOpen = false;
- this.ClosePanel();
- this.FadeOutPanel<T>(OnFinished, param);
- }
- protected void FadeInPanel()
- {
- this.fadeTargetPanel.SetActive(true);
- this.BeforeFadeIn();
- this.ChangeFadeState(BasePanelMgr.FadeState.StartFadeIn);
- TweenAlpha tweenAlpha = this.fadeTargetPanel.GetComponent<TweenAlpha>();
- if (tweenAlpha)
- {
- UnityEngine.Object.Destroy(tweenAlpha);
- }
- if (this.durationToFadeIn <= 0f)
- {
- UIRect uirect = this.fadeTargetPanel.GetComponent<UIRect>();
- SpriteRenderer component = this.fadeTargetPanel.GetComponent<SpriteRenderer>();
- Material material = null;
- if (uirect == null && component == null)
- {
- Renderer component2 = this.fadeTargetPanel.GetComponent<Renderer>();
- if (component2 != null)
- {
- material = component2.material;
- }
- if (material == null)
- {
- uirect = this.fadeTargetPanel.GetComponentInChildren<UIRect>();
- }
- }
- float num = 1f;
- if (uirect != null)
- {
- uirect.alpha = num;
- }
- else if (component != null)
- {
- Color color = component.color;
- color.a = num;
- component.color = color;
- }
- else if (material != null)
- {
- Color color2 = material.color;
- color2.a = num;
- material.color = color2;
- }
- this.ChangeFadeState(BasePanelMgr.FadeState.EndFadeIn);
- this.AfterFadeIn();
- return;
- }
- tweenAlpha = this.fadeTargetPanel.AddComponent<TweenAlpha>();
- tweenAlpha.from = 0f;
- tweenAlpha.to = 1f;
- tweenAlpha.duration = this.durationToFadeIn;
- EventDelegate.Set(tweenAlpha.onFinished, delegate()
- {
- this.ChangeFadeState(BasePanelMgr.FadeState.EndFadeIn);
- this.AfterFadeIn();
- });
- tweenAlpha.PlayForward();
- }
- protected void FadeOutPanel()
- {
- this.BeforeFadeOut();
- this.ChangeFadeState(BasePanelMgr.FadeState.StartFadeOut);
- if (this.durationToFadeOut <= 0f)
- {
- UIRect uirect = this.fadeTargetPanel.GetComponent<UIRect>();
- SpriteRenderer component = this.fadeTargetPanel.GetComponent<SpriteRenderer>();
- Material material = null;
- if (uirect == null && component == null)
- {
- Renderer component2 = this.fadeTargetPanel.GetComponent<Renderer>();
- if (component2 != null)
- {
- material = component2.material;
- }
- if (material == null)
- {
- uirect = this.fadeTargetPanel.GetComponentInChildren<UIRect>();
- }
- }
- float num = 0f;
- if (uirect != null)
- {
- uirect.alpha = num;
- }
- else if (component != null)
- {
- Color color = component.color;
- color.a = num;
- component.color = color;
- }
- else if (material != null)
- {
- Color color2 = material.color;
- color2.a = num;
- material.color = color2;
- }
- this.fadeTargetPanel.SetActive(false);
- this.ChangeFadeState(BasePanelMgr.FadeState.EndFadeOut);
- this.AfterFadeOut();
- return;
- }
- TweenAlpha tweenAlpha = TweenAlpha.Begin(this.fadeTargetPanel, this.durationToFadeOut, 0f);
- EventDelegate.Set(tweenAlpha.onFinished, delegate()
- {
- this.fadeTargetPanel.SetActive(false);
- this.ChangeFadeState(BasePanelMgr.FadeState.EndFadeOut);
- this.AfterFadeOut();
- });
- }
- protected void FadeOutPanel(Action OnFinished)
- {
- this.BeforeFadeOut();
- this.ChangeFadeState(BasePanelMgr.FadeState.StartFadeOut);
- TweenAlpha tweenAlpha = TweenAlpha.Begin(this.fadeTargetPanel, this.durationToFadeOut, 0f);
- EventDelegate.Set(tweenAlpha.onFinished, delegate()
- {
- this.fadeTargetPanel.SetActive(false);
- this.ChangeFadeState(BasePanelMgr.FadeState.EndFadeOut);
- this.AfterFadeOut();
- OnFinished();
- });
- }
- protected void FadeOutPanel<T>(Action<T> OnFinished, T param)
- {
- this.BeforeFadeOut();
- this.ChangeFadeState(BasePanelMgr.FadeState.StartFadeOut);
- TweenAlpha tweenAlpha = TweenAlpha.Begin(this.fadeTargetPanel, this.durationToFadeOut, 0f);
- EventDelegate.Set(tweenAlpha.onFinished, delegate()
- {
- this.fadeTargetPanel.SetActive(false);
- this.ChangeFadeState(BasePanelMgr.FadeState.EndFadeOut);
- this.AfterFadeOut();
- OnFinished(param);
- });
- }
- protected virtual void AfterFadeIn()
- {
- this.AfterOpen();
- }
- protected virtual void AfterFadeOut()
- {
- this.AfterClose();
- }
- protected virtual void BeforeOpen()
- {
- }
- protected virtual void AfterOpen()
- {
- }
- protected virtual void BeforeClose()
- {
- }
- protected virtual void AfterClose()
- {
- }
- public static bool IsOpen()
- {
- return BasePanelMgr.isOpen;
- }
- protected GameObject fadeTargetPanel;
- protected SceneMgr sceneMgr;
- protected BasePanelMgr.FadeState currentFadeState;
- private float durationToFadeIn_;
- private float durationToFadeOut_;
- private const string uiRootPath = "/UI Root";
- private const float DURATION_TO_FADE = 0.25f;
- protected static bool isOpen;
- public enum FadeState
- {
- None,
- StartFadeIn,
- EndFadeIn,
- StartFadeOut,
- EndFadeOut
- }
- }
|