ExporterTexture.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using UnityEditor;
  6. using UnityEngine;
  7. using UnityEngine.SceneManagement;
  8. namespace Unity3D2Babylon
  9. {
  10. public class BabylonTextureImporter
  11. {
  12. public TextureImporter textureImporter { get; private set; }
  13. private bool previousIsReadable;
  14. private string texturePath;
  15. public BabylonTextureImporter(string path)
  16. {
  17. try
  18. {
  19. texturePath = path;
  20. textureImporter = AssetImporter.GetAtPath(texturePath) as TextureImporter;
  21. previousIsReadable = textureImporter.isReadable;
  22. }
  23. catch (Exception ex)
  24. {
  25. UnityEngine.Debug.LogException(ex);
  26. }
  27. }
  28. public bool IsReadable()
  29. {
  30. return previousIsReadable;
  31. }
  32. public bool SetReadable()
  33. {
  34. bool result = false;
  35. try
  36. {
  37. textureImporter.isReadable = true;
  38. AssetDatabase.ImportAsset(texturePath);
  39. result = true;
  40. }
  41. catch (Exception ex)
  42. {
  43. UnityEngine.Debug.LogException(ex);
  44. }
  45. return result;
  46. }
  47. public void Resotre()
  48. {
  49. try
  50. {
  51. textureImporter.isReadable = previousIsReadable;
  52. }
  53. catch (Exception ex)
  54. {
  55. UnityEngine.Debug.LogException(ex);
  56. }
  57. finally
  58. {
  59. ForceUpdate();
  60. }
  61. }
  62. public void ForceUpdate()
  63. {
  64. try
  65. {
  66. AssetDatabase.ImportAsset(texturePath, ImportAssetOptions.ForceUpdate);
  67. }
  68. catch (Exception ex)
  69. {
  70. UnityEngine.Debug.LogException(ex);
  71. }
  72. }
  73. }
  74. }