public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var controlFactory = new GuiControlFactory(_guiSkinService.Skin);
            var style          = (GuiControlStyle)_styleConverter.ReadJson(reader, objectType, existingValue, serializer);
            var skin           = (string)style[_styleProperty];
            var control        = controlFactory.Create(style.TargetType, skin);

            object childControls;

            if (style.TryGetValue(nameof(GuiControl.Controls), out childControls))
            {
                var controlCollection = childControls as GuiControlCollection;

                if (controlCollection != null)
                {
                    foreach (var child in controlCollection)
                    {
                        control.Controls.Add(child);
                    }
                }
            }

            style.Apply(control);
            return(control);
        }
        static void CreateWidgetSlider()
        {
            SearchWindow.Open <GuiAtlas> ("Select atlas", "t:prefab", null, assetPath => {
                var slider = GuiControlFactory.CreateWidgetSlider(true, true);
                Undo.RegisterCreatedObjectUndo(slider.gameObject, "leopotamgroup.gui.create-slider");
                FixWidgetParent(slider);
                if (!string.IsNullOrEmpty(assetPath))
                {
                    var atlas                     = AssetDatabase.LoadAssetAtPath <GuiAtlas> (assetPath);
                    var sprNames                  = atlas.GetSpriteNames();
                    var name                      = sprNames != null && sprNames.Length > 0 ? sprNames[0] : null;
                    var thumb                     = slider.GetComponentInChildren <GuiBindPosition> ().GetComponent <GuiSprite> ();
                    slider.Background.name        = "Background";
                    slider.Foreground.name        = "Foreground";
                    thumb.name                    = "Thumb";
                    slider.Background.SpriteAtlas = atlas;
                    slider.Foreground.SpriteAtlas = atlas;
                    thumb.SpriteAtlas             = atlas;
                    slider.Background.SpriteName  = name;
                    slider.Foreground.SpriteName  = name;
                    thumb.SpriteName              = name;
                    slider.Background.ResetSize();
                    slider.Foreground.ResetSize();
                    thumb.ResetSize();

                    var receiver    = slider.Background.GetComponent <GuiEventReceiver> ();
                    receiver.Width  = slider.Background.Width;
                    receiver.Height = slider.Background.Height;
                }
                slider.Value = 0.5f;
                slider.UpdateVisuals();
                UpdateVisuals(slider);
            });
        }
 static void CreateWidgetProgressBar()
 {
     SearchWindow.Open <GuiAtlas> ("Select atlas", "t:prefab", null, assetPath => {
         var slider  = GuiControlFactory.CreateWidgetSlider();
         slider.name = "ProgressBar";
         Undo.RegisterCreatedObjectUndo(slider.gameObject, "leopotamgroup.gui.create-progressbar");
         FixWidgetParent(slider);
         if (!string.IsNullOrEmpty(assetPath))
         {
             var atlas                     = AssetDatabase.LoadAssetAtPath <GuiAtlas> (assetPath);
             var sprNames                  = atlas.GetSpriteNames();
             var name                      = sprNames != null && sprNames.Length > 0 ? sprNames[0] : null;
             slider.Background.name        = "Background";
             slider.Foreground.name        = "Foreground";
             slider.Background.SpriteAtlas = atlas;
             slider.Foreground.SpriteAtlas = atlas;
             slider.Background.SpriteName  = name;
             slider.Foreground.SpriteName  = name;
             slider.Background.ResetSize();
             slider.Foreground.ResetSize();
         }
         slider.Value = 0.5f;
         slider.UpdateVisuals();
         UpdateVisuals(slider);
     });
 }
        static void CreateWidgetButtonWithLabel()
        {
            SearchWindow.Open <GuiAtlas> ("Select atlas", "t:prefab", null, sprAssetPath => {
                var button = GuiControlFactory.CreateWidgetButtonWithLabel();
                Undo.RegisterCreatedObjectUndo(button.gameObject, "leopotamgroup.gui.create-btn");
                FixWidgetParent(button);
                if (!string.IsNullOrEmpty(sprAssetPath))
                {
                    var spr         = button.GetComponentInChildren <GuiSprite> ();
                    spr.SpriteAtlas = AssetDatabase.LoadAssetAtPath <GuiAtlas> (sprAssetPath);
                    var sprNames    = spr.SpriteAtlas.GetSpriteNames();
                    spr.SpriteName  = sprNames != null && sprNames.Length > 0 ? sprNames[0] : null;
                    spr.ResetSize();
                    button.Width  = spr.Width;
                    button.Height = spr.Height;
                    UpdateVisuals(spr);
                }

                SearchWindow.Open <Font> ("Select font", "t:font", null, fontAssetPath => {
                    var label  = button.GetComponentInChildren <GuiLabel> ();
                    label.Font = string.IsNullOrEmpty(fontAssetPath) ?
                                 Resources.GetBuiltinResource <Font> ("Arial.ttf") : AssetDatabase.LoadAssetAtPath <Font> (fontAssetPath);
                    label.Text = "Button";
                    UpdateVisuals(label);
                });

                UpdateVisuals(button);
            });
        }
        static void CreateInteractionDragScrollView()
        {
            var scroller = GuiControlFactory.CreateInteractionDragScrollView(Selection.activeGameObject);

            if (scroller != null)
            {
                Undo.RegisterCreatedObjectUndo(scroller.gameObject, "leopotamgroup.gui.create-dragscrollview");
                FixWidgetParent(scroller);
            }
        }
        static void CreateLayoutOverlayTransform()
        {
            var bind = GuiControlFactory.CreateLayoutOverlayTransform(Selection.activeGameObject);

            if (bind != null)
            {
                Undo.RegisterCreatedObjectUndo(bind.gameObject, "leopotamgroup.gui.create-overlay-transform");
                FixWidgetParent(bind);
            }
        }
        static void CreateLayoutBindEventReceiverSize()
        {
            var bind = GuiControlFactory.CreateLayoutBindEventReceiverSize(Selection.activeGameObject);

            if (bind != null)
            {
                Undo.RegisterCreatedObjectUndo(bind.gameObject, "leopotamgroup.gui.create-bind-receiver-size");
                FixWidgetParent(bind);
            }
        }
        static void CreateLayoutGuiBindPanelRange()
        {
            var bind = GuiControlFactory.CreateLayoutGuiBindPanelRange(Selection.activeGameObject);

            if (bind != null)
            {
                Undo.RegisterCreatedObjectUndo(bind.gameObject, "leopotamgroup.gui.create-bind-panel-range");
                FixWidgetParent(bind);
            }
        }
 static void CreateWidgetLabel()
 {
     SearchWindow.Open <Font> ("Select font", "t:font", null, assetPath => {
         var label = GuiControlFactory.CreateWidgetLabel();
         Undo.RegisterCreatedObjectUndo(label.gameObject, "leopotamgroup.gui.create-label");
         label.Font = string.IsNullOrEmpty(assetPath) ?
                      Resources.GetBuiltinResource <Font> ("Arial.ttf") : AssetDatabase.LoadAssetAtPath <Font> (assetPath);
         label.Text = "Label";
         FixWidgetParent(label);
         UpdateVisuals(label);
     });
 }
 static void CreateWidgetSprite()
 {
     SearchWindow.Open <GuiAtlas> ("Select atlas", "t:prefab", null, assetPath => {
         var spr = GuiControlFactory.CreateWidgetSprite();
         Undo.RegisterCreatedObjectUndo(spr.gameObject, "leopotamgroup.gui.create-sprite");
         if (!string.IsNullOrEmpty(assetPath))
         {
             spr.SpriteAtlas = AssetDatabase.LoadAssetAtPath <GuiAtlas> (assetPath);
             var sprNames    = spr.SpriteAtlas.GetSpriteNames();
             spr.SpriteName  = sprNames != null && sprNames.Length > 0 ? sprNames[0] : null;
             spr.ResetSize();
         }
         FixWidgetParent(spr);
         UpdateVisuals(spr);
     });
 }
        static void CreateLayoutScrollView()
        {
            if (Selection.activeGameObject.GetComponent <GuiPanel> () != null)
            {
                if (!EditorUtility.DisplayDialog("Warning", "GuiScrollView should be created on child GameObject relative to GuiPanel. Do you want to continue?", "Yes", "No"))
                {
                    return;
                }
            }
            var scroll = GuiControlFactory.CreateLayoutScrollView(Selection.activeGameObject);

            if (scroll != null)
            {
                Undo.RegisterCreatedObjectUndo(scroll.gameObject, "leopotamgroup.gui.create-scrollview");
                FixWidgetParent(scroll);
            }
        }
 static void CreateWidgetButton()
 {
     SearchWindow.Open <GuiAtlas> ("Select atlas", "t:prefab", null, assetPath => {
         var button = GuiControlFactory.CreateWidgetButton();
         Undo.RegisterCreatedObjectUndo(button.gameObject, "leopotamgroup.gui.create-btn");
         FixWidgetParent(button);
         if (!string.IsNullOrEmpty(assetPath))
         {
             var spr         = button.GetComponentInChildren <GuiSprite> ();
             spr.SpriteAtlas = AssetDatabase.LoadAssetAtPath <GuiAtlas> (assetPath);
             var sprNames    = spr.SpriteAtlas.GetSpriteNames();
             spr.SpriteName  = sprNames != null && sprNames.Length > 0 ? sprNames[0] : null;
             spr.ResetSize();
             button.Width  = spr.Width;
             button.Height = spr.Height;
             UpdateVisuals(spr);
         }
         UpdateVisuals(button);
     });
 }
Пример #13
0
 public MainApp()
 {
     InitializeComponent();
     controlFactory = new GuiControlFactory();
 }
 static void CreateLayoutPanel()
 {
     FixWidgetParent(GuiControlFactory.CreateWidgetPanel());
 }