Example #1
0
        /// <summary>
        /// 显示遮罩
        /// </summary>
        /// <param name="bgColor"></param>
        /// <param name="keepTime"></param>
        public static void ShowMask(Color bgColor, int keepTime)
        {
            GameObject canvas = new GameObject("MaskCanvas");
            Canvas     _cavas = canvas.AddComponent <Canvas>();

            _cavas.renderMode   = RenderMode.ScreenSpaceOverlay;
            _cavas.sortingOrder = 10000;
            canvas.AddComponent <CanvasScaler>();
            canvas.AddComponent <DondestoryOnLoad>();
            GameObject mask = new GameObject("Mask");

            mask.transform.SetParent(canvas.transform);
            Image bgImage = mask.AddComponent <Image>();

            bgImage.color = bgColor;
            RectTransform rect = bgImage.GetComponent <RectTransform>();

            rect.sizeDelta = Vector2.zero;
            rect.anchorMin = Vector2.zero;
            rect.anchorMax = Vector2.one;
            RainierUlitity.SetAnchorOfCenter(rect, 0, 0);
            GameObject text  = new GameObject("Title");
            Text       title = text.AddComponent <Text>();

            title.font = Font.CreateDynamicFontFromOSFont("simhei", 15);
            title.text = "数据加载中...";
            text.transform.SetParent(rect);
            RainierUlitity.SetAnchorOfCenter(text.GetComponent <RectTransform>(), 0, 0);

            canvas.transform.SetAsLastSibling();
            Object.Destroy(canvas, keepTime);
        }
Example #2
0
        /// <summary>
        /// 显示遮罩(加载loading动画)
        /// </summary>
        /// <param name="bgColor"></param>
        /// <param name="keepTime"></param>
        /// <param name="typePrefabName"></param>
        public static void ShowMask(Color bgColor, MaskType type)
        {
            GameObject canvas = new GameObject("MaskCanvas");

            canvas.AddComponent <Canvas>().renderMode = RenderMode.ScreenSpaceOverlay;
            canvas.AddComponent <CanvasScaler>();
            canvas.AddComponent <DondestoryOnLoad>();
            GameObject mask = new GameObject("Mask");

            mask.transform.SetParent(canvas.transform);
            Image bgImage = mask.AddComponent <Image>();

            bgImage.color = bgColor;
            RectTransform rect = bgImage.GetComponent <RectTransform>();

            rect.sizeDelta = Vector2.zero;
            rect.anchorMin = Vector2.zero;
            rect.anchorMax = Vector2.one;
            RainierUlitity.SetAnchorOfCenter(rect, 0, 0);
            GameObject typePrefab = (GameObject)Resources.Load(maskDic[type]);

            GameObject typeMask = MonoBehaviour.Instantiate <GameObject>(typePrefab);

            typeMask.transform.SetParent(rect.transform);
            RainierUlitity.SetAnchorOfCenter(typeMask.GetComponent <RectTransform>(), 0, 0);
            _canvas = canvas;
        }