WXMC/.svn/pristine/96/964c2f981b250bcff5e7ba37495182a518fe8b40.svn-base

102 lines
2.2 KiB
Plaintext
Raw Normal View History

2024-12-04 16:18:46 +08:00
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
using System.IO;
using System.Collections.Generic;
public class UIRoot : MonoSingletion<UIRoot>
{
public Transform root;
public Transform popUpRoot;
public Transform normalRoot;
Canvas rootCanvas;
public Canvas RootCanvas
{
get { return rootCanvas; }
}
public Camera UICamera
{
get { return rootCanvas.worldCamera; }
}
public void Tmp()
{
}
protected override void Awake()
{
base.Awake();
/******************GC优化******************/
useGUILayout = false;//不关闭每帧有GC
/************************************/
if (root == null)
root = this.transform;
rootCanvas = root.GetComponent<Canvas>();
if (popUpRoot == null)
{
GameObject go = CreateSubCanvas(root, 500);
go.name = "PopUpUICanvas";
popUpRoot = go.transform;
}
if (normalRoot == null)
{
GameObject go = CreateSubCanvas(root, 0);
go.name = "NormalUICanvas";
normalRoot = go.transform;
}
}
public void StartCoroutines(IEnumerator ie)
{
StartCoroutine(ie);
}
void Start()
{
}
public void StartLogin() {
UIMgr.ShowUI(UIPath.Login);
}
GameObject CreateSubCanvas(Transform root, int sortOrder)
{
GameObject go = new GameObject("NewCanvas");
go.transform.SetParent(root, false);
go.layer = root.gameObject.layer;
Canvas canvas = go.AddComponent<Canvas>();
canvas.overrideSorting = true;
canvas.sortingOrder = sortOrder;
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
RectTransform rect = go.GetComponent<RectTransform>();
rect.anchorMin = Vector2.zero;
rect.anchorMax = Vector2.one;
rect.sizeDelta = Vector2.zero;
rect.localScale = Vector3.one;
//负责检测UI射线检测否则界面点击没有反应
go.AddComponent<GraphicRaycaster>();
return go;
}
}