private static Sprite GenerateDefaultSprite(Texture2D texture)
        {
            string          assetPath       = AssetDatabase.GetAssetPath(texture);
            TextureImporter textureImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter;

            if (textureImporter.textureType != TextureImporterType.Sprite && textureImporter.textureType != TextureImporterType.Advanced)
            {
                return(null);
            }
            if (textureImporter.spriteImportMode == SpriteImportMode.None)
            {
                if (textureImporter.textureType == TextureImporterType.Advanced)
                {
                    return(null);
                }
                textureImporter.spriteImportMode = SpriteImportMode.Single;
                AssetDatabase.WriteImportSettingsIfDirty(assetPath);
                SpriteUtility.ForcedImportFor(assetPath);
            }
            UnityEngine.Object @object = null;
            try
            {
                @object = AssetDatabase.LoadAllAssetsAtPath(assetPath).First((UnityEngine.Object t) => t is Sprite);
            }
            catch (Exception)
            {
                Debug.LogWarning("Texture being dragged has no Sprites.");
            }
            return(@object as Sprite);
        }
        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));
        }
Exemple #3
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);
                     }
                 }
             }
         }
     }
 }
Exemple #4
0
        private static Sprite GenerateDefaultSprite(UnityEngine.Texture2D texture)
        {
            string          assetPath       = AssetDatabase.GetAssetPath(texture);
            TextureImporter textureImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter;
            Sprite          result;

            if (textureImporter == null)
            {
                result = null;
            }
            else if (textureImporter.textureType != TextureImporterType.Sprite)
            {
                result = null;
            }
            else
            {
                if (textureImporter.spriteImportMode == SpriteImportMode.None)
                {
                    textureImporter.spriteImportMode = SpriteImportMode.Single;
                    AssetDatabase.WriteImportSettingsIfDirty(assetPath);
                    SpriteUtility.ForcedImportFor(assetPath);
                }
                UnityEngine.Object @object = AssetDatabase.LoadAllAssetsAtPath(assetPath).FirstOrDefault((UnityEngine.Object t) => t is Sprite);
                result = (@object as Sprite);
            }
            return(result);
        }
        private static Sprite GenerateDefaultSprite(Texture2D texture)
        {
            string          assetPath = AssetDatabase.GetAssetPath((UnityEngine.Object)texture);
            TextureImporter atPath    = AssetImporter.GetAtPath(assetPath) as TextureImporter;

            if ((UnityEngine.Object)atPath == (UnityEngine.Object)null)
            {
                return((Sprite)null);
            }
            if (atPath.textureType != TextureImporterType.Sprite && atPath.textureType != TextureImporterType.Advanced)
            {
                return((Sprite)null);
            }
            if (atPath.spriteImportMode == SpriteImportMode.None)
            {
                if (atPath.textureType == TextureImporterType.Advanced)
                {
                    return((Sprite)null);
                }
                atPath.spriteImportMode = SpriteImportMode.Single;
                AssetDatabase.WriteImportSettingsIfDirty(assetPath);
                SpriteUtility.ForcedImportFor(assetPath);
            }
            UnityEngine.Object @object = (UnityEngine.Object)null;
            try
            {
                @object = ((IEnumerable <UnityEngine.Object>)AssetDatabase.LoadAllAssetsAtPath(assetPath)).First <UnityEngine.Object>((Func <UnityEngine.Object, bool>)(t => t is Sprite));
            }
            catch (Exception ex)
            {
                Debug.LogWarning((object)"Texture being dragged has no Sprites.");
            }
            return(@object as Sprite);
        }