123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- using System;
- using UnityEngine;
- namespace Kasizuki
- {
- public class NGUIWindow : MonoBehaviour
- {
- protected virtual void Awake()
- {
- if (this.m_CachedObjectDic == null)
- {
- this.m_CachedObjectDic = new ObjectCacheDic();
- }
- }
- public void Open(float time = 0.25f, Action callback = null)
- {
- if (!base.gameObject.activeSelf)
- {
- base.gameObject.SetActive(true);
- }
- if (this.OnOpen != null)
- {
- this.OnOpen();
- }
- this.SetRaycastBlockerActive(true);
- this.tweenAlpha.SetOnFinished(delegate
- {
- if (callback != null)
- {
- callback();
- }
- this.SetRaycastBlockerActive(false);
- });
- TweenAlpha.Begin(base.gameObject, time, 1f);
- }
- public void Close(float time = 0.25f, Action callback = null)
- {
- if (!base.gameObject.activeInHierarchy)
- {
- return;
- }
- callback = (Action)Delegate.Combine(callback, new Action(delegate
- {
- this.gameObject.SetActive(false);
- if (this.OnClose != null)
- {
- this.OnClose();
- }
- }));
- this.SetRaycastBlockerActive(true);
- this.tweenAlpha.SetOnFinished(delegate
- {
- if (callback != null)
- {
- callback();
- }
- this.SetRaycastBlockerActive(false);
- });
- TweenAlpha.Begin(base.gameObject, time, 0f);
- }
- public Action OnOpen { get; set; }
- public Action OnClose { get; set; }
- private GameObject raycastBlocker
- {
- get
- {
- if (this.m_RaycastBlocker == null)
- {
- this.m_RaycastBlocker = this.CreateBlocker();
- }
- return this.m_RaycastBlocker;
- }
- }
- private GameObject CreateBlocker()
- {
- GameObject gameObject = null;
- UIRect component = base.gameObject.GetComponent<UIRect>();
- if (component != null)
- {
- gameObject = new GameObject("Ray Blocker");
- gameObject.transform.SetParent(base.transform, false);
- gameObject.layer = base.gameObject.layer;
- gameObject.AddComponent<BoxCollider>();
- UIWidget uiwidget = gameObject.AddComponent<UIWidget>();
- uiwidget.depth = 9999;
- uiwidget.updateAnchors = UIRect.AnchorUpdate.OnStart;
- uiwidget.SetRect(-2500f, -2500f, 5000f, 5000f);
- uiwidget.autoResizeBoxCollider = true;
- uiwidget.ResizeCollider();
- }
- else
- {
- Debug.Log("[NGUI Window] " + base.gameObject.name + "には UI Rect を継承したクラスがありません");
- }
- return gameObject;
- }
- private void SetRaycastBlockerActive(bool isActive)
- {
- if (this.raycastBlocker == null)
- {
- return;
- }
- if (this.raycastBlocker.activeSelf != isActive)
- {
- this.raycastBlocker.SetActive(isActive);
- }
- }
- public T AddCache<T>(string name, T Obj) where T : UnityEngine.Object
- {
- if (this.m_CachedObjectDic == null)
- {
- this.m_CachedObjectDic = new ObjectCacheDic();
- }
- this.m_CachedObjectDic.AddCache<T>(name, Obj);
- return Obj;
- }
- public T GetCache<T>(string name) where T : UnityEngine.Object
- {
- return this.m_CachedObjectDic.GetCache<T>(name);
- }
- public void RemoveCache(string name)
- {
- this.m_CachedObjectDic.RemoveCache(name);
- }
- public GameObject GetChildObject(string name)
- {
- return UTY.GetChildObject(base.gameObject, name, false);
- }
- public T GetChildObject<T>(string name) where T : UnityEngine.Object
- {
- if (this.m_CachedObjectDic == null)
- {
- this.m_CachedObjectDic = new ObjectCacheDic();
- }
- return this.m_CachedObjectDic.GetChildObject<T>(base.gameObject, name);
- }
- public T CacheChildObject<T>(string path, string name) where T : UnityEngine.Object
- {
- return this.AddCache<T>(name, this.GetChildObject<T>(path));
- }
- public ObjectCacheDic cachedObjectDic
- {
- get
- {
- return this.m_CachedObjectDic;
- }
- }
- private TweenAlpha tweenAlpha
- {
- get
- {
- if (this.m_TweenAlpha == null)
- {
- this.m_TweenAlpha = base.GetComponent<TweenAlpha>();
- if (this.m_TweenAlpha == null)
- {
- this.m_TweenAlpha = base.gameObject.AddComponent<TweenAlpha>();
- if (this.m_TweenAlpha == null)
- {
- Debug.LogErrorFormat("「{0}」には「{1}」をアタッチ出来ません", new object[]
- {
- base.gameObject.name,
- typeof(TweenAlpha).Name
- });
- }
- }
- }
- return this.m_TweenAlpha;
- }
- }
- private GameObject m_RaycastBlocker;
- private TweenAlpha m_TweenAlpha;
- private ObjectCacheDic m_CachedObjectDic;
- }
- }
|