public override void InitWindowManager() { base.InitWindowManager(); InitWindowControl(); isNeedWaitHideOver = true; if (UIBackgroundLayerRoot == null) { GameObject BackgroundLayerRoot = new GameObject("UIBackgroundLayerRoot"); UIBackgroundLayerRoot = BackgroundLayerRoot.gameObject.AddComponent <RectTransform>(); UIBackgroundLayerRoot.anchorMax = new Vector2(1f, 1f); UIBackgroundLayerRoot.anchorMin = new Vector2(0f, 0f); UIBackgroundLayerRoot.offsetMax = new Vector2(0, 0); UIBackgroundLayerRoot.offsetMin = new Vector2(0, 0); UGUITools.AddChildToTarget(UIRoot, UIBackgroundLayerRoot); UGUITools.ChangeChildLayer(UIBackgroundLayerRoot, UIRoot.gameObject.layer); } if (UINormalLayerRoot == null) { GameObject NormalLayerRoot = new GameObject("UINormalWindowRoot"); UINormalLayerRoot = NormalLayerRoot.gameObject.AddComponent <RectTransform>(); UINormalLayerRoot.anchorMax = new Vector2(1f, 1f); UINormalLayerRoot.anchorMin = new Vector2(0f, 0f); UINormalLayerRoot.offsetMax = new Vector2(0, 0); UINormalLayerRoot.offsetMin = new Vector2(0, 0); UGUITools.AddChildToTarget(UIRoot, UINormalLayerRoot); UGUITools.ChangeChildLayer(UINormalLayerRoot, UIRoot.gameObject.layer); } if (UIForegroundLayerRoot == null) { GameObject ForegroundLayerRoot = new GameObject("UIForegroundLayerRoot"); UIForegroundLayerRoot = ForegroundLayerRoot.gameObject.AddComponent <RectTransform>(); UIForegroundLayerRoot.anchorMax = new Vector2(1f, 1f); UIForegroundLayerRoot.anchorMin = new Vector2(0f, 0f); UIForegroundLayerRoot.offsetMax = new Vector2(0, 0); UIForegroundLayerRoot.offsetMin = new Vector2(0, 0); UGUITools.AddChildToTarget(UIRoot, UIForegroundLayerRoot); UGUITools.ChangeChildLayer(UIForegroundLayerRoot, UIRoot.gameObject.layer); } }
// <summary> /// 给目标添加Collider背景 /// Add Collider Background for target /// </summary> public static GameObject AddColliderBgToTarget(GameObject target, string maskNames, bool isTransparent) { // 添加UIPaneldepth最小上面 // 保证添加的Collider放置在屏幕中间 Transform windowBg = UGUITools.FindDeepChild(target, "WindowBg"); if (windowBg == null) { //GameObject targetParent = GameUtility.GetPanelDepthMaxMin(target, false, true); //if (targetParent == null) // targetParent = target; GameObject temp = new GameObject("WindowBg"); UGUITools.AddChildToTarget(target.transform, temp.transform); RectTransform rt = temp.AddComponent <RectTransform>(); rt.offsetMax = Vector2.zero; rt.offsetMin = Vector2.zero; rt.anchorMax = Vector2.one; rt.anchorMin = Vector2.zero; windowBg = rt.transform; windowBg.SetAsFirstSibling(); } Transform Masker = UGUITools.FindDeepChild(target, "WindowColliderBg(Cool)"); if (Masker == null) { Transform root = UICenterMasterManager.Instance.GetTargetRoot(UIWindowType.ForegroundLayer); GameObject res = Resources.Load("UIPrefab/Mask/" + maskNames) as GameObject; Masker = UGUITools.AddChild(root.gameObject, res).transform; Masker.name = "WindowColliderBg(Cool)"; SetRectTransformOffset(Masker.gameObject, Vector2.zero, Vector2.zero); res = null; UGUITools.AddChildToTarget(windowBg, Masker.transform); if (isTransparent) { Masker.GetComponent <UnityEngine.UI.Image>().color = new Color(1, 1, 1, 0.1f); } else { Masker.GetComponent <UnityEngine.UI.Image>().color = new Color(1, 1, 1, 0.5f); } // add sprite or widget to ColliderBg //UIWidget widget = null; //if (!isTransparent) // widget = NGUITools.AddSprite(windowBg.gameObject, altas, maskName); //else // widget = NGUITools.AddWidget<UIWidget>(windowBg.gameObject); //widget.name = "WindowColliderBg(Cool)"; //bg = widget.transform; //// fill the screen //// You can use the new Anchor system //UIStretch stretch = bg.gameObject.AddComponent<UIStretch>(); //stretch.style = UIStretch.Style.Both; //// set relative size bigger //stretch.relativeSize = new Vector2(1.5f, 1.5f); //// set a lower depth //widget.depth = -5; //// set alpha //widget.alpha = 0.6f; //// add collider //NGUITools.AddWidgetCollider(bg.gameObject); } return(Masker.gameObject); }