Пример #1
0
        public static CTabBar CreateTabBar(int x, int y, Transform parent, string[] items, int itemW, int itemH, int depth, int offsetX = 0)
        {
            GameObject obj = UnityEngine.Object.Instantiate(FuncUtil.GetUIAssetByPath(TABBAR_PATH)) as GameObject;

            if (obj == null)
            {
                return(null);
            }
            obj.transform.parent        = parent;
            obj.transform.localScale    = Vector3.one;
            obj.transform.localPosition = new Vector3(x, y, 0);
            CTabBar box         = obj.GetComponent <CTabBar>();
            var     defaultItem = DisplayUtil.GetChildByName(obj.transform, "Tab0");

            if (defaultItem != null)
            {
                GameObject.DestroyImmediate(defaultItem.gameObject);
            }
            box.RemoveItems();
            for (var i = 0; i < items.Length; i++)
            {
                var btn = CreateTabBarBtn(i * itemW + offsetX, 0, obj.transform, items[i], itemW, itemH, depth);
                btn.name = "Tab" + i;
            }
            box.Start();
            return(box);
        }
Пример #2
0
        public static UILabel CreateLabel(string text, int x, int y, int w, int h, Transform parent, Color color, int size = 12, FontStyle style = FontStyle.Bold, NGUIText.Alignment align = NGUIText.Alignment.Left, int depth = LABEL_DEFAULT_DEPTH, UIWidget.Pivot pivot = UIWidget.Pivot.TopLeft, int zRotate = 0)
        {
            GameObject obj = UnityEngine.Object.Instantiate(FuncUtil.GetUIAssetByPath(LABEL_URL)) as GameObject;

            if (obj == null)
            {
                return(null);
            }
            UILabel label = obj.GetComponent <UILabel>();

            label.text      = text ?? "";
            label.width     = w;
            label.height    = h;
            label.fontSize  = size;
            label.fontStyle = style;
            label.pivot     = pivot;
            label.alignment = align;
            if (color == Color.black)
            {
                color = new Color(0, 1, 1);
            }
            label.color                 = color;
            label.depth                 = depth;
            obj.transform.parent        = parent;
            obj.transform.localScale    = Vector3.one * size / 20.0f;
            obj.transform.localPosition = new Vector3(x, y, 0);
            obj.transform.localRotation = Quaternion.Euler(new Vector3(0, 0, zRotate));
            return(label);
        }
Пример #3
0
 private void OnLoadTextureComplete(string url)
 {
     //如果是默认图  并且实际上用的图已经加载好
     if (url == defaultUrl && (curTexture != null || string.IsNullOrEmpty(_url)))
     {
         return;
     }
     //不是当前需求要的图
     if (url != defaultUrl && url != _url)
     {
         return;
     }
     isClear = false;
     try {
         curTexture = FuncUtil.GetUIAssetByPath(url) as Texture2D;
     } catch (Exception e) {
         FuncUtil.ShowError("Image加载完毕后获取Texture2D失败:{0}", e.Message);
         return;
     }
     if (curTexture == null)
     {
         Clear();
         FuncUtil.ShowError("Image加载完毕后获取Texture2D失败:{0}", url);
     }
     FuncUtil.NoDispose(_url);
     UpdateBaseTexture();
     if (_imageWidth != 0 && _imageHeight != 0)
     {
         width  = Convert.ToInt32(_imageWidth);
         height = Convert.ToInt32(_imageHeight);
     }
     OnCompleteCallBack();
 }
Пример #4
0
        public static CButton CreateImgButton(string path, string text, int depth, int x, int y, Transform parent, int w = 0, int h = 0, UIEventListener.VoidDelegate OnClick = null, string name = "Button", string toolTip = null)
        {
            GameObject obj = UnityEngine.Object.Instantiate(FuncUtil.GetUIAssetByPath(path)) as GameObject;

            if (obj == null)
            {
                return(null);
            }
            obj.name                    = name;
            obj.transform.parent        = parent;
            obj.transform.localScale    = Vector3.one;
            obj.transform.localPosition = new Vector3(x, y, 0);
            CButton  btn = obj.GetComponent <CButton>();
            UISprite sp  = btn.GetComponent <UISprite>();

            sp.depth = depth;
            if (w > 0 || h > 0)
            {
                sp.width  = w;
                sp.height = h;
            }
            if (toolTip != null)
            {
                btn.AddToolTip(toolTip);
            }
            if (OnClick != null)
            {
                UIEventListener.Get(obj).onClick = OnClick;
            }
            return(btn);
        }
Пример #5
0
        public static UISprite CreateSprite(string name, UIAtlas atlas, string spriteName, int x, int y, Transform parent = null, int width = 0, int height = 0, int depth = 8, UIWidget.Pivot pivot = UIWidget.Pivot.TopLeft)
        {
            if (FuncUtil.GetUIAssetByPath(SPRITE_PAHT) == null)
            {
                return(null);
            }
            GameObject obj = UnityEngine.Object.Instantiate(FuncUtil.GetUIAssetByPath(SPRITE_PAHT)) as GameObject;

            if (obj == null)
            {
                return(null);
            }
            obj.transform.parent = parent;
            UISprite     sprite = obj.GetComponent <UISprite>();
            UISpriteData spData = (atlas != null) ? atlas.GetSprite(spriteName) : null;

            sprite.type                 = (spData == null || !spData.hasBorder) ? UISprite.Type.Simple : UISprite.Type.Sliced;
            sprite.atlas                = atlas;
            sprite.spriteName           = spriteName;
            sprite.pivot                = pivot;
            obj.transform.localScale    = Vector3.one;
            obj.transform.localPosition = new Vector3(x, y, 0);
            if (width == 0 || height == 0)
            {
                sprite.MakePixelPerfect();
            }
            else
            {
                sprite.width  = width;
                sprite.height = height;
            }
            sprite.depth = depth;
            return(sprite);
        }
Пример #6
0
        public static CCheckBox CreateCheckBox(string name, int x, int y, Transform parent, int width = 0, int height = 0)
        {
            GameObject obj = UnityEngine.Object.Instantiate(FuncUtil.GetUIAssetByPath(CHECKBOX_PATH)) as GameObject;

            if (obj == null)
            {
                return(null);
            }
            obj.transform.parent        = parent;
            obj.transform.localScale    = Vector3.one;
            obj.transform.localPosition = new Vector3(x, y, 0);
            CCheckBox asset = obj.GetComponent <CCheckBox>();

            asset.Selected = false;
            if (width > 0)
            {
                asset.Label.width = width;
            }
            if (height > 0)
            {
                asset.Label.height = height;
            }
            asset.Text = name;
            return(asset);
        }
Пример #7
0
        public static UISprite CreateSprite(string atlasPath, string spriteName, int x, int y, Transform parent = null, int width = 0, int height = 0, int depth = 0)
        {
            if (FuncUtil.GetUIAssetByPath(SPRITE_PAHT) == null)
            {
                return(null);
            }
            GameObject obj = UnityEngine.Object.Instantiate(FuncUtil.GetUIAssetByPath(SPRITE_PAHT)) as GameObject;

            if (obj == null)
            {
                return(null);
            }
            obj.transform.parent = parent;
            UISprite sp = obj.GetComponent <UISprite>();

            sp.transform.localPosition = new Vector3(x, y, 0);
            sp.transform.localScale    = Vector3.one;
            if (width == 0 || height == 0)
            {
                sp.MakePixelPerfect();
            }
            else
            {
                sp.width  = width;
                sp.height = height;
            }
            object  atlasObj = FuncUtil.GetUIAssetByPath(atlasPath, typeof(UIAtlas));
            UIAtlas atlas    = (atlasObj is GameObject) ? (atlasObj as GameObject).GetComponent <UIAtlas>() : atlasObj as UIAtlas;

            sp.atlas      = atlas;
            sp.spriteName = spriteName;
            sp.depth      = depth;
            return(sp);
        }
Пример #8
0
        //渐变的label
        public static UILabel CreateGradLabel(string text, int x, int y, int w, int h, Transform parent, Color color, Color topColor, Color bottomColor, Color effectColor, int size = 12, FontStyle style = FontStyle.Bold, NGUIText.Alignment align = NGUIText.Alignment.Left, int depth = 13, UIWidget.Pivot pivot = UIWidget.Pivot.TopLeft)
        {
            GameObject obj = UnityEngine.Object.Instantiate(FuncUtil.GetUIAssetByPath(LABEL_URL)) as GameObject;

            if (obj == null)
            {
                return(null);
            }
            UILabel label = obj.GetComponent <UILabel>();

            label.text           = text ?? "";
            label.width          = w;
            label.height         = h;
            label.fontSize       = size;
            label.fontStyle      = style;
            label.pivot          = pivot;
            label.alignment      = align;
            label.applyGradient  = true;
            label.gradientTop    = topColor;
            label.gradientBottom = bottomColor;
            label.effectColor    = effectColor;
            label.effectStyle    = UILabel.Effect.Outline;
            if (color == Color.black)
            {
                color = new Color(0, 1, 1);
            }
            label.color                 = color;
            label.depth                 = depth;
            obj.transform.parent        = parent;
            obj.transform.localScale    = Vector3.one * size / 20.0f;
            obj.transform.localPosition = new Vector3(x, y, 0);
            return(label);
        }
Пример #9
0
        private void OnLoadMaskCullingComplete(string url)
        {
            var ttCulling = FuncUtil.GetUIAssetByPath(url) as Texture2D;

            if (material != null)
            {
                material.SetTexture("_Mask", ttCulling);
            }
            UpdateBaseTexture();
        }
Пример #10
0
        public static UIWidget CreateWidget()
        {
            GameObject obj = UnityEngine.Object.Instantiate(FuncUtil.GetUIAssetByPath(WIDGET_PAHT)) as GameObject;

            if (obj == null)
            {
                return(null);
            }
            obj.transform.localScale    = Vector3.one;
            obj.transform.localPosition = Vector3.zero;
            UIWidget asset = obj.GetComponent <UIWidget>();

            return(asset);
        }
Пример #11
0
        public static CCombobox CreateCombobox(string name, int x, int y, Transform parent, int w, int h, int depth)
        {
            GameObject obj = UnityEngine.Object.Instantiate(FuncUtil.GetUIAssetByPath(COMBOBOX_PATH)) as GameObject;

            if (obj == null)
            {
                return(null);
            }
            obj.transform.parent        = parent;
            obj.transform.localScale    = Vector3.one;
            obj.transform.localPosition = new Vector3(x, y, 0);
            CCombobox box = obj.GetComponent <CCombobox>();

            return(box);
        }
Пример #12
0
        public static Image CreateImage(int x, int y, Transform parent)
        {
            GameObject obj = UnityEngine.Object.Instantiate(FuncUtil.GetUIAssetByPath(IMAGE_PATH)) as GameObject;

            if (obj == null)
            {
                return(null);
            }
            obj.transform.parent        = parent;
            obj.transform.localScale    = Vector3.one;
            obj.transform.localPosition = new Vector3(x, y, 0);
            Image asset = obj.GetComponent <Image>();

            return(asset);
        }
Пример #13
0
        public static CNumStepper CreateNumStepper2(int x, int y, Transform parent)
        {
            GameObject obj = UnityEngine.Object.Instantiate(FuncUtil.GetUIAssetByPath(NUMBER_STEPER_2)) as GameObject;

            if (obj == null)
            {
                return(null);
            }
            obj.transform.parent        = parent;
            obj.transform.localScale    = Vector3.one;
            obj.transform.localPosition = new Vector3(x, y, 0);
            CNumStepper step = obj.GetComponent <CNumStepper>();

            return(step);
        }
Пример #14
0
        //public static CTileList CreateTileList(string name, int x, int y, Transform parent, int w, int h, int depth){
        //    GameObject obj = UnityEngine.Object.Instantiate(FuncUtil.GetUIAssetByPath(TILELIST_PATH)) as GameObject;
        //    if (obj == null) return null;
        //    obj.transform.parent = parent;
        //    obj.transform.localScale = Vector3.one;
        //    obj.transform.localPosition = new Vector3(x, y, 0);
        //    CTileList list = obj.GetComponent<CTileList>();
        //    return list;
        //}

        public static CMissionList CreateMissionList(string name, int x, int y, Transform parent, int w, int h, int depth)
        {
            GameObject obj = UnityEngine.Object.Instantiate(FuncUtil.GetUIAssetByPath(MISSION_LIST_PATH)) as GameObject;

            if (obj == null)
            {
                return(null);
            }
            obj.transform.parent        = parent;
            obj.transform.localScale    = Vector3.one;
            obj.transform.localPosition = new Vector3(x, y, 0);
            CMissionList list = obj.GetComponent <CMissionList>();

            return(list);
        }
Пример #15
0
        public static UISprite CreateMask(int x, int y, Transform parent = null, int width = 0, int height = 0, int depth = 0)
        {
            GameObject obj = UnityEngine.Object.Instantiate(FuncUtil.GetUIAssetByPath(UI_MASK_PATH)) as GameObject;

            obj.transform.parent = parent;
            UIPanel panel = obj.GetComponent <UIPanel>();

            panel.depth = depth;
            UISprite sprite = obj.GetComponentInChildren <UISprite>();

            sprite.width  = width;
            sprite.height = height;
            sprite.transform.localPosition = new Vector3(x, y, 0);
            sprite.transform.localScale    = Vector3.one;
            return(sprite);
        }
Пример #16
0
        public static CPageBar CreatePageBar(int x, int y, Transform parent, int min, int max, int depth)
        {
            GameObject obj = UnityEngine.Object.Instantiate(FuncUtil.GetUIAssetByPath(PAGEBAR)) as GameObject;

            if (obj == null)
            {
                return(null);
            }
            obj.transform.parent        = parent;
            obj.transform.localScale    = Vector3.one;
            obj.transform.localPosition = new Vector3(x, y, 0);
            CPageBar bar = obj.GetComponent <CPageBar>();

            bar.Min   = min;
            bar.Max   = max;
            bar.depth = depth;
            return(bar);
        }
Пример #17
0
        public static CButtonToggle CreateTabBarBtn(int x, int y, Transform parent, string name, int w, int h, int depth)
        {
            GameObject obj = UnityEngine.Object.Instantiate(FuncUtil.GetUIAssetByPath(TAB_BUTTON_PATH)) as GameObject;

            if (obj == null)
            {
                return(null);
            }
            obj.transform.parent        = parent;
            obj.transform.localScale    = Vector3.one;
            obj.transform.localPosition = new Vector3(x, y, 0);
            CButtonToggle box = obj.GetComponent <CButtonToggle>();

            box.width  = w;
            box.height = h;
            box.Text   = name;
            return(box);
        }
Пример #18
0
        public static CButton CreateButton(string text, int depth, int x, int y, Transform parent, int w = 0, int h = 0, UIEventListener.VoidDelegate OnClick = null, string name = "Button", string toolTip = null)
        {
            GameObject obj = UnityEngine.Object.Instantiate(FuncUtil.GetUIAssetByPath(BUTTON_URL)) as GameObject;

            if (obj == null)
            {
                return(null);
            }
            obj.name                    = name;
            obj.transform.parent        = parent;
            obj.transform.localScale    = Vector3.one;
            obj.transform.localPosition = new Vector3(x, y, 0);
            CButton btn = obj.GetComponent <CButton>();

            btn.Text = text ?? "";
            UISprite sp = btn.GetComponent <UISprite>();

            btn.Label.SetAnchor(btn.transform);
            btn.Label.leftAnchor.Set(0, -38);
            btn.Label.rightAnchor.Set(1, 38);
            btn.Label.topAnchor.Set(1, 32);
            btn.Label.bottomAnchor.Set(0, -40);
            sp.depth = depth;
            if (w > 0 || h > 0)
            {
                sp.width  = w;
                sp.height = h;
            }
            if (toolTip != null)
            {
                btn.AddToolTip(toolTip);
            }
            btn.Label.depth = 200; //整个界面的文字基本不会重叠,搞成同一层避免隔开具有相同图集的其他组件的深度
            if (OnClick != null)
            {
                //UIEventListener.Get(obj).onClick = OnClick;
                btn.AddClick(OnClick);
            }
            return(btn);
        }
Пример #19
0
        public static CProgressBar CreateProgressBar(string name, int x, int y, Transform parent, int w, int h, int depth)
        {
            GameObject obj = UnityEngine.Object.Instantiate(FuncUtil.GetUIAssetByPath(PROGRESSBAR_PATH)) as GameObject;

            if (obj == null)
            {
                return(null);
            }
            obj.transform.parent        = parent;
            obj.transform.localScale    = Vector3.one;
            obj.transform.localPosition = new Vector3(x, y, 0);
            CProgressBar bar    = obj.GetComponent <CProgressBar>();
            UISprite     sprite = bar.GetComponent <UISprite>();

            sprite.width  = w;
            sprite.height = h;
            sprite.depth  = depth;
            UISprite overlay = bar.transform.Find("Overlay").GetComponent <UISprite>();

            overlay.depth = depth + 1;
            return(bar);
        }
Пример #20
0
 virtual public void SetObjByURL(string url)
 {
     SetObjAndInstantiate(FuncUtil.GetUIAssetByPath(url) as GameObject);
 }
Пример #21
0
 private void OnLoadMaskComplete(string path)
 {
     material       = new Material(FuncUtil.GetUIAssetByPath(path) as Material);
     material.color = color;
     FuncUtil.Load(_maskPath + "", (Action <string>)OnLoadMaskCullingComplete, _maskPath);
 }
Пример #22
0
        public static GameObject CreateUIRoot()
        {
            GameObject obj = UnityEngine.Object.Instantiate(FuncUtil.GetUIAssetByPath(UI_ROOT)) as GameObject;

            return(obj);
        }