Пример #1
0
    // show the sprite selector
    static public void Show(SVGBasicAtlas atlas, string spriteName, OnSpriteSelectionCallback callback)
    {
        // close the current selector instance, if any
        SVGSpriteSelector.CloseAll();

        if (atlas != null)
        {
            SVGSpriteSelector selector = ScriptableWizard.DisplayWizard <SVGSpriteSelector>("Select a sprite");
            selector.m_Atlas        = atlas;
            selector.m_SearchString = spriteName;
            selector.m_Callback     = callback;
            selector.m_ScrollPos    = Vector2.zero;
            selector.m_SpritesList  = SVGSpriteSelector.GetSpritesList(atlas);
        }
    }
    protected bool UpdateButtonDraw(SVGBasicAtlas atlas)
    {
        bool pushed = false;
        // update button
        string updateStr = (atlas.NeedsUpdate()) ? "Update *" : "Update";

        if (GUILayout.Button(updateStr))
        {
            // close all modal popup editors
            SVGPivotEditor.CloseAll();
            SVGSpriteSelector.CloseAll();
            SVGAtlasSelector.CloseAll();
            pushed = true;
        }

        return(pushed);
    }
Пример #3
0
    private void DrawInspector()
    {
        bool resizeOnStart   = EditorGUILayout.Toggle("Resize on Start()", this.m_EditedLoader.ResizeOnStart);
        bool updateTransform = EditorGUILayout.Toggle("Update transform", this.m_EditedLoader.UpdateTransform);

        string atlasName = (this.m_EditedLoader.Atlas != null) ? this.m_EditedLoader.Atlas.name : "<select>";

        EditorGUILayout.BeginHorizontal();
        {
            EditorGUILayout.PrefixLabel("Atlas");
            if (GUILayout.Button(atlasName, "DropDown"))
            {
                SVGAtlasSelector.Show("", this.OnAtlasSelect);
            }
        }
        EditorGUILayout.EndHorizontal();

        if (this.m_EditedLoader.Atlas != null && this.m_EditedLoader.SpriteReference != null)
        {
            SVGSpriteAssetFile spriteAsset = this.m_EditedLoader.Atlas.GetGeneratedSprite(this.m_EditedLoader.SpriteReference);
            string             buttonText  = (spriteAsset != null) ? spriteAsset.SpriteData.Sprite.name : "<select>";

            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.PrefixLabel("Sprite");
                if (GUILayout.Button(buttonText, "DropDown"))
                {
                    SVGSpriteSelector.Show(this.m_EditedLoader.Atlas, "", this.OnSpriteSelect);
                }
            }
            EditorGUILayout.EndHorizontal();
        }

        if (this.m_EditedLoader.ResizeOnStart != resizeOnStart)
        {
            this.m_EditedLoader.ResizeOnStart = resizeOnStart;
            SVGUtils.MarkObjectDirty(this.m_EditedLoader);
        }

        if (this.m_EditedLoader.UpdateTransform != updateTransform)
        {
            this.m_EditedLoader.UpdateTransform = updateTransform;
            SVGUtils.MarkObjectDirty(this.m_EditedLoader);
        }
    }
Пример #4
0
 private List <SVGSpriteAssetFile> Header()
 {
     EditorGUIUtility.labelWidth = SVGSpriteSelector.SPRITE_PREVIEW_DIMENSION;
     // show atlas name
     GUILayout.Label(this.m_Atlas.name + " sprites", "LODLevelNotifyText");
     // the search toolbox
     GUILayout.BeginHorizontal();
     {
         GUILayout.Space(85);
         this.m_SearchString = EditorGUILayout.TextField("", this.m_SearchString, "SearchTextField");
         if (GUILayout.Button("", "SearchCancelButton", GUILayout.Width(18)))
         {
             this.m_SearchString        = "";
             GUIUtility.keyboardControl = 0;
         }
         GUILayout.Space(85);
     }
     GUILayout.EndHorizontal();
     // return the filtered sprites list
     return(SVGSpriteSelector.FilterSpritesList(this.m_SpritesList, this.m_SearchString));
 }
    private void DrawInspector()
    {
        bool resizeOnStart;

        EditorGUILayout.BeginHorizontal();
        {
            EditorGUILayout.PrefixLabel("Resize on Start()");
            resizeOnStart = EditorGUILayout.Toggle(this.m_EditedLoader.ResizeOnStart);
        }
        EditorGUILayout.EndHorizontal();

        SVGUIAtlas uiAtlas = this.m_EditedLoader.UIAtlas;

        if ((uiAtlas != null) && (this.m_EditedLoader.SpriteReference != null))
        {
            SVGSpriteAssetFile spriteAsset = uiAtlas.GetGeneratedSprite(this.m_EditedLoader.SpriteReference);
            string             buttonText  = (spriteAsset != null) ? spriteAsset.SpriteData.Sprite.name : "<select>";

            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.PrefixLabel("Sprite");
                if (GUILayout.Button(buttonText, "DropDown"))
                {
                    SVGSpriteSelector.Show(uiAtlas, "", this.OnSpriteSelect);
                }
                if (GUILayout.Button("Edit", GUILayout.Width(80)))
                {
                    // show pivot editor
                    SVGPivotEditor.Show(spriteAsset, this.OnSpriteEdited);
                }
            }
            EditorGUILayout.EndHorizontal();
        }

        if (this.m_EditedLoader.ResizeOnStart != resizeOnStart)
        {
            this.m_EditedLoader.ResizeOnStart = resizeOnStart;
            SVGUtils.MarkObjectDirty(this.m_EditedLoader);
        }
    }
Пример #6
0
    private bool DrawGUI()
    {
        bool close = false;

    #if UNITY_EDITOR_WIN
        // take care of dpi scaling factor on Windows (Display Settings --> Advanced scaling settings)
        float dpi = Screen.dpi;
        // dpi  96 == 1.00
        // dpi 120 == 1.25
        // dpi 144 == 1.50
        // dpi 168 == 1.75
        // ... and so on
        float dpiAdjust = (((dpi - 96.0f) / 24.0f) * 0.25f) + 1.0f;
    #else
        float dpiAdjust = 1.0f;
    #endif
        int  columnsPerRow = Math.Max(Mathf.FloorToInt((Screen.width / dpiAdjust) / SVGSpriteSelector.SPRITE_PREVIEW_DIMENSION_PADDED), 1);
        int  rowsCount     = 1;
        int  spriteIdx     = 0;
        Rect rect          = new Rect(SVGSpriteSelector.SPRITE_PREVIEW_BORDER, SVGSpriteSelector.SPRITE_PREVIEW_BORDER,
                                      SVGSpriteSelector.SPRITE_PREVIEW_DIMENSION, SVGSpriteSelector.SPRITE_PREVIEW_DIMENSION);
        // draw header, with the name of atlas and the "search by name" toolbox
        List <SVGSpriteAssetFile> spritesList = this.Header();

        this.m_ScrollPos = GUILayout.BeginScrollView(this.m_ScrollPos);
        while (spriteIdx < spritesList.Count)
        {
            // start a new row
            GUILayout.BeginHorizontal();
            {
                int currentColumn = 0;
                rect.x = SVGSpriteSelector.SPRITE_PREVIEW_BORDER;

                while (spriteIdx < spritesList.Count)
                {
                    SVGSpriteAssetFile spriteAsset = spritesList[spriteIdx];
                    Sprite             sprite      = spriteAsset.SpriteData.Sprite;

                    // buttons are used to implement sprite selection (we use the sprite name as tooltip)
                    if (GUI.Button(rect, new GUIContent("", sprite.name)))
                    {
                        // mouse left button click
                        if (Event.current.button == 0)
                        {
                            if (this.m_Callback != null)
                            {
                                this.m_Callback(spriteAsset);
                            }
                            close = true;
                        }
                    }

                    // show sprite preview, taking care to highlight the currently selected one
                    if (Event.current.type == EventType.Repaint)
                    {
                        SVGSpriteSelector.SpritePreview(sprite, rect);
                    }
                    // draw sprite name
                    SVGSpriteSelector.SpriteLabel(sprite.name, rect);

                    // next sprite
                    spriteIdx++;
                    // next column
                    rect.x += SVGSpriteSelector.SPRITE_PREVIEW_DIMENSION_PADDED;
                    if (++currentColumn >= columnsPerRow)
                    {
                        break;
                    }
                }
            }

            GUILayout.EndHorizontal();
            GUILayout.Space(SVGSpriteSelector.SPRITE_PREVIEW_DIMENSION_PADDED);
            rect.y += SVGSpriteSelector.SPRITE_PREVIEW_DIMENSION_PADDED + SVGSpriteSelector.SPRITE_NAME_HEIGHT;
            rowsCount++;
        }

        GUILayout.Space((rowsCount - 1) * SVGSpriteSelector.SPRITE_NAME_HEIGHT + SVGSpriteSelector.SPRITE_PREVIEW_BORDER);
        GUILayout.EndScrollView();

        return(close);
    }
Пример #7
0
 public static void CloseAll()
 {
     // close the current selector instance, if any
     if (m_Instance != null)
     {
         m_Instance.Close();
         m_Instance = null;
     }
 }
Пример #8
0
 void OnEnable()
 {
     m_Instance = this;
 }
Пример #9
0
 void OnDisable()
 {
     m_Instance = null;
 }