Пример #1
0
        /// <summary>
        /// 得到CanvasGroup
        /// </summary>
        /// <param name="panel"></param>
        /// <returns></returns>
        private static CanvasGroup GetCanvasGroup(UIPanelBase panel)
        {
            var cg = panel.GetComponent <CanvasGroup>();

            if (!cg)
            {
                cg = panel.gameObject.AddComponent <CanvasGroup>();
            }
            return(cg);
        }
Пример #2
0
    /// <summary>
    /// 给目标添加Collider背景
    /// </summary>
    public void AddColliderBgToTarget(UIPanelBase target, string maskName, bool isTransparent)
    {
        // 保证添加的Collider放置在屏幕中间
        Transform mask = target.transform.Find("ColliderMask");

        if (mask == null)
        {
            mask = (new GameObject("ColliderMask")).transform;
            Util.AddChildToTarget(target.transform, mask);
        }

        Transform maskBtn = mask.Find("ColliderMaskBtn");

        if (maskBtn == null)
        {
            UIWidget widget = null;
            widget        = NGUITools.AddWidget <UIWidget>(mask.gameObject);
            widget.width  = (int)UIRootHelper.Instance.TargetFillSize.x;
            widget.height = (int)UIRootHelper.Instance.TargetFillSize.y;
            widget.gameObject.AddComponent <UIButton>();
            NGUITools.AddWidgetCollider(widget.gameObject);
            widget.name  = "ColliderMaskBtn";
            widget.depth = -5;
            maskBtn      = widget.transform;
            NGUITools.AddWidgetCollider(maskBtn.gameObject);
            UIEventListener.Get(maskBtn.gameObject).onClick += delegate
            {
                UIPanelBase targetPanelBase = target.GetComponent <UIPanelBase>();
                if (null != targetPanelBase)
                {
                    targetPanelBase.OnColliderMaskClicked();
                }
            };
        }
        //非透明,添加半透明背景
        if (!isTransparent &&
            (!IsShowPanel(PanelID.CommonBgPanel) || target.PanelType != PanelType.Normal))
        {
            Transform maskBg = mask.Find("ColliderMaskBg");
            if (null == maskBg)
            {
                UISprite sp = NGUITools.AddSprite(mask.gameObject, null, maskName);
                sp.width  = (int)UIRootHelper.Instance.TargetFillSize.x;
                sp.height = (int)UIRootHelper.Instance.TargetFillSize.y;
                sp.alpha  = 0.5f;
                sp.depth  = -6;
                sp.type   = UIBasicSprite.Type.Sliced;
                maskBg    = sp.transform;
                maskBg.gameObject.name = "ColliderMaskBg";

                CMResAsynSeedData <CMAtlas> cASD = null;
                UIManager.GetAtlasAsyn(maskName, ref cASD, () =>
                {
                    if (null != sp)
                    {
                        sp.atlas = null;
                    }
                }, sp, false);
            }
        }
    }