Unity 框架

SpecialFolderFileInit.cs 1.1KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /****************************************************
  2. 文件:SpecialFolderFileInit.cs
  3. 作者:陶长春
  4. 邮箱:376248129@qq.com
  5. 日期:2025年3月24日 7:32:11
  6. UnityVersion: 2021.3.13f1
  7. 功能:特殊文件夹文件创建处理
  8. *****************************************************/
  9. using System.Collections;
  10. using UnityEngine;
  11. using System.Collections.Generic;
  12. using UnityEditor;
  13. using System;
  14. using System.IO;
  15. namespace TFramework
  16. {
  17. public class SpecialFolderFileInit:AssetPostprocessor
  18. {
  19. void OnPreprocessTexture()
  20. {
  21. string suffix = Path.GetExtension(assetPath);
  22. if ((suffix == ".png" || suffix == ".jpg") && assetPath.Contains("Sprite"))
  23. InitSprite(assetPath);
  24. }
  25. private void InitSprite(string arg0)
  26. {
  27. TextureImporter importer = assetImporter as TextureImporter;
  28. if(importer)
  29. {
  30. importer.textureType = TextureImporterType.Sprite;
  31. AssetDatabase.ImportAsset(arg0, ImportAssetOptions.ForceUpdate);
  32. }
  33. }
  34. }
  35. }