예제 #1
0
        // <summary>
        /// 给目标添加Collider背景
        /// Add Collider Background for target
        /// </summary>
        public static GameObject AddColliderBgToTarget(GameObject target, string maskName, UIAtlas altas, bool isTransparent)
        {
            // 添加UIPaneldepth最小上面
            // 保证添加的Collider放置在屏幕中间
            Transform windowBg = GameUtility.FindDeepChild(target, "WindowBg");

            if (windowBg == null)
            {
                GameObject targetParent = GameUtility.GetPanelDepthMaxMin(target, false, true);
                if (targetParent == null)
                {
                    targetParent = target;
                }

                windowBg = (new GameObject("WindowBg")).transform;
                GameUtility.AddChildToTarget(targetParent.transform, windowBg);
            }

            Transform bg = GameUtility.FindDeepChild(target, "WindowColliderBg(Cool)");

            if (bg == null)
            {
                // 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(bg.gameObject);
        }