Example #1
0
 /// <summary>
 /// Sprite Extraction Button
 /// </summary>
 private void ExtractButton()
 {
     if (GUILayout.Button("Extract"))
     {
         if (_spriteSheet)
         {
             SpriteExtractor.ExtractAllSprites(_spriteSheet);
         }
     }
 }
Example #2
0
        /// <summary>
        /// Drag and Drop Sprite Sheets into the Window.
        /// </summary>
        private void DragAndDropSpriteSheets()
        {
            if (Event.current.type == EventType.DragUpdated)
            {
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                Event.current.Use();
            }
            else if (Event.current.type == EventType.DragPerform)
            {
                // To consume drag data.
                DragAndDrop.AcceptDrag();

                // Unity Assets including folder.
                if (DragAndDrop.objectReferences.Length > 0)
                {
                    Debug.Log("UnityAsset");

                    int length = DragAndDrop.objectReferences.Length;

                    foreach (Object objectReference in DragAndDrop.objectReferences)
                    {
                        _path     = AssetDatabase.GetAssetPath(objectReference);
                        _savePath = _path.Replace(Path.GetFileName(_path), "");

                        if (!(objectReference is Texture2D))
                        {
                            Debug.Log($"Not a Texture2D: {objectReference.name}");
                            continue;
                        }

                        _spriteSheet = objectReference as Texture2D;
                        Assert.IsNotNull(_spriteSheet);

                        if (!_autoExtractSelectedSprites)
                        {
                            break;
                        }

                        SpriteExtractor.ExtractAllSprites(_spriteSheet);
                    }
                }
                // Log to make sure we cover all cases.
                else
                {
                    Debug.Log("Out of reach");
                    Debug.Log("Paths:");

                    foreach (string path in DragAndDrop.paths)
                    {
                        Debug.Log("- " + path);
                    }

                    Debug.Log("ObjectReferences:");

                    foreach (Object obj in DragAndDrop.objectReferences)
                    {
                        Debug.Log("- " + obj);
                    }
                }
            }
        }