using System; using UnityEngine; public abstract class WfScreenChildren : MonoBehaviour { public virtual void Awake() { this.root_obj_ = this.RootPanel; this.awake_active_ = this.root_obj_.activeSelf; if (!this.root_obj_.activeSelf) { this.root_obj_.SetActive(true); } this.call_fadein_wait_ = (this.cur_call_fadein_wait_ = 0); } public virtual void Update() { if (this.fade_status_ == WfScreenChildren.FadeStatus.FadeInWait) { this.cur_call_fadein_wait_--; if (0 <= this.cur_call_fadein_wait_) { return; } if (this.IsCallFadeIn()) { this.cur_call_fadein_wait_ = 0; if (this.fade_status_ == WfScreenChildren.FadeStatus.FadeInWait) { this.FadeIn(); } } } else { this.cur_call_fadein_wait_ = 0; } if (this.fade_status_ == WfScreenChildren.FadeStatus.FadeIn) { if (!GameMain.Instance.MainCamera.IsFadeProc()) { this.fade_status_ = WfScreenChildren.FadeStatus.Wait; } } else if (this.fade_status_ == WfScreenChildren.FadeStatus.FadeOut) { if (!GameMain.Instance.MainCamera.IsFadeProc()) { this.fade_status_ = WfScreenChildren.FadeStatus.FadeEnd; this.OnFinish(); } } else if (this.fade_status_ == WfScreenChildren.FadeStatus.FadeEnd) { this.OnFadeEnd(); } } public bool Call() { if (!this.init_finishied) { NDebug.Assert("初期化完了前にCallが呼ばれました", false); return false; } if (this.fade_status_ != WfScreenChildren.FadeStatus.Null) { Debug.LogWarning("Call呼び出し\nフェード状態は" + this.fade_status_.ToString() + "なのでキャンセルされました"); return false; } this.cur_call_fadein_wait_ = 0; if (!this.root_obj_.activeSelf) { this.root_obj_.SetActive(true); } this.OnCall(); if (this.call_fadein_wait_ <= 0 && this.IsCallFadeIn()) { this.FadeIn(); } else { if (0 < this.call_fadein_wait_) { this.cur_call_fadein_wait_ = this.call_fadein_wait_; } if (this.fade_status_ == WfScreenChildren.FadeStatus.Null) { this.fade_status_ = WfScreenChildren.FadeStatus.FadeInWait; } } return true; } public void Reset() { this.fade_status_ = WfScreenChildren.FadeStatus.Null; } protected abstract void OnCall(); protected virtual bool IsCallFadeIn() { return true; } public void SetCallInFadeWaitFrame(int frame) { this.call_fadein_wait_ = frame; } protected virtual void OnFinish() { } protected virtual void OnFadeEnd() { } public virtual bool Finish() { if (this.fade_status_ != WfScreenChildren.FadeStatus.Wait) { Debug.LogWarning("Finish呼び出し\nフェード状態は" + this.fade_status_.ToString() + "なのでキャンセルされました"); return false; } this.FadeOut(); return true; } public void SetFadeTime(float time) { this.fade_time_ = time; } protected void SetFadeStatus(WfScreenChildren.FadeStatus status) { this.fade_status_ = status; } protected virtual void FadeIn() { GameMain.Instance.MainCamera.FadeIn(this.fade_time_, false, null, true, true, default(Color)); if (GameMain.Instance.MainCamera.IsFadeProc()) { this.fade_status_ = WfScreenChildren.FadeStatus.FadeIn; } else { this.fade_status_ = WfScreenChildren.FadeStatus.Wait; } } protected virtual void FadeOut() { GameMain.Instance.MainCamera.FadeOut(this.fade_time_, false, null, true, default(Color)); if (GameMain.Instance.MainCamera.IsFadeProc()) { this.fade_status_ = WfScreenChildren.FadeStatus.FadeOut; } else { this.fade_status_ = WfScreenChildren.FadeStatus.FadeEnd; this.OnFinish(); } } public virtual void LateUpdate() { if (!this.awake_init_) { if (!this.awake_active_) { this.root_obj_.SetActive(false); } this.awake_init_ = true; } } public bool init_finishied { get { return this.awake_init_; } } public GameObject root_obj { get { return this.root_obj_; } } public float fade_time { get { return this.fade_time_; } } public WfScreenManager parent_mgr { get; set; } public WfScreenChildren.FadeStatus fade_status { get { return this.fade_status_; } } [SerializeField] public GameObject RootPanel; private bool awake_active_; private bool awake_init_; private GameObject root_obj_; private float fade_time_ = 0.5f; private WfScreenChildren.FadeStatus fade_status_; private int call_fadein_wait_; private int cur_call_fadein_wait_; public enum FadeStatus { Null, FadeInWait, FadeIn, Wait, FadeOut, FadeEnd } }