protected void AdaptationUI(RectTransform rect, EUICanvas eEUICanvas) { if (rect != null) { rect.anchorMin = new Vector2(0, 0); rect.anchorMax = new Vector2(1f, 1f); rect.transform.localScale = Vector3.one; UIManagerCanvas canvas = GetCanvas(eEUICanvas); //真实宽度 float RealScreenScale = Screen.width / (float)Screen.height; float ReadWidth = canvas.canvasScaler.referenceResolution.y * RealScreenScale; //实际宽度 float width = canvas.canvasScaler.referenceResolution.y * m_ScreenScale; float height = canvas.canvasScaler.referenceResolution.y; float offsetX = 0; if (width > ReadWidth) { width = ReadWidth; } else { offsetX = (ReadWidth - width) * 0.5f; } rect.offsetMax = new Vector2(-offsetX, 0); rect.offsetMin = new Vector2(offsetX, 0); //rect.sizeDelta = new Vector2(width, 0); } }
public void SetCanvasActive(EUICanvas canvas, bool isActive) { GameObject target = GetCanvas(canvas); if (target) { target.SetActive(isActive); } }
public void SetCanvas(UIBase ui, EUICanvas eType, bool isAutoReset = true) { UIManagerCanvas canvas = null; if (m_canvasDic.TryGetValue(eType, out canvas)) { canvas.SetUI(ui.transform, isAutoReset); } }
// DealLuaObject(string uiPath, string luaPath, EUIType eType, bool useBack, EUICanvas canvas, bool isAutoReset, bool preLoad = false) public UIPreLoad(string uiPath, EUIType eType, bool useBack, EUICanvas canvas, bool isAutoReset, bool preLoad = false) { this.uiPath = uiPath; this.eType = eType; this.useBack = useBack; this.canvas = canvas; this.isAutoReset = isAutoReset; this.preLoad = preLoad; }
public Vector3 ScreenToWorldPoint(EUICanvas eCanvas, Vector3 vec) { UIManagerCanvas canvas = null; if (m_canvasDic.TryGetValue(eCanvas, out canvas)) { return(canvas.ScreenToWorldPoint(vec)); } return(vec); }
public Vector3 WorldToScreenPoint(int index, Vector3 vec) { EUICanvas eCanvas = (EUICanvas)index; UIManagerCanvas canvas = null; if (m_canvasDic.TryGetValue(eCanvas, out canvas)) { return(canvas.WorldToScreenPoint(vec)); } return(vec); }
public UIManagerCanvas GetCanvas(EUICanvas eType) { if (m_canvasDic.ContainsKey(eType)) { return(m_canvasDic[eType]); } else { return(null); } }
protected void SetCanvas(GameObject canvaspre, EUICanvas eCanvas) { if (!m_canvasDic.ContainsKey(eCanvas)) { GameObject go = GameObject.Instantiate(canvaspre); go.name = eCanvas.ToString(); go.transform.SetParent(tranform); ResetNode(go.transform); UIManagerCanvas data = new UIManagerCanvas(); data.Initalize(go, eCanvas); data.SetParent(tranform); m_canvasDic[eCanvas] = data; } }
public void AddButtonCallback(EUICanvas canvas, string buttonName, UnityAction callback) { GameObject target = GetCanvas(canvas); if (target) { foreach (var button in target.GetComponentsInChildren <Button> (true)) { if (buttonName == button.gameObject.name) { button.onClick.AddListener(callback); break; } } } }
protected void RegisterUI(UIBase uiBase, EUICanvas eType, bool isAutoReset) { UIManagerCanvas canvas = null; if (m_canvasDic.TryGetValue(eType, out canvas)) { canvas.SetUI(uiBase.transform, isAutoReset); if (uiBase != null) { if (uiBase.useBack) { uiBase.SetOverrideSorting(true); } uiBase.order = canvas.canvas.sortingOrder; uiBase.gameObject.SetActive(false); } } }
private GameObject GetCanvas(EUICanvas canvas) { switch (canvas) { case EUICanvas.MainMenu: return(m_mainMenuCanvas); case EUICanvas.Loading: return(m_loadingCanvas); case EUICanvas.Play: return(m_playCanvas); case EUICanvas.Tutorial: return(m_tutorialCanvas); } return(null); }
public bool Add <T>(Type type, string uiPath, EUICanvas eCanvas, bool isAutoReset = true, bool isUseBack = false) where T : UIBase { if (m_uiDic.ContainsKey(type)) { return(false); } GameObject obj = Res.ResourcesManager.Instance.SyncGetResource <GameObject>(uiPath, Res.ResourceType.UI); T com = obj.AddComponent <T>(); UIManager.Instance.SetCanvas(com, eCanvas, isAutoReset); string name = obj.name.Replace("(Clone)", string.Empty); com.name = name; com.useBack = isUseBack; com.isGame = false; com.eUICanvas = eCanvas; com.Initalize(); m_uiDic[type] = com; return(true); }
public void AdaptationUI(GameObject go, EUICanvas eEUICanvas) { RectTransform rect = go.GetComponent <RectTransform>(); AdaptationUI(rect, eEUICanvas); }
public void Initalize(GameObject gameObject, EUICanvas canvasType) { this.gameObject = gameObject; this.gameObject.SetActive(true); this.transform = gameObject.transform; m_eCanvasType = canvasType; m_CameraUI = Utility.GameUtility.FindDeepChild(gameObject, "Camera/Camera_UI"); m_CameraUICom = m_CameraUI.GetComponent <Camera>(); switch (m_eCanvasType) { case EUICanvas.EUICanvas_Move: m_CameraUICom.depth = DepthUtils.UIMove; break; case EUICanvas.EUICanvas_Normal: m_CameraUICom.depth = DepthUtils.UI; break; case EUICanvas.EUICanvas_Top: m_CameraUICom.depth = DepthUtils.UITop; break; case EUICanvas.EUICanvas_Bottom: m_CameraUICom.depth = DepthUtils.UIBottom; break; case EUICanvas.EUICanvas_WordMap: m_CameraUICom.depth = DepthUtils.UIWorldMap; break; default: m_CameraUICom.depth = DepthUtils.UI; break; } m_CameraUICom.nearClipPlane = -100; // m_Camera3D = Utility.GameUtility.FindDeepChild(gameObject, "Camera/Camera_3D"); m_CanvasTransform = Utility.GameUtility.FindDeepChild(gameObject, "CanvasChain"); m_Canvas = m_CanvasTransform.gameObject.GetComponent <Canvas>(); m_CanvasScaler = m_CanvasTransform.gameObject.GetComponent <CanvasScaler>(); SetCulliingMask(); SetLayer((int)m_CameraUICom.depth); int layer = 0; switch (m_eCanvasType) { case EUICanvas.EUICanvas_Move: layer = LayerUtils.UIMove; break; case EUICanvas.EUICanvas_Normal: layer = LayerUtils.UI; break; case EUICanvas.EUICanvas_Top: layer = LayerUtils.UITop; break; case EUICanvas.EUICanvas_Bottom: layer = LayerUtils.UIBottom; break; case EUICanvas.EUICanvas_WordMap: layer = LayerUtils.UIWorldMap; break; } Utility.GameUtility.ChangeChildLayer(transform, layer); }
public void RegisterUI(string uiPath, EUIType eType, bool useBack, EUICanvas canvas, bool isAutoReset, bool preLoad = false, object tempObj = null) { string luaFileName = System.IO.Path.GetFileName(uiPath); if (m_uiDic.ContainsKey(luaFileName)) { return; } GameObject obj = null; if (tempObj != null) { obj = tempObj as GameObject; } else { obj = Res.ResourcesManager.Instance.SyncGetResource <GameObject>(uiPath, Res.ResourceType.UI); } string name = obj.name.Replace("(Clone)", string.Empty); obj.name = name; UIBase uiBase = null; switch (luaFileName) { case EUIName.RegistUI: uiBase = obj.AddComponent <RegistUI>(); break; case EUIName.BattleUI: uiBase = obj.AddComponent <BattleUI>(); break; case EUIName.WallpaperUI: uiBase = obj.AddComponent <WallpaperUI>(); break; case EUIName.HomeUI: uiBase = obj.AddComponent <HomeUI>(); break; case EUIName.AccountUI: uiBase = obj.AddComponent <AccountUI>(); break; case EUIName.ResigsterSucceesUI: uiBase = obj.AddComponent <ResigsterSucceesUI>(); break; case EUIName.BattleCardShowUI: uiBase = obj.AddComponent <BattleCardShowUI>(); break; case EUIName.SearchEnemyUI: uiBase = obj.AddComponent <SearchEnemyUI>(); break; default: uiBase = obj.AddComponent <UIBase>(); break; } uiBase.eUIType = eType; uiBase.eUICanvas = canvas; uiBase.useBack = useBack; m_uiDic[luaFileName] = uiBase; RegisterUI(uiBase, canvas, isAutoReset); }
public Transform GetCanvasTransform(EUICanvas type) { return(GetCanvas(type).canvas.transform); }