Exemplo n.º 1
0
        private static Sprite HandleExternalDrag(bool perform)
        {
            if (DragAndDrop.paths.Length == 0)
            {
                return(null);
            }
            string text = DragAndDrop.paths[0];

            if (!SpriteUtility.ValidPathForTextureAsset(text))
            {
                return(null);
            }
            DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
            if (!perform)
            {
                return(null);
            }
            string text2 = AssetDatabase.GenerateUniqueAssetPath(Path.Combine("Assets", FileUtil.GetLastPathNameComponent(text)));

            if (text2.Length <= 0)
            {
                return(null);
            }
            FileUtil.CopyFileOrDirectory(text, text2);
            SpriteUtility.ForcedImportFor(text2);
            return(SpriteUtility.GenerateDefaultSprite(AssetDatabase.LoadMainAssetAtPath(text2) as Texture2D));
        }
Exemplo n.º 2
0
 private static void HandleExternalDrag(string[] paths, bool perform, ref List <Sprite> result)
 {
     for (int i = 0; i < paths.Length; i++)
     {
         string text = paths[i];
         if (SpriteUtility.ValidPathForTextureAsset(text))
         {
             DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
             if (perform)
             {
                 string text2 = AssetDatabase.GenerateUniqueAssetPath(Path.Combine("Assets", FileUtil.GetLastPathNameComponent(text)));
                 if (text2.Length > 0)
                 {
                     FileUtil.CopyFileOrDirectory(text, text2);
                     SpriteUtility.ForcedImportFor(text2);
                     Sprite sprite = SpriteUtility.GenerateDefaultSprite(AssetDatabase.LoadMainAssetAtPath(text2) as UnityEngine.Texture2D);
                     if (sprite != null)
                     {
                         result.Add(sprite);
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
        public static List <Sprite> TextureToSprites(UnityEngine.Texture2D tex)
        {
            UnityEngine.Object[] array = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(tex));
            List <Sprite>        list  = new List <Sprite>();

            for (int i = 0; i < array.Length; i++)
            {
                if (array[i].GetType() == typeof(Sprite))
                {
                    list.Add(array[i] as Sprite);
                }
            }
            List <Sprite> result;

            if (list.Count > 0)
            {
                result = list;
            }
            else
            {
                Sprite sprite = SpriteUtility.GenerateDefaultSprite(tex);
                if (sprite != null)
                {
                    list.Add(sprite);
                }
                result = list;
            }
            return(result);
        }
Exemplo n.º 4
0
        public static Sprite[] TextureToSprites(Texture2D tex)
        {
            UnityEngine.Object[] objectArray = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath((UnityEngine.Object)tex));
            List <Sprite>        spriteList  = new List <Sprite>();

            for (int index = 0; index < objectArray.Length; ++index)
            {
                if (objectArray[index].GetType() == typeof(Sprite))
                {
                    spriteList.Add(objectArray[index] as Sprite);
                }
            }
            if (spriteList.Count > 0)
            {
                return(spriteList.ToArray());
            }
            return(new Sprite[1] {
                SpriteUtility.GenerateDefaultSprite(tex)
            });
        }
Exemplo n.º 5
0
        public static Sprite[] TextureToSprites(Texture2D tex)
        {
            UnityEngine.Object[] array = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(tex));
            List <Sprite>        list  = new List <Sprite>();

            for (int i = 0; i < array.Length; i++)
            {
                if (array[i].GetType() == typeof(Sprite))
                {
                    list.Add(array[i] as Sprite);
                }
            }
            if (list.Count > 0)
            {
                return(list.ToArray());
            }
            return(new Sprite[]
            {
                SpriteUtility.GenerateDefaultSprite(tex)
            });
        }