| | |
| | | using System; |
| | | using UnityEngine; |
| | | using UnityEngine.Events; |
| | | using UnityEngine.UI; |
| | | |
| | | namespace Snxxz.UI |
| | | { |
| | | |
| | | [DisallowMultipleComponent] |
| | | [RequireComponent(typeof(WindowInfo))] |
| | | public abstract class Window : MonoBehaviour |
| | | { |
| | | |
| | | static readonly Vector3 HIDE_POSITION = new Vector3(0, 5000, 5000); |
| | | |
| | | WindowInfo m_WindowInfo = null; |
| | | public WindowInfo windowInfo { |
| | | get { |
| | | return m_WindowInfo ?? (m_WindowInfo = this.GetComponent<WindowInfo>()); |
| | | } |
| | | } |
| | | |
| | | public WindowState windowState { |
| | | get; private set; |
| | | } |
| | | |
| | | RectTransform rectTransform { get { return this.transform.AddMissingComponent<RectTransform>(); } } |
| | | |
| | | RawImage windowMask; |
| | | ButtonEx emptyCloseButton; |
| | | bool initialized = false; |
| | | float windowTimer = 0f; |
| | | |
| | | int m_FunctionOrder = 0; |
| | | public int functionOrder { |
| | | get { return m_FunctionOrder; } |
| | | set { m_FunctionOrder = value; } |
| | | } |
| | | |
| | | public bool playAnimation { get; set; } |
| | | |
| | | internal Window Open() |
| | | { |
| | | try |
| | | { |
| | | if (!initialized) |
| | | { |
| | | if (windowInfo.clickEmptyToClose && emptyCloseButton == null) |
| | | { |
| | | AddEmptyCloseResponser(); |
| | | } |
| | | |
| | | if (windowInfo.needMask && windowMask == null) |
| | | { |
| | | AddSreenMask(); |
| | | } |
| | | |
| | | BindController(); |
| | | AddListeners(); |
| | | initialized = true; |
| | | } |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | Debug.Log(ex.StackTrace); |
| | | } |
| | | |
| | | try |
| | | { |
| | | windowTimer = 0f; |
| | | OnPreOpen(); |
| | | WindowCenter.Instance.NotifyBeforeOpen(this); |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | Debug.Log(ex.StackTrace); |
| | | } |
| | | finally |
| | | { |
| | | var parent = FindParent(windowInfo.windowType); |
| | | |
| | | if (parent != null) |
| | | { |
| | | rectTransform.MatchWhith(parent); |
| | | if (windowInfo.windowType >= WindowType.Normal) |
| | | { |
| | | rectTransform.SetAsLastSibling(); |
| | | } |
| | | } |
| | | |
| | | windowState = WindowState.Opening; |
| | | windowInfo.raycastTarget = false; |
| | | if (windowInfo.needMask) |
| | | { |
| | | windowMask.rectTransform.MatchWhith(rectTransform.parent as RectTransform); |
| | | windowMask.transform.localScale = Vector3.one * 1.01f; |
| | | windowMask.transform.SetSiblingIndex(rectTransform.GetSiblingIndex()); |
| | | CameraUtility.ScreenShotCut(windowMask, ActiveWindow); |
| | | } |
| | | else |
| | | { |
| | | ActiveWindow(); |
| | | } |
| | | |
| | | } |
| | | |
| | | return this; |
| | | } |
| | | |
| | | internal Window Close() |
| | | { |
| | | try |
| | | { |
| | | OnPreClose(); |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | Debug.Log(ex.StackTrace); |
| | | } |
| | | |
| | | try |
| | | { |
| | | windowTimer = 0f; |
| | | if (playAnimation && windowInfo.tween != null) |
| | | { |
| | | windowInfo.tween.Play(true); |
| | | } |
| | | |
| | | WindowCenter.Instance.NotifyBeforeClose(this); |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | Debug.Log(ex.StackTrace); |
| | | } |
| | | finally |
| | | { |
| | | windowInfo.raycastTarget = false; |
| | | windowState = WindowState.Closing; |
| | | } |
| | | |
| | | return this; |
| | | } |
| | | |
| | | internal Window CloseImmediately() |
| | | { |
| | | try |
| | | { |
| | | OnPreClose(); |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | Debug.Log(ex.Message); |
| | | } |
| | | |
| | | try |
| | | { |
| | | windowInfo.raycastTarget = false; |
| | | WindowCenter.Instance.NotifyBeforeClose(this); |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | Debug.Log(ex.StackTrace); |
| | | } |
| | | finally |
| | | { |
| | | if (windowInfo.needMask) |
| | | { |
| | | CameraUtility.StopShotCut(windowMask); |
| | | windowMask.transform.SetParentEx(this.transform, Vector3.zero, Quaternion.identity, Vector3.one); |
| | | } |
| | | |
| | | if (windowInfo.windowType == WindowType.Base) |
| | | { |
| | | this.enabled = false; |
| | | this.rectTransform.SetParentEx(WindowCenter.Instance.uiRoot.recycleBin, Vector3.zero, Vector3.zero, Vector3.one); |
| | | } |
| | | else |
| | | { |
| | | this.gameObject.SetActive(false); |
| | | } |
| | | |
| | | windowState = WindowState.Closed; |
| | | } |
| | | |
| | | try |
| | | { |
| | | WindowCenter.Instance.NotifyAfterClose(this); |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | Debug.Log(ex.StackTrace); |
| | | } |
| | | |
| | | try |
| | | { |
| | | OnAfterClose(); |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | Debug.Log(ex.StackTrace); |
| | | } |
| | | |
| | | try |
| | | { |
| | | WindowCenter.Instance.JumpNotifyAfterClose(this); |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | Debug.Log(ex.StackTrace); |
| | | } |
| | | |
| | | return this; |
| | | } |
| | | |
| | | internal void SetMask(GameObject _mask) |
| | | { |
| | | if (_mask != null) |
| | | { |
| | | _mask.transform.SetParentEx(this.transform, Vector3.zero, Quaternion.identity, Vector3.one); |
| | | _mask.transform.SetAsFirstSibling(); |
| | | } |
| | | } |
| | | |
| | | public virtual void CloseClick() |
| | | { |
| | | CloseImmediately(); |
| | | } |
| | | |
| | | protected virtual void LateUpdate() |
| | | { |
| | | |
| | | } |
| | | |
| | | protected virtual void OnActived() |
| | | { |
| | | |
| | | } |
| | | |
| | | protected abstract void BindController(); |
| | | protected abstract void AddListeners(); |
| | | protected abstract void OnPreOpen(); |
| | | protected abstract void OnAfterOpen(); |
| | | protected abstract void OnPreClose(); |
| | | protected abstract void OnAfterClose(); |
| | | |
| | | private void Update() |
| | | { |
| | | switch (windowState) |
| | | { |
| | | case WindowState.Opening: |
| | | OnOpening(); |
| | | break; |
| | | case WindowState.Closing: |
| | | OnClosing(); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | private void OnOpening() |
| | | { |
| | | if (playAnimation && windowInfo.tween != null && windowTimer < windowInfo.tween.duration) |
| | | { |
| | | windowTimer += Time.deltaTime; |
| | | if (windowTimer > windowInfo.tween.duration) |
| | | { |
| | | try |
| | | { |
| | | OnAfterOpen(); |
| | | WindowCenter.Instance.NotifyAfterOpen(this); |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | Debug.Log(ex.Message); |
| | | } |
| | | finally |
| | | { |
| | | windowInfo.raycastTarget = true; |
| | | windowState = WindowState.Opened; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | try |
| | | { |
| | | OnAfterOpen(); |
| | | WindowCenter.Instance.NotifyAfterOpen(this); |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | Debug.Log(ex.StackTrace); |
| | | } |
| | | finally |
| | | { |
| | | windowInfo.raycastTarget = true; |
| | | windowState = WindowState.Opened; |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void OnClosing() |
| | | { |
| | | if (playAnimation && windowInfo.tween && windowTimer < windowInfo.tween.duration) |
| | | { |
| | | windowTimer += Time.deltaTime; |
| | | if (windowTimer > windowInfo.tween.duration) |
| | | { |
| | | try |
| | | { |
| | | WindowCenter.Instance.NotifyAfterClose(this); |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | Debug.Log(ex.StackTrace); |
| | | } |
| | | finally |
| | | { |
| | | if (windowInfo.needMask) |
| | | { |
| | | CameraUtility.StopShotCut(windowMask); |
| | | windowMask.transform.SetParentEx(this.transform, Vector3.zero, Quaternion.identity, Vector3.one); |
| | | } |
| | | |
| | | if (windowInfo.windowType == WindowType.Base) |
| | | { |
| | | this.enabled = false; |
| | | this.rectTransform.SetParentEx(WindowCenter.Instance.uiRoot.recycleBin, Vector3.zero, Vector3.zero, Vector3.one); |
| | | } |
| | | else |
| | | { |
| | | this.gameObject.SetActive(false); |
| | | } |
| | | |
| | | windowState = WindowState.Closed; |
| | | } |
| | | |
| | | try |
| | | { |
| | | OnAfterClose(); |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | Debug.Log(ex.StackTrace); |
| | | } |
| | | |
| | | try |
| | | { |
| | | WindowCenter.Instance.JumpNotifyAfterClose(this); |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | Debug.Log(ex.StackTrace); |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | try |
| | | { |
| | | WindowCenter.Instance.NotifyAfterClose(this); |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | Debug.Log(ex.StackTrace); |
| | | } |
| | | finally |
| | | { |
| | | if (windowInfo.needMask) |
| | | { |
| | | CameraUtility.StopShotCut(windowMask); |
| | | windowMask.transform.SetParentEx(this.transform, Vector3.zero, Quaternion.identity, Vector3.one); |
| | | } |
| | | |
| | | if (windowInfo.windowType == WindowType.Base) |
| | | { |
| | | this.enabled = false; |
| | | this.rectTransform.SetParentEx(WindowCenter.Instance.uiRoot.recycleBin, Vector3.zero, Vector3.zero, Vector3.one); |
| | | } |
| | | else |
| | | { |
| | | this.gameObject.SetActive(false); |
| | | } |
| | | |
| | | windowState = WindowState.Closed; |
| | | } |
| | | |
| | | try |
| | | { |
| | | OnAfterClose(); |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | Debug.Log(ex.StackTrace); |
| | | } |
| | | |
| | | try |
| | | { |
| | | WindowCenter.Instance.JumpNotifyAfterClose(this); |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | Debug.Log(ex.StackTrace); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void ActiveWindow() |
| | | { |
| | | if (windowState == WindowState.Closed || windowState == WindowState.Closing) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | this.enabled = true; |
| | | |
| | | if (!this.gameObject.activeInHierarchy) |
| | | { |
| | | this.gameObject.SetActive(true); |
| | | } |
| | | |
| | | if (windowMask != null) |
| | | { |
| | | windowMask.color.SetA(1f); |
| | | windowMask.gameObject.SetActive(true); |
| | | } |
| | | |
| | | try |
| | | { |
| | | OnActived(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Debug.Log(ex.StackTrace); |
| | | } |
| | | |
| | | if (playAnimation && windowInfo.tween != null) |
| | | { |
| | | windowInfo.tween.reversal = false; |
| | | windowInfo.tween.Play(); |
| | | } |
| | | } |
| | | |
| | | private void AddEmptyCloseResponser() |
| | | { |
| | | var emptyClose = UIUtility.CreateWidget("InvisibleButton", "EmptyClose"); |
| | | var rectTransform = emptyClose.transform as RectTransform; |
| | | rectTransform.SetParentEx(this.transform, Vector3.zero, Quaternion.identity, Vector3.one); |
| | | rectTransform.SetAsFirstSibling(); |
| | | rectTransform.MatchWhith(this.transform as RectTransform); |
| | | emptyCloseButton = emptyClose.GetComponent<ButtonEx>(); |
| | | emptyCloseButton.AddListener(CloseClick); |
| | | } |
| | | |
| | | private void AddSreenMask() |
| | | { |
| | | var maskObject = UIUtility.CreateWidget("ScreenMask", "ScreenMask"); |
| | | var rectTransform = maskObject.transform as RectTransform; |
| | | rectTransform.SetParentEx(this.transform, Vector3.zero, Quaternion.identity, Vector3.one); |
| | | rectTransform.SetAsFirstSibling(); |
| | | windowMask = maskObject.GetComponent<RawImage>(); |
| | | } |
| | | |
| | | private RectTransform FindParent(WindowType _type) |
| | | { |
| | | RectTransform parent = null; |
| | | switch (_type) |
| | | { |
| | | case WindowType.Base: |
| | | parent = WindowCenter.Instance.uiRoot.baseCanvas.transform as RectTransform; |
| | | break; |
| | | case WindowType.Normal: |
| | | parent = WindowCenter.Instance.uiRoot.normalCanvas.transform as RectTransform; |
| | | break; |
| | | case WindowType.Modal: |
| | | parent = WindowCenter.Instance.uiRoot.modalCanvas.transform as RectTransform; |
| | | break; |
| | | case WindowType.Tip: |
| | | parent = WindowCenter.Instance.uiRoot.tipsCanvas.transform as RectTransform; |
| | | break; |
| | | case WindowType.System: |
| | | parent = WindowCenter.Instance.uiRoot.systemCanvas.transform as RectTransform; |
| | | break; |
| | | case WindowType.Loading: |
| | | parent = WindowCenter.Instance.uiRoot.loadingCanvas.transform as RectTransform; |
| | | break; |
| | | default: |
| | | parent = WindowCenter.Instance.uiRoot.normalCanvas.transform as RectTransform; |
| | | break; |
| | | } |
| | | |
| | | return parent; |
| | | } |
| | | |
| | | public enum WindowState |
| | | { |
| | | Closed, |
| | | Opening, |
| | | Opened, |
| | | Closing, |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | using System;
|
| | | using UnityEngine;
|
| | | using UnityEngine.Events;
|
| | | using UnityEngine.UI;
|
| | |
|
| | | namespace Snxxz.UI
|
| | | {
|
| | |
|
| | | [DisallowMultipleComponent]
|
| | | [RequireComponent(typeof(WindowInfo))]
|
| | | public abstract class Window : MonoBehaviour
|
| | | {
|
| | |
|
| | | static readonly Vector3 HIDE_POSITION = new Vector3(0, 5000, 5000);
|
| | |
|
| | | WindowInfo m_WindowInfo = null;
|
| | | public WindowInfo windowInfo {
|
| | | get {
|
| | | return m_WindowInfo ?? (m_WindowInfo = this.GetComponent<WindowInfo>());
|
| | | }
|
| | | }
|
| | |
|
| | | public WindowState windowState {
|
| | | get; private set;
|
| | | }
|
| | |
|
| | | RectTransform rectTransform { get { return this.transform.AddMissingComponent<RectTransform>(); } }
|
| | |
|
| | | RawImage windowMask;
|
| | | ButtonEx emptyCloseButton;
|
| | | bool initialized = false;
|
| | | float windowTimer = 0f;
|
| | |
|
| | | int m_FunctionOrder = 0;
|
| | | public int functionOrder {
|
| | | get { return m_FunctionOrder; }
|
| | | set { m_FunctionOrder = value; }
|
| | | }
|
| | |
|
| | | public bool playAnimation { get; set; }
|
| | | public bool executedActiveWindow { get; set; }
|
| | |
|
| | | internal Window Open()
|
| | | {
|
| | | try
|
| | | {
|
| | | if (!initialized)
|
| | | {
|
| | | if (windowInfo.clickEmptyToClose && emptyCloseButton == null)
|
| | | {
|
| | | AddEmptyCloseResponser();
|
| | | }
|
| | |
|
| | | if (windowInfo.needMask && windowMask == null)
|
| | | {
|
| | | AddSreenMask();
|
| | | }
|
| | |
|
| | | BindController();
|
| | | AddListeners();
|
| | | initialized = true;
|
| | | }
|
| | | }
|
| | | catch (System.Exception ex)
|
| | | {
|
| | | Debug.Log(ex.StackTrace);
|
| | | }
|
| | |
|
| | | executedActiveWindow = false;
|
| | | RectTransform parent = null;
|
| | | try
|
| | | {
|
| | | windowTimer = 0f;
|
| | | var parentName = string.Empty;
|
| | | if (WindowConfig.Get().FindParentWindow(this.gameObject.name, out parentName))
|
| | | {
|
| | | var parentWindow = WindowCenter.Instance.Get(parentName);
|
| | | if (parentWindow != null)
|
| | | {
|
| | | parent = parentWindow.transform as RectTransform;
|
| | | rectTransform.MatchWhith(parent);
|
| | | }
|
| | | }
|
| | | OnPreOpen();
|
| | | WindowCenter.Instance.NotifyBeforeOpen(this);
|
| | | }
|
| | | catch (System.Exception ex)
|
| | | {
|
| | | Debug.Log(ex.StackTrace);
|
| | | }
|
| | | finally
|
| | | {
|
| | | if (parent == null)
|
| | | {
|
| | | parent = FindParent(windowInfo.windowType);
|
| | | if (parent != null)
|
| | | {
|
| | | rectTransform.MatchWhith(parent);
|
| | | if (windowInfo.windowType >= WindowType.Normal)
|
| | | {
|
| | | rectTransform.SetAsLastSibling();
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | windowState = WindowState.Opening;
|
| | | windowInfo.raycastTarget = false;
|
| | | if (windowInfo.needMask)
|
| | | {
|
| | | windowMask.rectTransform.MatchWhith(rectTransform.parent as RectTransform);
|
| | | windowMask.transform.localScale = Vector3.one * 1.01f;
|
| | | windowMask.transform.SetSiblingIndex(rectTransform.GetSiblingIndex());
|
| | | CameraUtility.ScreenShotCut(windowMask, ActiveWindow);
|
| | | }
|
| | | else
|
| | | {
|
| | | ActiveWindow();
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | return this;
|
| | | }
|
| | |
|
| | | internal Window Close()
|
| | | {
|
| | | try
|
| | | {
|
| | | OnPreClose();
|
| | | }
|
| | | catch (System.Exception ex)
|
| | | {
|
| | | Debug.Log(ex.StackTrace);
|
| | | }
|
| | |
|
| | | try
|
| | | {
|
| | | windowTimer = 0f;
|
| | | if (playAnimation && windowInfo.tween != null)
|
| | | {
|
| | | windowInfo.tween.Play(true);
|
| | | }
|
| | |
|
| | | WindowCenter.Instance.NotifyBeforeClose(this);
|
| | | }
|
| | | catch (System.Exception ex)
|
| | | {
|
| | | Debug.Log(ex.StackTrace);
|
| | | }
|
| | | finally
|
| | | {
|
| | | windowInfo.raycastTarget = false;
|
| | | windowState = WindowState.Closing;
|
| | | }
|
| | |
|
| | | executedActiveWindow = false;
|
| | | return this;
|
| | | }
|
| | |
|
| | | internal Window CloseImmediately()
|
| | | {
|
| | | try
|
| | | {
|
| | | OnPreClose();
|
| | | }
|
| | | catch (System.Exception ex)
|
| | | {
|
| | | Debug.Log(ex.Message);
|
| | | }
|
| | |
|
| | | try
|
| | | {
|
| | | windowInfo.raycastTarget = false;
|
| | | WindowCenter.Instance.NotifyBeforeClose(this);
|
| | | }
|
| | | catch (System.Exception ex)
|
| | | {
|
| | | Debug.Log(ex.StackTrace);
|
| | | }
|
| | | finally
|
| | | {
|
| | | if (windowInfo.needMask)
|
| | | {
|
| | | CameraUtility.StopShotCut(windowMask);
|
| | | windowMask.transform.SetParentEx(this.transform, Vector3.zero, Quaternion.identity, Vector3.one);
|
| | | }
|
| | |
|
| | | if (windowInfo.windowType == WindowType.Base)
|
| | | {
|
| | | this.enabled = false;
|
| | | this.rectTransform.SetParentEx(WindowCenter.Instance.uiRoot.recycleBin, Vector3.zero, Vector3.zero, Vector3.one);
|
| | | }
|
| | | else
|
| | | {
|
| | | this.gameObject.SetActive(false);
|
| | | }
|
| | |
|
| | | windowState = WindowState.Closed;
|
| | | }
|
| | |
|
| | | try
|
| | | {
|
| | | WindowCenter.Instance.NotifyAfterClose(this);
|
| | | }
|
| | | catch (System.Exception ex)
|
| | | {
|
| | | Debug.Log(ex.StackTrace);
|
| | | }
|
| | |
|
| | | try
|
| | | {
|
| | | OnAfterClose();
|
| | | executedActiveWindow = false;
|
| | | }
|
| | | catch (System.Exception ex)
|
| | | {
|
| | | Debug.Log(ex.StackTrace);
|
| | | }
|
| | |
|
| | | try
|
| | | {
|
| | | WindowCenter.Instance.JumpNotifyAfterClose(this);
|
| | | }
|
| | | catch (System.Exception ex)
|
| | | {
|
| | | Debug.Log(ex.StackTrace);
|
| | | }
|
| | |
|
| | | return this;
|
| | | }
|
| | |
|
| | | internal void SetMask(GameObject _mask)
|
| | | {
|
| | | if (_mask != null)
|
| | | {
|
| | | _mask.transform.SetParentEx(this.transform, Vector3.zero, Quaternion.identity, Vector3.one);
|
| | | _mask.transform.SetAsFirstSibling();
|
| | | }
|
| | | }
|
| | |
|
| | | public virtual void CloseClick()
|
| | | {
|
| | | CloseImmediately();
|
| | | }
|
| | |
|
| | | public void ChildActive()
|
| | | {
|
| | | OnActived();
|
| | | }
|
| | |
|
| | | protected virtual void LateUpdate()
|
| | | {
|
| | |
|
| | | }
|
| | |
|
| | | protected virtual void OnActived()
|
| | | {
|
| | |
|
| | | }
|
| | |
|
| | | protected abstract void BindController();
|
| | | protected abstract void AddListeners();
|
| | | protected abstract void OnPreOpen();
|
| | | protected abstract void OnAfterOpen();
|
| | | protected abstract void OnPreClose();
|
| | | protected abstract void OnAfterClose();
|
| | |
|
| | | private void Update()
|
| | | {
|
| | | switch (windowState)
|
| | | {
|
| | | case WindowState.Opening:
|
| | | OnOpening();
|
| | | break;
|
| | | case WindowState.Closing:
|
| | | OnClosing();
|
| | | break;
|
| | | }
|
| | | }
|
| | |
|
| | | private void OnOpening()
|
| | | {
|
| | | if (playAnimation && windowInfo.tween != null && windowTimer < windowInfo.tween.duration)
|
| | | {
|
| | | windowTimer += Time.deltaTime;
|
| | | if (windowTimer > windowInfo.tween.duration)
|
| | | {
|
| | | try
|
| | | {
|
| | | OnAfterOpen();
|
| | | WindowCenter.Instance.NotifyAfterOpen(this);
|
| | | }
|
| | | catch (System.Exception ex)
|
| | | {
|
| | | Debug.Log(ex.Message);
|
| | | }
|
| | | finally
|
| | | {
|
| | | windowInfo.raycastTarget = true;
|
| | | windowState = WindowState.Opened;
|
| | | }
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | try
|
| | | {
|
| | | OnAfterOpen();
|
| | | WindowCenter.Instance.NotifyAfterOpen(this);
|
| | | }
|
| | | catch (System.Exception ex)
|
| | | {
|
| | | Debug.Log(ex.StackTrace);
|
| | | }
|
| | | finally
|
| | | {
|
| | | windowInfo.raycastTarget = true;
|
| | | windowState = WindowState.Opened;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | private void OnClosing()
|
| | | {
|
| | | if (playAnimation && windowInfo.tween && windowTimer < windowInfo.tween.duration)
|
| | | {
|
| | | windowTimer += Time.deltaTime;
|
| | | if (windowTimer > windowInfo.tween.duration)
|
| | | {
|
| | | try
|
| | | {
|
| | | WindowCenter.Instance.NotifyAfterClose(this);
|
| | | }
|
| | | catch (System.Exception ex)
|
| | | {
|
| | | Debug.Log(ex.StackTrace);
|
| | | }
|
| | | finally
|
| | | {
|
| | | if (windowInfo.needMask)
|
| | | {
|
| | | CameraUtility.StopShotCut(windowMask);
|
| | | windowMask.transform.SetParentEx(this.transform, Vector3.zero, Quaternion.identity, Vector3.one);
|
| | | }
|
| | |
|
| | | if (windowInfo.windowType == WindowType.Base)
|
| | | {
|
| | | this.enabled = false;
|
| | | this.rectTransform.SetParentEx(WindowCenter.Instance.uiRoot.recycleBin, Vector3.zero, Vector3.zero, Vector3.one);
|
| | | }
|
| | | else
|
| | | {
|
| | | this.gameObject.SetActive(false);
|
| | | }
|
| | |
|
| | | windowState = WindowState.Closed;
|
| | | }
|
| | |
|
| | | try
|
| | | {
|
| | | OnAfterClose();
|
| | | executedActiveWindow = false;
|
| | | }
|
| | | catch (System.Exception ex)
|
| | | {
|
| | | Debug.Log(ex.StackTrace);
|
| | | }
|
| | |
|
| | | try
|
| | | {
|
| | | WindowCenter.Instance.JumpNotifyAfterClose(this);
|
| | | }
|
| | | catch (System.Exception ex)
|
| | | {
|
| | | Debug.Log(ex.StackTrace);
|
| | | }
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | try
|
| | | {
|
| | | WindowCenter.Instance.NotifyAfterClose(this);
|
| | | }
|
| | | catch (System.Exception ex)
|
| | | {
|
| | | Debug.Log(ex.StackTrace);
|
| | | }
|
| | | finally
|
| | | {
|
| | | if (windowInfo.needMask)
|
| | | {
|
| | | CameraUtility.StopShotCut(windowMask);
|
| | | windowMask.transform.SetParentEx(this.transform, Vector3.zero, Quaternion.identity, Vector3.one);
|
| | | }
|
| | |
|
| | | if (windowInfo.windowType == WindowType.Base)
|
| | | {
|
| | | this.enabled = false;
|
| | | this.rectTransform.SetParentEx(WindowCenter.Instance.uiRoot.recycleBin, Vector3.zero, Vector3.zero, Vector3.one);
|
| | | }
|
| | | else
|
| | | {
|
| | | this.gameObject.SetActive(false);
|
| | | }
|
| | |
|
| | | windowState = WindowState.Closed;
|
| | | }
|
| | |
|
| | | try
|
| | | {
|
| | | OnAfterClose();
|
| | | executedActiveWindow = false;
|
| | | }
|
| | | catch (System.Exception ex)
|
| | | {
|
| | | Debug.Log(ex.StackTrace);
|
| | | }
|
| | |
|
| | | try
|
| | | {
|
| | | WindowCenter.Instance.JumpNotifyAfterClose(this);
|
| | | }
|
| | | catch (System.Exception ex)
|
| | | {
|
| | | Debug.Log(ex.StackTrace);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | private void ActiveWindow()
|
| | | {
|
| | | if (windowState == WindowState.Closed || windowState == WindowState.Closing)
|
| | | {
|
| | | return;
|
| | | }
|
| | |
|
| | | this.enabled = true;
|
| | |
|
| | | if (!this.gameObject.activeInHierarchy)
|
| | | {
|
| | | this.gameObject.SetActive(true);
|
| | | }
|
| | |
|
| | | if (windowMask != null)
|
| | | {
|
| | | windowMask.color.SetA(1f);
|
| | | windowMask.gameObject.SetActive(true);
|
| | | }
|
| | |
|
| | | try
|
| | | {
|
| | | var isChildWindow = WindowConfig.Get().IsChildWindow(this.gameObject.name);
|
| | | if (isChildWindow)
|
| | | {
|
| | | var parentName = string.Empty;
|
| | | WindowConfig.Get().FindParentWindow(this.gameObject.name, out parentName);
|
| | | var parentWindow = WindowCenter.Instance.Get(parentName);
|
| | | if (parentWindow != null && parentWindow.executedActiveWindow)
|
| | | {
|
| | | OnActived();
|
| | | executedActiveWindow = true;
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | OnActived();
|
| | | executedActiveWindow = true;
|
| | | var childWindows = WindowConfig.Get().FindChildWindows(this.gameObject.name);
|
| | | var isParentWindow = childWindows != null;
|
| | | if (isParentWindow)
|
| | | {
|
| | | foreach (var child in childWindows)
|
| | | {
|
| | | var window = WindowCenter.Instance.Get(child);
|
| | | if (window != null && !window.executedActiveWindow)
|
| | | {
|
| | | window.ChildActive();
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | | catch (Exception ex)
|
| | | {
|
| | | Debug.Log(ex.StackTrace);
|
| | | }
|
| | |
|
| | | if (playAnimation && windowInfo.tween != null)
|
| | | {
|
| | | windowInfo.tween.reversal = false;
|
| | | windowInfo.tween.Play();
|
| | | }
|
| | | }
|
| | |
|
| | | private void AddEmptyCloseResponser()
|
| | | {
|
| | | var emptyClose = UIUtility.CreateWidget("InvisibleButton", "EmptyClose");
|
| | | var rectTransform = emptyClose.transform as RectTransform;
|
| | | rectTransform.SetParentEx(this.transform, Vector3.zero, Quaternion.identity, Vector3.one);
|
| | | rectTransform.SetAsFirstSibling();
|
| | | rectTransform.MatchWhith(this.transform as RectTransform);
|
| | | emptyCloseButton = emptyClose.GetComponent<ButtonEx>();
|
| | | emptyCloseButton.AddListener(CloseClick);
|
| | | }
|
| | |
|
| | | private void AddSreenMask()
|
| | | {
|
| | | var maskObject = UIUtility.CreateWidget("ScreenMask", "ScreenMask");
|
| | | var rectTransform = maskObject.transform as RectTransform;
|
| | | rectTransform.SetParentEx(this.transform, Vector3.zero, Quaternion.identity, Vector3.one);
|
| | | rectTransform.SetAsFirstSibling();
|
| | | windowMask = maskObject.GetComponent<RawImage>();
|
| | | }
|
| | |
|
| | | private RectTransform FindParent(WindowType _type)
|
| | | {
|
| | | RectTransform parent = null;
|
| | | switch (_type)
|
| | | {
|
| | | case WindowType.Base:
|
| | | parent = WindowCenter.Instance.uiRoot.baseCanvas.transform as RectTransform;
|
| | | break;
|
| | | case WindowType.Normal:
|
| | | parent = WindowCenter.Instance.uiRoot.normalCanvas.transform as RectTransform;
|
| | | break;
|
| | | case WindowType.Modal:
|
| | | parent = WindowCenter.Instance.uiRoot.modalCanvas.transform as RectTransform;
|
| | | break;
|
| | | case WindowType.Tip:
|
| | | parent = WindowCenter.Instance.uiRoot.tipsCanvas.transform as RectTransform;
|
| | | break;
|
| | | case WindowType.System:
|
| | | parent = WindowCenter.Instance.uiRoot.systemCanvas.transform as RectTransform;
|
| | | break;
|
| | | case WindowType.Loading:
|
| | | parent = WindowCenter.Instance.uiRoot.loadingCanvas.transform as RectTransform;
|
| | | break;
|
| | | default:
|
| | | parent = WindowCenter.Instance.uiRoot.normalCanvas.transform as RectTransform;
|
| | | break;
|
| | | }
|
| | |
|
| | | return parent;
|
| | | }
|
| | |
|
| | | public enum WindowState
|
| | | {
|
| | | Closed,
|
| | | Opening,
|
| | | Opened,
|
| | | Closing,
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | |
|
| | | } |