Beispiel #1
0
    // show the atlas selector
    static public void Show(string atlasName, OnAtlasSelectionCallback callback)
    {
        // close the current selector instance, if any
        SVGAtlasSelector.CloseAll();

        SVGAtlasSelector selector = ScriptableWizard.DisplayWizard <SVGAtlasSelector>("Select an atlas");

        selector.m_SearchString = atlasName;
        selector.m_Callback     = callback;
        selector.m_ScrollPos    = Vector2.zero;
        selector.m_AtlasesList  = SVGAtlasSelector.GetAtlasesList();
        selector.m_Time         = Time.realtimeSinceStartup;
        selector.m_TextureIndex = 0;
    }
    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);
    }
Beispiel #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);
        }
    }
Beispiel #4
0
 private List <SVGAtlas> Header()
 {
     EditorGUIUtility.labelWidth = SVGAtlasSelector.ATLAS_PREVIEW_DIMENSION;
     // show atlas name
     GUILayout.Label("Available atlases", "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 atlases list
     return(SVGAtlasSelector.FilterAtlasesList(this.m_AtlasesList, this.m_SearchString));
 }
Beispiel #5
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) / SVGAtlasSelector.ATLAS_PREVIEW_DIMENSION_PADDED), 1);
        int  rowsCount     = 1;
        int  atlasIdx      = 0;
        Rect rect          = new Rect(SVGAtlasSelector.ATLAS_PREVIEW_BORDER, SVGAtlasSelector.ATLAS_PREVIEW_BORDER,
                                      SVGAtlasSelector.ATLAS_PREVIEW_DIMENSION, SVGAtlasSelector.ATLAS_PREVIEW_DIMENSION);
        // draw header, with the name of atlas and the "search by name" toolbox
        List <SVGAtlas> atlasesList = this.Header();

        this.m_ScrollPos = GUILayout.BeginScrollView(this.m_ScrollPos);
        while (atlasIdx < atlasesList.Count)
        {
            // start a new row
            GUILayout.BeginHorizontal();
            {
                int currentColumn = 0;
                rect.x = SVGAtlasSelector.ATLAS_PREVIEW_BORDER;

                while (atlasIdx < atlasesList.Count)
                {
                    SVGAtlas atlas = atlasesList[atlasIdx];

                    // buttons are used to implement atlas selection (we use the atlas name as tooltip)
                    if (GUI.Button(rect, new GUIContent("", atlas.name)))
                    {
                        // mouse left button click
                        if (Event.current.button == 0)
                        {
                            if (this.m_Callback != null)
                            {
                                this.m_Callback(atlas);
                            }
                            close = true;
                        }
                    }
                    // draw atlas preview
                    if (Event.current.type == EventType.Repaint)
                    {
                        SVGAtlasSelector.AtlasPreview(atlas, rect, this.m_TextureIndex);
                    }
                    // draw atlas name
                    SVGAtlasSelector.AtlasLabel(atlas.name, rect);

                    // next atlas
                    atlasIdx++;
                    // next column
                    rect.x += SVGAtlasSelector.ATLAS_PREVIEW_DIMENSION_PADDED;
                    if (++currentColumn >= columnsPerRow)
                    {
                        break;
                    }
                }
            }

            GUILayout.EndHorizontal();
            GUILayout.Space(SVGAtlasSelector.ATLAS_PREVIEW_DIMENSION_PADDED);
            rect.y += SVGAtlasSelector.ATLAS_PREVIEW_DIMENSION_PADDED + SVGAtlasSelector.ATLAS_NAME_HEIGHT;
            rowsCount++;
        }

        GUILayout.Space((rowsCount - 1) * SVGAtlasSelector.ATLAS_NAME_HEIGHT + SVGAtlasSelector.ATLAS_PREVIEW_BORDER);
        GUILayout.EndScrollView();

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