void Awake()
 {
     if (SpriteSettingsUtility.Prefs == null)
     {
         SpriteSettingsUtility.LoadPrefs();
     }
 }
Example #2
0
        void DrawApplyButton()
        {
            Color defaultBg = GUI.backgroundColor;

            GUI.backgroundColor = Color.green;
            if (GUILayout.Button("Apply"))
            {
                foreach (var obj in Selection.objects)
                {
                    if (IsObjectValidTexture(obj))
                    {
                        // Load currently set fileSettings for multi-select. Otherwise use saved fileSettings
                        SpriteFileSettings settings = Selection.objects.Length == 1 ?
                                                      FileSettings : LoadSavedFileSettingsForObject(obj);
                        if (!settings.SlicingOptions.IsValid())
                        {
                            Debug.LogWarning("Skipping ApplyingTextureSettings to object due to invalid "
                                             + "Slicing Options. Object: " + obj.name);
                            continue;
                        }
                        string path            = AssetDatabase.GetAssetPath(obj);
                        var    selectedTexture = AssetDatabase.LoadAssetAtPath <Texture2D> (path);
                        SpriteSettingsUtility.ApplySpriteSettings(selectedTexture,
                                                                  currentSelectedSettings, settings);
                    }
                }

                if (currentSelectedSettings.PackOnApply)
                {
                    UnityEditor.Sprites.Packer.RebuildAtlasCacheIfNeeded(
                        EditorUserBuildSettings.activeBuildTarget, true);
                }
            }
            GUI.backgroundColor = defaultBg;
        }
        void DrawApplyButton()
        {
            Color defaultBg = GUI.backgroundColor;

            GUI.backgroundColor = Color.green;
            if (GUILayout.Button("Apply"))
            {
                SpriteSettingsUtility.ApplyDefaultTextureSettings(currentSelectedSettings, changePivot, changePackingTag);

                if (currentSelectedSettings.PackOnApply)
                {
                    UnityEditor.Sprites.Packer.RebuildAtlasCacheIfNeeded(
                        EditorUserBuildSettings.activeBuildTarget, true);
                }

                Close();
            }
            GUI.backgroundColor = defaultBg;
        }
        void DrawSelectedTextureInfo()
        {
            if (Selection.objects.Length > 0)
            {
                EditorGUILayout.LabelField("Selected textures");
                EditorGUILayout.Space();

                Color defaultColor = GUI.color;
                GUI.color = Color.yellow;

                foreach (var obj in Selection.objects)
                {
                    if (!AssetDatabase.Contains(obj))
                    {
                        continue;
                    }

                    string path = AssetDatabase.GetAssetPath(obj);

                    var asset = AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D)) as Texture2D;
                    if (asset == null)
                    {
                        continue;
                    }

                    string metaData = "";

                    var spriteSheetData = SpriteSettingsUtility.GetSpriteData(path, currentSelectedSettings.SpritesheetDataFile);
                    if (spriteSheetData != null)
                    {
                        metaData = " " + spriteSheetData.Size + ", " + spriteSheetData.Frames + " frames";
                    }

                    EditorGUILayout.LabelField(path + metaData);
                }

                GUI.color = defaultColor;
            }
        }
Example #5
0
        SpriteFileSettings LoadSavedFileSettingsForObject(Object obj)
        {
            string path = AssetDatabase.GetAssetPath(obj);

            return(SpriteSettingsUtility.GetFileSettings(path, currentSelectedSettings.SpritesheetDataFile));
        }