コード例 #1
0
        private void DrawBodyContent()
        {
            var height = this.position.height - 3 * EditorGUIUtility.singleLineHeight;
            var width  = this.position.width - 1 * EditorGUIUtility.singleLineHeight;

            using (var hor = new EditorGUILayout.HorizontalScope(GUILayout.Width(width), GUILayout.Height(height)))
            {
                using (var ver = new EditorGUILayout.VerticalScope(GUILayout.Width(width * 0.3f), GUILayout.Height(height)))
                {
                    WidgetUtility.DrawContentColor(ver.rect, Color.green);

                    using (var scroll = new EditorGUILayout.ScrollViewScope(scroll_left, false, true))
                    {
                        scroll_left = scroll.scrollPosition;
                        DrawWidghtsOptions(width * 0.3f);
                    }
                }

                using (var ver = new EditorGUILayout.VerticalScope(GUILayout.Width(width * 0.7f), GUILayout.Height(height)))
                {
                    WidgetUtility.DrawContentColor(ver.rect, Color.green);

                    DrawScrollViewObjs(width * 0.7f, height * 0.9f);

                    using (var hor0 = new EditorGUILayout.HorizontalScope(GUILayout.Width(width * 0.7f), GUILayout.Height(height * 0.1f)))
                    {
                        WidgetUtility.DrawContentColor(hor0.rect, Color.green);

                        DrawToolButtons();
                    }
                }
            }
        }
コード例 #2
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);
        }
コード例 #3
0
        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];
            }
        }
コード例 #4
0
        private void MakeUISpriteTypeBack()
        {
            if (allobjhs == null)
            {
                return;
            }

            foreach (var item in allobjhs)
            {
                if (item.spriteDic == null)
                {
                    continue;
                }
                float current = 0;
                float all     = item.spriteDic.Count;
                foreach (var spriteItem in item.spriteDic)
                {
                    EditorUtility.DisplayProgressBar("wait", "还原图片状态", current++ / all);

                    if (spriteItem.Value != null)
                    {
                        WidgetUtility.MakeSpriteAsUISprite(spriteItem.Value);
                    }
                }
            }
            EditorUtility.ClearProgressBar();
        }
コード例 #5
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);
                    foreach (var key in WidgetUtility.GetKeys(item.type))
                    {
                        if (!item.spriteDic.ContainsKey(key))
                        {
                            item.spriteDic.Add(key, null);
                        }
                    }
                    items.Add(item);
                }
            }
            return(items.ToArray());
        }
コード例 #6
0
        void InitSpriteDic()
        {
            var keys = WidgetUtility.GetKeys(type);

            if (spriteDic == null)
            {
                spriteDic = new Dictionary <string, Sprite>();
            }
            else
            {
                a : foreach (var item in spriteDic)
                {
                    if (!keys.Contains(item.Key))
                    {
                        Catch(item.Key, item.Value);
                        spriteDic.Remove(item.Key);
                        goto a;
                    }
                }
            }

            foreach (var item in keys)
            {
                if (!spriteDic.ContainsKey(item))
                {
                    spriteDic.Add(item, TryLoad(item));
                }
            }
        }
コード例 #7
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];
            }
        }
コード例 #8
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);
            }
        }
コード例 #9
0
        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);
            }
        }
コード例 #10
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]);
            }
        }
コード例 #11
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);
        }
コード例 #12
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);
        }
コード例 #13
0
        private void InportFromJson()
        {
            if (jsonFile == null)
            {
                return;
            }
            var    filePath = AssetDatabase.GetAssetPath(jsonFile);
            string dir      = filePath.Replace(System.IO.Path.GetFileName(filePath), "");
            var    json     = jsonFile.text;
            var    loaded   = WidgetUtility.LoadWidgeItems(json, dir);

            if (loaded != null)
            {
                widgetItems.Clear();
                widgetItems.AddRange(loaded);
            }
        }
コード例 #14
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);
        }
コード例 #15
0
        private void DrawHeader()
        {
            using (var ver = new EditorGUILayout.VerticalScope(GUILayout.Height(3 * EditorGUIUtility.singleLineHeight)))
            {
                WidgetUtility.DrawContentColor(ver.rect, Color.yellow);

                EditorGUILayout.PropertyField(scriptProp);

                GUILayout.Space(5);

                using (var hor = new EditorGUILayout.HorizontalScope())
                {
                    EditorGUILayout.LabelField("自定义加载路径:", GUILayout.Width(100));
                    if (GUILayout.Button(userPath, EditorStyles.label))
                    {
                        var folder = AssetDatabase.LoadAssetAtPath <DefaultAsset>(userPath);
                        Selection.activeObject = folder;
                    }

                    if (GUILayout.Button("选择", EditorStyles.miniButtonRight, GUILayout.Width(40)))
                    {
                        if (Selection.activeObject != null && ProjectWindowUtil.IsFolder(Selection.activeInstanceID))
                        {
                            var path = AssetDatabase.GetAssetPath(Selection.activeInstanceID);
                            userPath  = path;
                            currobjhs = null;
                            UpdateObjectHolders();
                        }
                        else
                        {
                            var folder = EditorUtility.OpenFolderPanel("选择文件夹", Application.dataPath, "");
                            folder = folder.Replace(Application.dataPath, "Assets");
                            if (!string.IsNullOrEmpty(folder))
                            {
                                userPath  = folder;
                                currobjhs = null;
                                UpdateObjectHolders();
                            }
                        }
                    }
                }
            }
        }
コード例 #16
0
        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);
            }
        }
コード例 #17
0
 private void UpdateObjectHolders()
 {
     allobjhs = WidgetUtility.LoadAllGameObject(userPath);
     if (allobjhs != null)
     {
         List <string> menus = new List <string>();
         for (int i = 0; i < allobjhs.Length; i++)
         {
             if (!menus.Contains(allobjhs[i].menuName))
             {
                 menus.Add(allobjhs[i].menuName);
             }
         }
         this.menus = menus.ToArray();
         if (menus.Count > 0)
         {
             LoadCurrObjects();
         }
     }
 }
コード例 #18
0
        private void DrawWidgeItem(Rect rect, int index, bool isActive, bool isFocused)
        {
            var boxRect = new Rect(rect.x + 2, rect.y + 2, rect.width - 4, rect.height - 4);

            WidgetUtility.DrawContentColor(boxRect, Color.green);

            rect = new Rect(rect.x + 5, rect.y + 5, rect.width - 10, rect.height - 10);

            var item = widgetItems[index];

            var typeRect = new Rect(rect.x, rect.y, rect.width * 0.3f, EditorGUIUtility.singleLineHeight);

            EditorGUI.BeginChangeCheck();
            item.type = (WidgetType)EditorGUI.EnumPopup(typeRect, item.type);
            if (EditorGUI.EndChangeCheck())
            {
                item.ChangeType(item.type);
            }

            var nameRect = new Rect(rect.x + rect.width * 0.3f, rect.y, rect.width * 0.7f, EditorGUIUtility.singleLineHeight);

            item.name = EditorGUI.TextField(nameRect, item.name);

            if (item.spriteDic == null)
            {
                return;
            }

            var itemnameRect = new Rect(rect.x + 0.1f * rect.width, rect.y + EditorGUIUtility.singleLineHeight, rect.width * 0.3f, EditorGUIUtility.singleLineHeight);
            var spriteRect   = new Rect(rect.x + 0.4f * rect.width, rect.y + +EditorGUIUtility.singleLineHeight, rect.width * 0.6f, EditorGUIUtility.singleLineHeight);
            var keys         = item.spriteDic.Keys;
            var array        = new List <string>(keys);

            foreach (var key in array)
            {
                EditorGUI.LabelField(itemnameRect, key);
                item.spriteDic[key] = EditorGUI.ObjectField(spriteRect, item.spriteDic[key], typeof(Sprite), false) as Sprite;
                itemnameRect.y     += EditorGUIUtility.singleLineHeight;
                spriteRect.y       += EditorGUIUtility.singleLineHeight;
            }
        }
コード例 #19
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);
        }
コード例 #20
0
        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;
            }
        }
コード例 #21
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);
        }
コード例 #22
0
 internal static void InitImage(Image image, Sprite sprite, Image.Type simple = Image.Type.Simple)
 {
     image.sprite = sprite;
     image.type   = Image.Type.Simple;
     WidgetUtility.SetNativeSize(image);
 }
コード例 #23
0
 internal static void InitRawImage(RawImage image, Texture texture)
 {
     image.texture = texture;
     WidgetUtility.SetNativeSize(image);
 }