//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Friday, July 28, 2017
|
//--------------------------------------------------------
|
using UnityEngine;
|
using System.Collections;
|
|
namespace vnxbqy.UI
|
{
|
|
//[ExecuteAlways]
|
[DisallowMultipleComponent]
|
[RequireComponent(typeof(RectTransform))]
|
public class WindowInfo : MonoBehaviour, ICanvasRaycastFilter
|
{
|
|
[SerializeField]
|
WindowType m_WindowType = WindowType.Normal;
|
public WindowType windowType {
|
get { return m_WindowType; }
|
set { m_WindowType = value; }
|
}
|
|
[SerializeField]
|
Tween m_Tween;
|
public Tween tween {
|
get { return m_Tween; }
|
set { m_Tween = value; }
|
}
|
|
[SerializeField]
|
bool m_ClickEmptyToClose = false;
|
public bool clickEmptyToClose {
|
get { return m_ClickEmptyToClose; }
|
set { m_ClickEmptyToClose = value; }
|
}
|
|
[SerializeField]
|
bool m_NeedMask = false;
|
public bool needMask {
|
get { return m_NeedMask; }
|
set { m_NeedMask = value; }
|
}
|
|
[SerializeField]
|
bool m_FullScreen = false;
|
public bool fullScreen {
|
get { return m_FullScreen; }
|
set { m_FullScreen = value; }
|
}
|
|
[SerializeField]
|
bool m_RaycastTarget = true;
|
public bool raycastTarget {
|
get { return m_RaycastTarget; }
|
set { m_RaycastTarget = value; }
|
}
|
|
public bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera)
|
{
|
return raycastTarget;
|
}
|
|
//[ExecuteAlways]
|
private void Awake()
|
{
|
#if UNITY_EDITOR
|
if (!Application.isPlaying)
|
{
|
FindParent();
|
}
|
#endif
|
}
|
|
private void FindParent()
|
{
|
var uiroot = GameObject.FindObjectOfType<UIRoot>();
|
if (uiroot == null)
|
{
|
var prefab = BuiltInLoader.LoadPrefab("UIRoot");
|
var instance = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity);
|
instance.name = "UIRoot";
|
uiroot = instance.GetComponent<UIRoot>();
|
}
|
|
uiroot.uicamera.clearFlags = CameraClearFlags.SolidColor;
|
|
var rectTransform = this.transform as RectTransform;
|
RectTransform parent = null;
|
switch (windowType)
|
{
|
case WindowType.Base:
|
parent = uiroot.baseCanvas.transform as RectTransform;
|
break;
|
case WindowType.Normal:
|
parent = uiroot.normalCanvas.transform as RectTransform;
|
break;
|
case WindowType.Modal:
|
parent = uiroot.modalCanvas.transform as RectTransform;
|
break;
|
case WindowType.Tip:
|
parent = uiroot.tipsCanvas.transform as RectTransform;
|
break;
|
case WindowType.System:
|
parent = uiroot.systemCanvas.transform as RectTransform;
|
break;
|
case WindowType.Loading:
|
parent = uiroot.loadingCanvas.transform as RectTransform;
|
break;
|
}
|
|
if (parent != null)
|
{
|
rectTransform.MatchWhith(parent);
|
}
|
#if UNITY_EDITOR
|
UnityEditor.Selection.activeGameObject = this.gameObject;
|
#endif
|
}
|
|
}
|
|
}
|
|
|
|