using UnityEngine; using System.Collections; public class PopUpManager : MonoBehaviour { public static bool modal = false; public static void UpdateModal() { PopUpPanel[] popUpPanels = GameObject.FindObjectsOfType(); for(int i=0; i(gameObj, popType.ToString())); panel = (PopUpPanel)gameObj.AddComponent(panelType); } else { panel = gameObj.GetComponent(); } //panel.gameObject.AddComponent(); DllManager.instance.AddCompotent(panel.gameObject, "PopUpUtil"); Vector3 originSizeDelta = panel.GetComponent().sizeDelta; if(parent == null) { MainCanvas canvas = GameObject.FindObjectOfType(); //parent = canvas.transform.FindChild("UIRoot"); PopUpManager.AddToForwardCanvas(gameObj); } panel.modal = modal; panel.Added(); UpdateModal(); return panel; } public static void AddToMainCanvas(GameObject gameObj, Transform parent = null) { RectTransform rectTrans = gameObj.GetComponent(); if(rectTrans != null) { Vector3 originPos = rectTrans.localPosition; Vector3 originSizeDelta = rectTrans.sizeDelta; Vector3 originRotation = rectTrans.localEulerAngles; if(parent == null) { MainCanvas canvas = GameObject.FindObjectOfType(); parent = canvas.transform.FindChild("UIRoot"); } gameObj.transform.SetParent(parent); gameObj.transform.localScale = new Vector3(1f, 1f, 1f); rectTrans.localPosition = originPos; rectTrans.sizeDelta = originSizeDelta; rectTrans.localEulerAngles = originRotation; } else { Vector3 pos =gameObj.transform.localPosition; Vector3 scale = gameObj.transform.localScale; if(parent == null) { MainCanvas canvas = GameObject.FindObjectOfType(); parent = canvas.transform.FindChild("UIRoot"); } gameObj.transform.SetParent(parent); gameObj.transform.localScale = scale; gameObj.transform.localPosition = pos; } } public static void AddToForwardCanvas(GameObject gameObj, Transform parent = null) { RectTransform rectTrans = gameObj.GetComponent(); if(rectTrans != null) { Vector3 anchoredPosition3D = rectTrans.anchoredPosition3D; Vector3 originSizeDelta = rectTrans.sizeDelta; Vector3 originRotation = rectTrans.localEulerAngles; if(parent == null) { ForwardCanvas canvas = GameObject.FindObjectOfType(); parent = canvas.transform.FindChild("UIRoot"); } gameObj.transform.SetParent(parent); gameObj.transform.localScale = new Vector3(1f, 1f, 1f); rectTrans.anchoredPosition3D = anchoredPosition3D; rectTrans.sizeDelta = originSizeDelta; rectTrans.localEulerAngles = originRotation; } else { Vector3 pos =gameObj.transform.localPosition; Vector3 scale = gameObj.transform.localScale; if(parent == null) { MainCanvas canvas = GameObject.FindObjectOfType(); parent = canvas.transform.FindChild("UIRoot"); } gameObj.transform.SetParent(parent); gameObj.transform.localScale = scale; gameObj.transform.localPosition = pos; } } public static void ClearForwardCanvas() { ForwardCanvas canvas = GameObject.FindObjectOfType(); Transform parent = canvas.transform.FindChild("UIRoot"); int count = parent.childCount - 1; for (int i = count; i > -1; i--) { PopUpPanel panel = parent.GetChild(i).GetComponent(); if (panel != null) Destroy(panel.gameObject);// panel.OnClose(); } } public static void RemovePopUp(PopUpPanel panel) { Destroy(panel.gameObject); UpdateModal(); } }