Exemplo n.º 1
0
        protected override void ChargeWidgetInfo(Component component, WidgetItem info)
        {
            var bar = component as Scrollbar;

            var dic = info.spriteDic;

            if (dic.ContainsKey(KeyWord.background))
            {
                var image = bar.GetComponent <Image>();
                image.sprite = dic[KeyWord.background];
                image.type   = Image.Type.Simple;
                if (image.sprite.rect.width > image.sprite.rect.height)
                {
                    bar.SetDirection(Scrollbar.Direction.LeftToRight, true);
                }
                else
                {
                    bar.SetDirection(Scrollbar.Direction.BottomToTop, true);
                }
                WidgetUtility.SetNativeSize(image);
            }

            if (dic.ContainsKey(KeyWord.handle))
            {
                bar.handleRect.GetComponent <Image>().sprite = dic[KeyWord.handle];
            }
        }
Exemplo n.º 2
0
        public override GameObject CreateInstence(WidgetItem info)
        {
            var ok = EditorApplication.ExecuteMenuItem("GameObject/UI/Toggle");

            if (ok)
            {
                var created    = Selection.activeGameObject;
                var spriteDic  = info.spriteDic;
                var toggle     = created.GetComponent <Toggle>();
                var background = toggle.targetGraphic as Image;
                var mask       = toggle.graphic as Image;
                if (spriteDic.ContainsKey(KeyWord.background))
                {
                    background.sprite = spriteDic[KeyWord.background];
                    background.type   = Image.Type.Simple;
                    background.SetNativeSize();
                }
                if (spriteDic.ContainsKey(KeyWord.mask))
                {
                    mask.sprite     = spriteDic[KeyWord.mask];
                    background.type = Image.Type.Simple;
                    background.SetNativeSize();
                }

                var text = toggle.GetComponentInChildren <Text>();
                text.text = info.name;
                return(created);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 从json文件中加载出配制
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public static WidgetItem[] LoadWidgeItems(string json, string assetDir)
        {
            if (string.IsNullOrEmpty(json))
            {
                return(null);
            }

            var items = new List <WidgetItem>();

            var jsonarray = JSONNode.Parse(json).AsArray;

            foreach (var nodeItem in jsonarray)
            {
                var jsonClass = nodeItem as JSONClass;
                if (nodeItem != null && jsonClass != null)
                {
                    var item = new WidgetItem();
                    item.type      = (WidgetType)Enum.Parse(typeof(WidgetType), jsonClass[KeyWord.type].Value);
                    item.name      = jsonClass[KeyWord.name].Value;
                    item.spriteDic = LoadTextures(jsonClass, assetDir);
                    items.Add(item);
                }
            }
            return(items.ToArray());
        }
Exemplo n.º 4
0
        public override GameObject CreateInstence(WidgetItem info)
        {
            var ok = EditorApplication.ExecuteMenuItem("GameObject/UI/Scrollbar");

            if (ok)
            {
                var obj = Selection.activeGameObject;
                var bar = obj.GetComponent <Scrollbar>();
                var dic = info.spriteDic;

                if (dic.ContainsKey(KeyWord.background))
                {
                    var image = bar.GetComponent <Image>();
                    image.sprite = dic[KeyWord.background];
                    image.type   = Image.Type.Simple;
                    if (image.sprite.rect.width > image.sprite.rect.height)
                    {
                        bar.SetDirection(Scrollbar.Direction.LeftToRight, true);
                    }
                    else
                    {
                        bar.SetDirection(Scrollbar.Direction.BottomToTop, true);
                    }
                    image.SetNativeSize();
                }

                if (dic.ContainsKey(KeyWord.handle))
                {
                    bar.handleRect.GetComponent <Image>().sprite = dic[KeyWord.handle];
                }

                return(obj);
            }
            return(null);
        }
        protected override void ChargeWidgetInfo(Component component, WidgetItem info)
        {
            Dropdown dropdown = component as Dropdown;
            var      dic      = info.spriteDic;

            if (dic.ContainsKey(backgroundbase))
            {
                WidgetUtility.InitImage(dropdown.targetGraphic as Image, dic[backgroundbase], Image.Type.Sliced);
            }

            if (dic.ContainsKey(backgroundgroup))
            {
                dropdown.template.GetComponent <Image>().sprite = dic[backgroundgroup];
            }

            if (dic.ContainsKey(backgrounditem))
            {
                var itemgraph = dropdown.template.GetComponentInChildren <Toggle>().targetGraphic as Image;
                itemgraph.sprite = dic[backgrounditem];
            }

            var scrollbar = dropdown.template.GetComponentInChildren <Scrollbar>();

            if (dic.ContainsKey(scrollbarbackground))
            {
                (scrollbar.targetGraphic as Image).sprite = dic[scrollbarbackground];
            }
            if (dic.ContainsKey(scrollbarfill))
            {
                scrollbar.handleRect.GetComponent <Image>().sprite = dic[scrollbarfill];
            }
        }
Exemplo n.º 6
0
        public static Texture CreatePreview(WidgetType type, WidgetItem info)
        {
            var creater = GetCreater(type);
            var list    = creater.GetPreviewList(info);

            return(GetPreviewFromSpriteList(list));
        }
        public override GameObject CreateOrCharge(WidgetItem info)
        {
            var oldBtn = Selection.activeTransform == null ? null : Selection.activeTransform.GetComponent(CommponentType);

            if (oldBtn != null)
            {
                Undo.RecordObject(oldBtn, "charge:" + oldBtn.name);
                ChargeWidgetInfo(oldBtn, info);
                return(oldBtn.gameObject);
            }
            else
            {
                var instence = CreateInstence(info);
                if (instence)
                {
                    instence.name = info.name;
                    Undo.RecordObject(instence, "charge:" + instence.name);
                    ChargeWidgetInfo(instence, info);
                    instence.transform.SetParent(Selection.activeTransform, false);
                    instence.transform.localPosition = Vector3.zero;
                    return(instence.gameObject);
                }
            }

            return(null);
        }
Exemplo n.º 8
0
        public override GameObject CreateInstence(WidgetItem info)
        {
            var ok = EditorApplication.ExecuteMenuItem("GameObject/UI/Image");

            if (ok)
            {
                var backgroundImage = Selection.activeGameObject;
                if (info.spriteDic.ContainsKey(KeyWord.background))
                {
                    WidgetUtility.InitImage(backgroundImage.GetComponent <Image>(), info.spriteDic[KeyWord.background]);
                }
                ok = EditorApplication.ExecuteMenuItem("GameObject/UI/Image");
                if (ok)
                {
                    var fillImage = Selection.activeGameObject.GetComponent <Image>();
                    fillImage.name = KeyWord.fill;

                    fillImage.type       = Image.Type.Filled;
                    fillImage.fillMethod = Image.FillMethod.Radial360;
                    if (info.spriteDic.ContainsKey(KeyWord.fill))
                    {
                        fillImage.sprite = info.spriteDic[KeyWord.fill];
                    }

                    fillImage.transform.SetParent(backgroundImage.transform, false);
                    (fillImage.transform as RectTransform).anchorMin = Vector2.zero;
                    (fillImage.transform as RectTransform).anchorMax = Vector2.one;
                    fillImage.transform.localPosition = Vector3.zero;
                    (fillImage.transform as RectTransform).SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, (backgroundImage.transform as RectTransform).sizeDelta.x);
                    (fillImage.transform as RectTransform).SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, (backgroundImage.transform as RectTransform).sizeDelta.y);
                }
                return(backgroundImage);
            }
            return(null);
        }
        protected override void ChargeWidgetInfo(Component component, WidgetItem info)
        {
            var image = component as RawImage;

            if (info.spriteDic.ContainsKey(KeyWord.sprite))
            {
                WidgetUtility.InitRawImage(image, info.spriteDic[KeyWord.sprite].texture);
            }
        }
Exemplo n.º 10
0
        protected override void ChargeWidgetInfo(Component component, WidgetItem info)
        {
            var image = component as Image;

            if (info.spriteDic.ContainsKey(KeyWord.sprite))
            {
                WidgetUtility.InitImage(image, info.spriteDic[KeyWord.sprite], Image.Type.Simple);
            }
        }
Exemplo n.º 11
0
        protected override void ChargeWidgetInfo(Component component, WidgetItem info)
        {
            var inputfield = component as  InputField;

            if (info.spriteDic.ContainsKey(KeyWord.background))
            {
                var image = inputfield.targetGraphic as Image;
                WidgetUtility.InitImage(image, info.spriteDic[KeyWord.background]);
            }
        }
Exemplo n.º 12
0
        public override List <Sprite> GetPreviewList(WidgetItem info)
        {
            var list = new List <Sprite>();

            if (info.spriteDic.ContainsKey(backgroundbase))
            {
                list.Add(info.spriteDic[backgroundbase]);
            }
            return(list);
        }
        protected override Component CreateInstence(WidgetItem info)
        {
            var component = base.CreateInstence(info);

            if (component != null)
            {
                component.GetComponentInChildren <Text>().text = "";
            }
            return(component);
        }
Exemplo n.º 14
0
        public override GameObject CreateInstence(WidgetItem info)
        {
            var ok = EditorApplication.ExecuteMenuItem("GameObject/UI/Button");

            if (ok)
            {
                var created   = Selection.activeGameObject;
                var spriteDic = info.spriteDic;
                var btn       = created.GetComponent <Button>();

                if (spriteDic.ContainsKey(KeyWord.normal))
                {
                    var texture = spriteDic[KeyWord.normal];

                    var image = btn.targetGraphic as Image;
                    image.sprite = texture;
                    image.type   = Image.Type.Simple;
                    image.SetNativeSize();

                    var text = btn.GetComponentInChildren <Text>();
                    text.text = info.name;
                }

                foreach (var item in spriteDic)
                {
                    if (item.Key == KeyWord.normal)
                    {
                        continue;
                    }
                    btn.transition = Selectable.Transition.SpriteSwap;
                    var keyword = item.Key;
                    var sprite  = item.Value;
                    var state   = btn.spriteState;
                    if (keyword == KeyWord.disabled)
                    {
                        state.disabledSprite = sprite;
                    }
                    else if (keyword == KeyWord.highlighted)
                    {
                        state.highlightedSprite = sprite;
                    }
                    else if (keyword == KeyWord.pressed)
                    {
                        state.pressedSprite = sprite;
                    }
                    btn.spriteState = state;
                }

                return(created);
            }
            else
            {
                return(null);
            }
        }
        public override List <Sprite> GetPreviewList(WidgetItem info)
        {
            List <Sprite> list      = new List <Sprite>();
            var           spriteDic = info.spriteDic;

            if (spriteDic.ContainsKey(KeyWord.background))
            {
                var sprite = spriteDic[KeyWord.background];
                list.Add(sprite);
            }
            return(list);
        }
        protected virtual Component CreateInstence(WidgetItem info)
        {
            var ok = EditorApplication.ExecuteMenuItem(MenuPath);

            if (ok)
            {
                var created = Selection.activeGameObject;
                var btn     = created.GetComponent(CommponentType);
                return(btn);
            }
            return(null);
        }
        public override List <Sprite> GetPreviewList(WidgetItem info)
        {
            List <Sprite> List      = new List <Sprite>();
            var           spriteDic = info.spriteDic;

            if (spriteDic.ContainsKey(KeyWord.normal))
            {
                var sprite = spriteDic[KeyWord.normal];
                List.Add(sprite);
            }
            return(List);
        }
Exemplo n.º 18
0
        public override List <Sprite> GetPreviewList(WidgetItem info)
        {
            var list = new List <Sprite>();

            if (info.spriteDic.ContainsKey(KeyWord.fill))
            {
                list.Add(info.spriteDic[KeyWord.fill]);
            }
            else if (info.spriteDic.ContainsKey(KeyWord.background))
            {
                list.Add(info.spriteDic[KeyWord.background]);
            }
            return(list);
        }
        public override List <Sprite> GetPreviewList(WidgetItem info)
        {
            List <Sprite> list = new List <Sprite>();

            if (info.spriteDic.ContainsKey(KeyWord.sprite))
            {
                var sprite = info.spriteDic[KeyWord.sprite];
                if (sprite != null)
                {
                    list.Add(sprite);
                }
            }
            return(list);
        }
Exemplo n.º 20
0
        public override GameObject CreateInstence(WidgetItem info)
        {
            var ok = EditorApplication.ExecuteMenuItem("GameObject/UI/Image");

            if (ok)
            {
                var created = Selection.activeGameObject;
                var image   = Selection.activeGameObject.GetComponent <Image>();
                if (info.spriteDic.ContainsKey(KeyWord.sprite))
                {
                    WidgetUtility.InitImage(image, info.spriteDic[KeyWord.sprite], Image.Type.Simple);
                }
                return(created);
            }
            return(null);
        }
Exemplo n.º 21
0
        public override GameObject CreateInstence(WidgetItem info)
        {
            var ok = EditorApplication.ExecuteMenuItem("GameObject/UI/Input Field");

            if (ok)
            {
                var inputfield = Selection.activeGameObject.GetComponent <InputField>();
                if (info.spriteDic.ContainsKey(KeyWord.background))
                {
                    var image = inputfield.targetGraphic as Image;
                    WidgetUtility.InitImage(image, info.spriteDic[KeyWord.background]);
                }

                return(inputfield.gameObject);
            }
            return(null);
        }
Exemplo n.º 22
0
        public GameObject CreateInstence()
        {
            var lastTrans = Selection.activeTransform;

            if (lastTrans == null || !(lastTrans is RectTransform))
            {
                var canvas = GameObject.FindObjectOfType <Canvas>();
                if (canvas == null)
                {
                    EditorApplication.ExecuteMenuItem("GameObject/UI/Canvas");
                }
            }

            var info    = new WidgetItem(name, spriteDic);
            var created = WidgetUtility.CreateOrCharge(widgetType, info);

            return(created);
        }
Exemplo n.º 23
0
        public override List <Sprite> GetPreviewList(WidgetItem info)
        {
            var list = new List <Sprite>();
            var dic  = info.spriteDic;

            if (dic != null)
            {
                if (dic.ContainsKey(KeyWord.background))
                {
                    list.Add(dic[KeyWord.background]);
                }

                else if (dic.ContainsKey(KeyWord.handle))
                {
                    list.Add(dic[KeyWord.handle]);
                }
            }
            return(list);
        }
        protected override void ChargeWidgetInfo(Component component, WidgetItem info)
        {
            var spriteDic  = info.spriteDic;
            var toggle     = component as Toggle;
            var background = toggle.targetGraphic as Image;
            var mask       = toggle.graphic as Image;

            if (spriteDic.ContainsKey(KeyWord.background))
            {
                background.sprite = spriteDic[KeyWord.background];
                background.type   = Image.Type.Simple;
                WidgetUtility.SetNativeSize(background);
            }
            if (spriteDic.ContainsKey(KeyWord.mask))
            {
                mask.sprite     = spriteDic[KeyWord.mask];
                background.type = Image.Type.Simple;
                WidgetUtility.SetNativeSize(background);
            }
        }
Exemplo n.º 25
0
        public override GameObject CreateInstence(WidgetItem info)
        {
            var ok = EditorApplication.ExecuteMenuItem("GameObject/UI/Slider");

            if (ok)
            {
                var obj    = Selection.activeGameObject;
                var slider = obj.GetComponent <Slider>();
                var dic    = info.spriteDic;
                if (dic.ContainsKey(KeyWord.background))
                {
                    var image = slider.transform.Find("Background").GetComponent <Image>();

                    if (image.sprite.rect.width > image.sprite.rect.height)
                    {
                        slider.SetDirection(Slider.Direction.LeftToRight, true);
                    }
                    else
                    {
                        slider.SetDirection(Slider.Direction.BottomToTop, true);
                    }
                    image.sprite = dic[KeyWord.background];
                    var sliderRect = slider.GetComponent <RectTransform>();
                    sliderRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, image.sprite.rect.width);
                    sliderRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, image.sprite.rect.height);
                    var backgroundRect = image.GetComponent <RectTransform>();
                    backgroundRect.anchorMin = Vector2.zero;
                    backgroundRect.anchorMax = Vector2.one;
                }
                if (dic.ContainsKey(KeyWord.fill))
                {
                    slider.fillRect.GetComponent <Image>().sprite = dic[KeyWord.fill];
                }
                if (dic.ContainsKey(KeyWord.handle))
                {
                    slider.handleRect.GetComponent <Image>().sprite = dic[KeyWord.handle];
                }
                return(obj);
            }
            return(null);
        }
Exemplo n.º 26
0
        public GameObject CreateInstence()
        {
            RectTransform parent    = null;
            var           lastTrans = Selection.activeTransform;

            if (lastTrans != null && lastTrans is RectTransform)
            {
                parent = lastTrans as RectTransform;
            }
            else
            {
                var canvas = GameObject.FindObjectOfType <Canvas>();
                if (canvas != null)
                {
                    parent = canvas.GetComponent <RectTransform>();
                }
                else
                {
                    var ok = EditorApplication.ExecuteMenuItem("GameObject/UI/Canvas");
                    if (ok)
                    {
                        parent = Selection.activeGameObject.GetComponent <RectTransform>();
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            Selection.activeObject = parent;
            var info    = new WidgetItem(name, spriteDic);
            var created = WidgetUtility.CreateInstence(widgetType, info);

            if (created != null)
            {
                created.transform.SetParent(parent, false);
                created.name = name;
                created.transform.localPosition = Vector3.zero;
            }
            return(created);
        }
        protected override void ChargeWidgetInfo(UnityEngine.Component component, WidgetItem info)
        {
            var btn       = component as Button;
            var spriteDic = info.spriteDic;

            if (spriteDic.ContainsKey(KeyWord.normal))
            {
                var texture = spriteDic[KeyWord.normal];

                var image = btn.targetGraphic as Image;
                image.sprite = texture;
                image.type   = Image.Type.Simple;
                WidgetUtility.SetNativeSize(image);
            }

            foreach (var item in spriteDic)
            {
                if (item.Key == KeyWord.normal)
                {
                    continue;
                }
                btn.transition = Selectable.Transition.SpriteSwap;
                var keyword = item.Key;
                var sprite  = item.Value;
                var state   = btn.spriteState;
                if (keyword == KeyWord.disabled)
                {
                    state.disabledSprite = sprite;
                }
                else if (keyword == KeyWord.highlighted)
                {
                    state.highlightedSprite = sprite;
                }
                else if (keyword == KeyWord.pressed)
                {
                    state.pressedSprite = sprite;
                }
                btn.spriteState = state;
            }
        }
Exemplo n.º 28
0
        public override GameObject CreateInstence(WidgetItem info)
        {
            var ok = EditorApplication.ExecuteMenuItem("GameObject/UI/Dropdown");

            if (ok)
            {
                Dropdown dropdown = Selection.activeGameObject.GetComponent <Dropdown>();
                var      dic      = info.spriteDic;
                if (dic.ContainsKey(backgroundbase))
                {
                    WidgetUtility.InitImage(dropdown.targetGraphic as Image, dic[backgroundbase], Image.Type.Sliced);
                }

                if (dic.ContainsKey(backgroundgroup))
                {
                    dropdown.template.GetComponent <Image>().sprite = dic[backgroundgroup];
                }

                if (dic.ContainsKey(backgrounditem))
                {
                    var itemgraph = dropdown.template.GetComponentInChildren <Toggle>().targetGraphic as Image;
                    itemgraph.sprite = dic[backgrounditem];
                }

                var scrollbar = dropdown.template.GetComponentInChildren <Scrollbar>();

                if (dic.ContainsKey(scrollbarbackground))
                {
                    (scrollbar.targetGraphic as Image).sprite = dic[scrollbarbackground];
                }
                if (dic.ContainsKey(scrollbarfill))
                {
                    scrollbar.handleRect.GetComponent <Image>().sprite = dic[scrollbarfill];
                }
                return(dropdown.gameObject);
            }
            return(null);
        }
Exemplo n.º 29
0
        protected override void ChargeWidgetInfo(Component component, WidgetItem info)
        {
            var slider = component as Slider;
            var dic    = info.spriteDic;

            if (dic.ContainsKey(KeyWord.background))
            {
                var image = slider.transform.Find("Background").GetComponent <Image>();
                image.sprite = dic[KeyWord.background];

                if (image.sprite.rect.width > image.sprite.rect.height)
                {
                    slider.SetDirection(Slider.Direction.LeftToRight, true);
                }
                else
                {
                    slider.SetDirection(Slider.Direction.BottomToTop, true);
                }

                var sliderRect = slider.GetComponent <RectTransform>();
                sliderRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, image.sprite.rect.width);
                sliderRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, image.sprite.rect.height);
                var backgroundRect = image.GetComponent <RectTransform>();
                backgroundRect.anchorMin = Vector2.zero;
                backgroundRect.anchorMax = Vector2.one;
            }

            if (dic.ContainsKey(KeyWord.fill))
            {
                slider.fillRect.gameObject.SetActive(true);
                slider.fillRect.GetComponent <Image>().sprite = dic[KeyWord.fill];
            }
            else
            {
                slider.fillRect.gameObject.SetActive(false);
            }

            if (slider.fillRect != null)
            {
                var fileRectParent = slider.fillRect.parent as RectTransform;
                fileRectParent.anchoredPosition = Vector2.zero;
                fileRectParent.sizeDelta        = Vector2.zero;
            }

            if (dic.ContainsKey(KeyWord.handle))
            {
                slider.handleRect.gameObject.SetActive(true);
                var handleImage = slider.handleRect.GetComponent <Image>();
                handleImage.sprite = dic[KeyWord.handle];
            }
            else
            {
                slider.handleRect.gameObject.SetActive(false);
            }

            if (slider.handleRect != null)
            {
                var handleRectParent = slider.handleRect.parent as RectTransform;
                handleRectParent.sizeDelta = Vector2.zero;
            }
        }
Exemplo n.º 30
0
 public abstract List <Sprite> GetPreviewList(WidgetItem info);