SwitchCollectionAndSprite() public method

public SwitchCollectionAndSprite ( tk2dSpriteCollectionData, newCollection, int newSpriteId ) : void
newCollection tk2dSpriteCollectionData,
newSpriteId int
return void
Exemplo n.º 1
0
    // Callback and delegate
    void SpriteChangedCallbackImpl(tk2dSpriteCollectionData spriteCollection, int spriteId, object data)
    {
        tk2dBaseSprite s = target as tk2dBaseSprite;

        if (s != null)
        {
            s.SwitchCollectionAndSprite(spriteCollection, spriteId);
            s.EditMode__CreateCollider();
            EditorUtility.SetDirty(target);
        }
    }
Exemplo n.º 2
0
    protected void DrawSpriteEditorGUI(tk2dBaseSprite sprite)
    {
        var newCollection = tk2dSpriteGuiUtility.SpriteCollectionPopup("Collection", sprite.Collection, true, sprite.spriteId);
        if (sprite.Collection != newCollection)
        {
            if (sprite.Collection == null)
                sprite.Collection = newCollection;

            int spriteId = sprite.spriteId;
            if (sprite.spriteId < 0 || sprite.spriteId >= sprite.Collection.Count
                || !sprite.Collection.inst.spriteDefinitions[sprite.spriteId].Valid)
                spriteId = sprite.Collection.FirstValidDefinitionIndex;
            sprite.SwitchCollectionAndSprite(newCollection, spriteId);
            sprite.ForceBuild();
        }

        if (sprite.Collection)
        {
            int newSpriteId = sprite.spriteId;

            // sanity check sprite id
            if (sprite.spriteId < 0 || sprite.spriteId >= sprite.Collection.Count
                || !sprite.Collection.inst.spriteDefinitions[sprite.spriteId].Valid)
            {
                newSpriteId = sprite.Collection.inst.FirstValidDefinitionIndex;
            }

            newSpriteId = tk2dSpriteGuiUtility.SpriteSelectorPopup("Sprite", sprite.spriteId, sprite.Collection);
            if (tk2dPreferences.inst.displayTextureThumbs)
            {
                tk2dSpriteDefinition def = sprite.GetCurrentSpriteDef();
                if (sprite.Collection.version < 1 || def.texelSize == Vector2.zero)
                {
                    string message = "";

                    message = "No thumbnail data.";
                    if (sprite.Collection.version < 1)
                        message += "\nPlease rebuild Sprite Collection.";

                    tk2dGuiUtility.InfoBox(message, tk2dGuiUtility.WarningLevel.Info);
                }
                else
                {
                    GUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel(" ");

                    Vector2 texSize = thumbnailCache.GetSpriteSizePixels(def);
                    float w = texSize.x;
                    float h = texSize.y;
                    float maxSize = 128.0f;
                    if (w > maxSize)
                    {
                        h = h / w * maxSize;
                        w = maxSize;
                    }

                    Rect r = GUILayoutUtility.GetRect(w, h, GUILayout.ExpandWidth(false));
                    thumbnailCache.DrawSpriteTexture(r, def);

                    GUILayout.EndHorizontal();
                }
            }

            if (newSpriteId != sprite.spriteId)
            {
                sprite.spriteId = newSpriteId;
                sprite.EditMode__CreateCollider();
                GUI.changed = true;
            }

            sprite.color = EditorGUILayout.ColorField("Color", sprite.color);
            Vector3 newScale = EditorGUILayout.Vector3Field("Scale", sprite.scale);
            if (newScale != sprite.scale)
            {
                sprite.scale = newScale;
                sprite.EditMode__CreateCollider();
            }

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("HFlip"))
            {
                Vector3 s = sprite.scale;
                s.x *= -1.0f;
                sprite.scale = s;
                GUI.changed = true;
            }
            if (GUILayout.Button("VFlip"))
            {
                Vector3 s = sprite.scale;
                s.y *= -1.0f;
                sprite.scale = s;
                GUI.changed = true;
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button(new GUIContent("Reset Scale", "Set scale to 1")))
            {
                Vector3 s = sprite.scale;
                s.x = Mathf.Sign(s.x);
                s.y = Mathf.Sign(s.y);
                s.z = Mathf.Sign(s.z);
                sprite.scale = s;
                GUI.changed = true;
            }

            if (GUILayout.Button(new GUIContent("Bake Scale", "Transfer scale from transform.scale -> sprite")))
            {
                tk2dScaleUtility.Bake(sprite.transform);
                GUI.changed = true;
            }

            GUIContent pixelPerfectButton = new GUIContent("1:1", "Make Pixel Perfect");
            if ( GUILayout.Button(pixelPerfectButton ))
            {
                if (tk2dPixelPerfectHelper.inst) tk2dPixelPerfectHelper.inst.Setup();
                sprite.MakePixelPerfect();
                GUI.changed = true;
            }

            sprite.pixelPerfect = GUILayout.Toggle(sprite.pixelPerfect, new GUIContent("Always", "Always keep pixel perfect"), GUILayout.Width(60.0f));
            EditorGUILayout.EndHorizontal();
        }
        else
        {
            EditorGUILayout.IntSlider("Need a collection bound", 0, 0, 1);
        }

        bool needUpdatePrefabs = false;
        if (GUI.changed)
        {
            EditorUtility.SetDirty(sprite);
        #if !(UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4)
            if (PrefabUtility.GetPrefabType(sprite) == PrefabType.Prefab)
                needUpdatePrefabs = true;
        #endif
        }

        // This is a prefab, and changes need to be propagated. This isn't supported in Unity 3.4
        if (needUpdatePrefabs)
        {
        #if !(UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4)
            // Rebuild prefab instances
            tk2dBaseSprite[] allSprites = Resources.FindObjectsOfTypeAll(sprite.GetType()) as tk2dBaseSprite[];
            foreach (var spr in allSprites)
            {
                if (PrefabUtility.GetPrefabType(spr) == PrefabType.PrefabInstance &&
                    PrefabUtility.GetPrefabParent(spr.gameObject) == sprite.gameObject)
                {
                    // Reset all prefab states
                    var propMod = PrefabUtility.GetPropertyModifications(spr);
                    PrefabUtility.ResetToPrefabState(spr);
                    PrefabUtility.SetPropertyModifications(spr, propMod);

                    spr.ForceBuild();
                }
            }
        #endif
        }
    }
Exemplo n.º 3
0
    protected void DrawSpriteEditorGUI(tk2dBaseSprite sprite)
    {
        var newCollection = tk2dSpriteGuiUtility.SpriteCollectionPopup("Collection", sprite.collection, true, sprite.spriteId);

        if (sprite.collection != newCollection)
        {
            if (sprite.collection == null)
            {
                sprite.collection = newCollection;
            }

            int spriteId = sprite.spriteId;
            if (sprite.spriteId < 0 || sprite.spriteId >= sprite.collection.Count ||
                !sprite.collection.spriteDefinitions[sprite.spriteId].Valid)
            {
                spriteId = sprite.collection.FirstValidDefinitionIndex;
            }
            sprite.SwitchCollectionAndSprite(newCollection, spriteId);
            sprite.ForceBuild();
        }

        if (sprite.collection)
        {
            int newSpriteId = sprite.spriteId;

            // sanity check sprite id
            if (sprite.spriteId < 0 || sprite.spriteId >= sprite.collection.Count ||
                !sprite.collection.spriteDefinitions[sprite.spriteId].Valid)
            {
                newSpriteId = sprite.collection.FirstValidDefinitionIndex;
            }

            newSpriteId = tk2dSpriteGuiUtility.SpriteSelectorPopup("Sprite", sprite.spriteId, sprite.collection);
            if (tk2dPreferences.inst.displayTextureThumbs)
            {
                if (sprite.collection.version < 1 || sprite.collection.dataGuid == tk2dSpriteGuiUtility.TransientGUID)
                {
                    string message = "";

                    message = "No thumbnail data.";
                    if (sprite.collection.version < 1 && sprite.collection.dataGuid != tk2dSpriteGuiUtility.TransientGUID)
                    {
                        message += "\nPlease rebuild Sprite Collection.";
                    }

                    tk2dGuiUtility.InfoBox(message, tk2dGuiUtility.WarningLevel.Info);
                }
                else
                {
                    var tex = tk2dSpriteThumbnailCache.GetThumbnailTexture(sprite.collection, sprite.spriteId);
                    if (tex)
                    {
                        float w       = tex.width;
                        float h       = tex.height;
                        float maxSize = 128.0f;
                        if (w > maxSize)
                        {
                            h = h / w * maxSize;
                            w = maxSize;
                        }

                        Rect r = GUILayoutUtility.GetRect(w, h);
                        GUI.DrawTexture(r, tex, ScaleMode.ScaleToFit);
                    }
                }
            }

            if (newSpriteId != sprite.spriteId)
            {
                sprite.spriteId = newSpriteId;
                sprite.EditMode__CreateCollider();
                GUI.changed = true;
            }

            sprite.color = EditorGUILayout.ColorField("Color", sprite.color);
            Vector3 newScale = EditorGUILayout.Vector3Field("Scale", sprite.scale);
            if (newScale != sprite.scale)
            {
                sprite.scale = newScale;
                sprite.EditMode__CreateCollider();
            }

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("HFlip"))
            {
                Vector3 s = sprite.scale;
                s.x         *= -1.0f;
                sprite.scale = s;
                GUI.changed  = true;
            }
            if (GUILayout.Button("VFlip"))
            {
                Vector3 s = sprite.scale;
                s.y         *= -1.0f;
                sprite.scale = s;
                GUI.changed  = true;
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button(new GUIContent("Reset Scale", "Set scale to 1")))
            {
                Vector3 s = sprite.scale;
                s.x          = Mathf.Sign(s.x);
                s.y          = Mathf.Sign(s.y);
                s.z          = Mathf.Sign(s.z);
                sprite.scale = s;
                GUI.changed  = true;
            }

            if (GUILayout.Button(new GUIContent("Bake Scale", "Transfer scale from transform.scale -> sprite")))
            {
                tk2dScaleUtility.Bake(sprite.transform);
                GUI.changed = true;
            }

            GUIContent pixelPerfectButton = new GUIContent("1:1", "Make Pixel Perfect");
            if (GUILayout.Button(pixelPerfectButton))
            {
                if (tk2dPixelPerfectHelper.inst)
                {
                    tk2dPixelPerfectHelper.inst.Setup();
                }
                sprite.MakePixelPerfect();
                GUI.changed = true;
            }

            sprite.pixelPerfect = GUILayout.Toggle(sprite.pixelPerfect, new GUIContent("Always", "Always keep pixel perfect"), GUILayout.Width(60.0f));
            EditorGUILayout.EndHorizontal();
        }
        else
        {
            EditorGUILayout.IntSlider("Need a collection bound", 0, 0, 1);
        }

        bool needUpdatePrefabs = false;

        if (GUI.changed)
        {
            EditorUtility.SetDirty(sprite);
#if !(UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4)
            if (PrefabUtility.GetPrefabType(sprite) == PrefabType.Prefab)
            {
                needUpdatePrefabs = true;
            }
#endif
        }

        // This is a prefab, and changes need to be propagated. This isn't supported in Unity 3.4
        if (needUpdatePrefabs)
        {
#if !(UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4)
            // Rebuild prefab instances
            tk2dBaseSprite[] allSprites = Resources.FindObjectsOfTypeAll(sprite.GetType()) as tk2dBaseSprite[];
            foreach (var spr in allSprites)
            {
                if (PrefabUtility.GetPrefabType(spr) == PrefabType.PrefabInstance &&
                    PrefabUtility.GetPrefabParent(spr.gameObject) == sprite.gameObject)
                {
                    // Reset all prefab states
                    var propMod = PrefabUtility.GetPropertyModifications(spr);
                    PrefabUtility.ResetToPrefabState(spr);
                    PrefabUtility.SetPropertyModifications(spr, propMod);

                    spr.ForceBuild();
                }
            }
#endif
        }
    }
    protected void DrawSpriteEditorGUI(tk2dBaseSprite sprite)
    {
        // maybe cache this if its too slow later
        if (generatorCache.all == null || generatorCache.current != sprite.collection)
        {
            generatorCache.all = tk2dEditorUtility.GetOrCreateIndex().GetSpriteCollectionIndex();
            if (generatorCache.all != null)
            {
                string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(sprite.collection));

                for (int i = 0; i < generatorCache.all.Length; ++i)
                {
                    if (generatorCache.all[i].spriteCollectionDataGUID == guid)
                    {
                        generatorCache.current     = sprite.collection;
                        generatorCache.currentGUID = guid;
                        break;
                    }
                }
            }
        }

        if (generatorCache.all == null)
        {
            EditorGUILayout.LabelField("Collection", "Error");
        }
        else
        {
            string[] collNames = new string[generatorCache.all.Length];
            int      selIndex  = -1;
            for (int i = 0; i < generatorCache.all.Length; ++i)
            {
                collNames[i] = generatorCache.all[i].name;
                if (generatorCache.all[i].spriteCollectionDataGUID == generatorCache.currentGUID)
                {
                    selIndex = i;
                }
            }

            int newIndex = EditorGUILayout.Popup("Collection", (selIndex != -1) ? selIndex : 0, collNames);
            if (newIndex != selIndex)
            {
                generatorCache.currentGUID = generatorCache.all[newIndex].spriteCollectionDataGUID;
                GameObject go = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(generatorCache.currentGUID), typeof(GameObject)) as GameObject;
                tk2dSpriteCollectionData data = go.GetComponent <tk2dSpriteCollectionData>();
                if (data != null)
                {
                    generatorCache.current = data;
                    int newId = (sprite.spriteId >= generatorCache.current.Count)?0:sprite.spriteId;

                    sprite.SwitchCollectionAndSprite(generatorCache.current, newId);
                    sprite.EditMode__CreateCollider();
                }
            }
        }

        if (sprite.collection)
        {
            // sanity check sprite id
            if (sprite.spriteId < 0 || sprite.spriteId >= sprite.collection.Count)
            {
                sprite.spriteId = 0;
                sprite.EditMode__CreateCollider();
            }

            int newSpriteId = sprite.spriteId;

            if (generatorCache.current)
            {
                newSpriteId = tk2dEditorUtility.SpriteSelectorPopup("Sprite", sprite.spriteId, generatorCache.current);

                if (tk2dPreferences.inst.displayTextureThumbs)
                {
                    if (generatorCache.current.version < 1)
                    {
                        GUILayout.Label("No thumbnail data.\nPlease rebuild Sprite Collection.");
                    }
                    else
                    {
                        var tex = tk2dSpriteThumbnailCache.GetThumbnailTexture(generatorCache.current, sprite.spriteId);
                        if (tex)
                        {
                            float w       = tex.width;
                            float h       = tex.height;
                            float maxSize = 128.0f;
                            if (w > maxSize)
                            {
                                h = h / w * maxSize;
                                w = maxSize;
                            }

                            Rect r = GUILayoutUtility.GetRect(w, h);
                            GUI.DrawTexture(r, tex, ScaleMode.ScaleToFit);
                            //GUILayout.Box(tex, GUILayout.Width(w), GUILayout.Height(h));
                        }
                    }
                }
            }
            else
            {
                newSpriteId = EditorGUILayout.IntSlider(sprite.spriteId, 0, sprite.collection.Count - 1);
            }

            if (newSpriteId != sprite.spriteId)
            {
                sprite.spriteId = newSpriteId;
                sprite.EditMode__CreateCollider();
                GUI.changed = true;
            }

            sprite.color = EditorGUILayout.ColorField("Color", sprite.color);
            Vector3 newScale = EditorGUILayout.Vector3Field("Scale", sprite.scale);
            if (newScale != sprite.scale)
            {
                sprite.scale = newScale;
                sprite.EditMode__CreateCollider();
            }

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("HFlip"))
            {
                Vector3 s = sprite.scale;
                s.x         *= -1.0f;
                sprite.scale = s;
                GUI.changed  = true;
            }
            if (GUILayout.Button("VFlip"))
            {
                Vector3 s = sprite.scale;
                s.y         *= -1.0f;
                sprite.scale = s;
                GUI.changed  = true;
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("Reset Scale"))
            {
                Vector3 s = sprite.scale;
                s.x          = Mathf.Sign(s.x);
                s.y          = Mathf.Sign(s.y);
                s.z          = Mathf.Sign(s.z);
                sprite.scale = s;
                GUI.changed  = true;
            }
            if (GUILayout.Button("Bake Scale"))
            {
                tk2dScaleUtility.Bake(sprite.transform);
                GUI.changed = true;
            }

            GUIContent pixelPerfectButton = new GUIContent("1:1", "Make Pixel Perfect");
            if (GUILayout.Button(pixelPerfectButton))
            {
                if (tk2dPixelPerfectHelper.inst)
                {
                    tk2dPixelPerfectHelper.inst.Setup();
                }
                sprite.MakePixelPerfect();
                GUI.changed = true;
            }

            sprite.pixelPerfect = GUILayout.Toggle(sprite.pixelPerfect, "Always", GUILayout.Width(60.0f));
            EditorGUILayout.EndHorizontal();
        }
        else
        {
            EditorGUILayout.IntSlider("Need a collection bound", 0, 0, 1);
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(sprite);
        }
    }
Exemplo n.º 5
0
    protected void DrawSpriteEditorGUI(tk2dBaseSprite sprite)
    {
        var newCollection = tk2dSpriteGuiUtility.SpriteCollectionPopup("Collection", sprite.collection, true, sprite.spriteId);
        if (sprite.collection != newCollection)
        {
            if (sprite.collection == null)
                sprite.collection = newCollection;

            int spriteId = sprite.spriteId;
            if (sprite.spriteId < 0 || sprite.spriteId >= sprite.collection.Count
                || !sprite.collection.spriteDefinitions[sprite.spriteId].Valid)
                spriteId = sprite.collection.FirstValidDefinitionIndex;
            sprite.SwitchCollectionAndSprite(newCollection, spriteId);
            sprite.ForceBuild();
        }

        if (sprite.collection)
        {
            int newSpriteId = sprite.spriteId;

            // sanity check sprite id
            if (sprite.spriteId < 0 || sprite.spriteId >= sprite.collection.Count
                || !sprite.collection.spriteDefinitions[sprite.spriteId].Valid)
            {
                newSpriteId = sprite.collection.FirstValidDefinitionIndex;
            }

            newSpriteId = tk2dSpriteGuiUtility.SpriteSelectorPopup("Sprite", sprite.spriteId, sprite.collection);
            if (tk2dPreferences.inst.displayTextureThumbs)
            {
                if (sprite.collection.version < 1 || sprite.collection.dataGuid == tk2dSpriteGuiUtility.TransientGUID)
                {
                    string message = "";

                    message = "No thumbnail data.";
                    if (sprite.collection.version < 1 && sprite.collection.dataGuid != tk2dSpriteGuiUtility.TransientGUID)
                        message += "\nPlease rebuild Sprite Collection.";

                    tk2dGuiUtility.InfoBox(message, tk2dGuiUtility.WarningLevel.Info);
                }
                else
                {
                    var tex = tk2dSpriteThumbnailCache.GetThumbnailTexture(sprite.collection, sprite.spriteId);
                    if (tex)
                    {
                        float w = tex.width;
                        float h = tex.height;
                        float maxSize = 128.0f;
                        if (w > maxSize)
                        {
                            h = h / w * maxSize;
                            w = maxSize;
                        }

                        Rect r = GUILayoutUtility.GetRect(w, h);
                        GUI.DrawTexture(r, tex, ScaleMode.ScaleToFit);
                    }
                }
            }

            if (newSpriteId != sprite.spriteId)
            {
                sprite.spriteId = newSpriteId;
                sprite.EditMode__CreateCollider();
                GUI.changed = true;
            }

            sprite.color = EditorGUILayout.ColorField("Color", sprite.color);
            Vector3 newScale = EditorGUILayout.Vector3Field("Scale", sprite.scale);
            if (newScale != sprite.scale)
            {
                sprite.scale = newScale;
                sprite.EditMode__CreateCollider();
            }

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("HFlip"))
            {
                Vector3 s = sprite.scale;
                s.x *= -1.0f;
                sprite.scale = s;
                GUI.changed = true;
            }
            if (GUILayout.Button("VFlip"))
            {
                Vector3 s = sprite.scale;
                s.y *= -1.0f;
                sprite.scale = s;
                GUI.changed = true;
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button(new GUIContent("Reset Scale", "Set scale to 1")))
            {
                Vector3 s = sprite.scale;
                s.x = Mathf.Sign(s.x);
                s.y = Mathf.Sign(s.y);
                s.z = Mathf.Sign(s.z);
                sprite.scale = s;
                GUI.changed = true;
            }

            if (GUILayout.Button(new GUIContent("Bake Scale", "Transfer scale from transform.scale -> sprite")))
            {
                tk2dScaleUtility.Bake(sprite.transform);
                GUI.changed = true;
            }

            GUIContent pixelPerfectButton = new GUIContent("1:1", "Make Pixel Perfect");
            if ( GUILayout.Button(pixelPerfectButton ))
            {
                if (tk2dPixelPerfectHelper.inst) tk2dPixelPerfectHelper.inst.Setup();
                sprite.MakePixelPerfect();
                GUI.changed = true;
            }

            sprite.pixelPerfect = GUILayout.Toggle(sprite.pixelPerfect, new GUIContent("Always", "Always keep pixel perfect"), GUILayout.Width(60.0f));
            EditorGUILayout.EndHorizontal();
        }
        else
        {
            EditorGUILayout.IntSlider("Need a collection bound", 0, 0, 1);
        }

        if (GUI.changed)
            EditorUtility.SetDirty(sprite);
    }
Exemplo n.º 6
0
    protected void DrawSpriteEditorGUI(tk2dBaseSprite sprite)
    {
        var newCollection = tk2dSpriteGuiUtility.SpriteCollectionPopup("Collection", sprite.collection, true, sprite.spriteId);

        if (sprite.collection != newCollection)
        {
            int spriteId = sprite.spriteId;
            if (sprite.spriteId < 0 || sprite.spriteId >= sprite.collection.Count ||
                !sprite.collection.spriteDefinitions[sprite.spriteId].Valid)
            {
                spriteId = sprite.collection.FirstValidDefinitionIndex;
            }
            sprite.SwitchCollectionAndSprite(newCollection, spriteId);
            sprite.ForceBuild();
        }

        if (sprite.collection)
        {
            int newSpriteId = sprite.spriteId;

            // sanity check sprite id
            if (sprite.spriteId < 0 || sprite.spriteId >= sprite.collection.Count ||
                !sprite.collection.spriteDefinitions[sprite.spriteId].Valid)
            {
                newSpriteId = sprite.collection.FirstValidDefinitionIndex;
            }

            newSpriteId = tk2dSpriteGuiUtility.SpriteSelectorPopup("Sprite", sprite.spriteId, sprite.collection);
            if (tk2dPreferences.inst.displayTextureThumbs)
            {
                if (sprite.collection.version < 1 || sprite.collection.dataGuid == tk2dSpriteGuiUtility.TransientGUID)
                {
                    string message = "";

                    message = "No thumbnail data.";
                    if (sprite.collection.version < 1 && sprite.collection.dataGuid != tk2dSpriteGuiUtility.TransientGUID)
                    {
                        message += "\nPlease rebuild Sprite Collection.";
                    }

                    tk2dGuiUtility.InfoBox(message, tk2dGuiUtility.WarningLevel.Info);
                }
                else
                {
                    var tex = tk2dSpriteThumbnailCache.GetThumbnailTexture(sprite.collection, sprite.spriteId);
                    if (tex)
                    {
                        float w       = tex.width;
                        float h       = tex.height;
                        float maxSize = 128.0f;
                        if (w > maxSize)
                        {
                            h = h / w * maxSize;
                            w = maxSize;
                        }

                        Rect r = GUILayoutUtility.GetRect(w, h);
                        GUI.DrawTexture(r, tex, ScaleMode.ScaleToFit);
                    }
                }
            }

            if (newSpriteId != sprite.spriteId)
            {
                sprite.spriteId = newSpriteId;
                sprite.EditMode__CreateCollider();
                GUI.changed = true;
            }

            sprite.color = EditorGUILayout.ColorField("Color", sprite.color);
            Vector3 newScale = EditorGUILayout.Vector3Field("Scale", sprite.scale);
            if (newScale != sprite.scale)
            {
                sprite.scale = newScale;
                sprite.EditMode__CreateCollider();
            }

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("HFlip"))
            {
                Vector3 s = sprite.scale;
                s.x         *= -1.0f;
                sprite.scale = s;
                GUI.changed  = true;
            }
            if (GUILayout.Button("VFlip"))
            {
                Vector3 s = sprite.scale;
                s.y         *= -1.0f;
                sprite.scale = s;
                GUI.changed  = true;
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button(new GUIContent("Reset Scale", "Set scale to 1")))
            {
                Vector3 s = sprite.scale;
                s.x          = Mathf.Sign(s.x);
                s.y          = Mathf.Sign(s.y);
                s.z          = Mathf.Sign(s.z);
                sprite.scale = s;
                GUI.changed  = true;
            }

            if (GUILayout.Button(new GUIContent("Bake Scale", "Transfer scale from transform.scale -> sprite")))
            {
                tk2dScaleUtility.Bake(sprite.transform);
                GUI.changed = true;
            }

            GUIContent pixelPerfectButton = new GUIContent("1:1", "Make Pixel Perfect");
            if (GUILayout.Button(pixelPerfectButton))
            {
                if (tk2dPixelPerfectHelper.inst)
                {
                    tk2dPixelPerfectHelper.inst.Setup();
                }
                sprite.MakePixelPerfect();
                GUI.changed = true;
            }

            sprite.pixelPerfect = GUILayout.Toggle(sprite.pixelPerfect, new GUIContent("Always", "Always keep pixel perfect"), GUILayout.Width(60.0f));
            EditorGUILayout.EndHorizontal();
        }
        else
        {
            EditorGUILayout.IntSlider("Need a collection bound", 0, 0, 1);
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(sprite);
        }
    }