AssetUty.cs 1006 B

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using UnityEngine;
  3. public class AssetUty
  4. {
  5. public AssetUty(AFileSystemBase f_FileSys)
  6. {
  7. this.m_FileSys = f_FileSys;
  8. }
  9. public AssetBundle LoadAssetBundle(string f_strFileName)
  10. {
  11. NDebug.Assert(this.m_FileSys != null, "LoadAssetBundle を呼び出す前に、ファイルシステムを登録して下さい。");
  12. byte[] binary;
  13. using (AFileBase afileBase = this.m_FileSys.FileOpen(f_strFileName))
  14. {
  15. binary = afileBase.ReadAll();
  16. }
  17. AssetBundle assetBundle = AssetBundle.LoadFromMemory(binary);
  18. NDebug.Assert(assetBundle != null && assetBundle.mainAsset != null, "メモリからアセットが読み出せません。\n" + f_strFileName);
  19. return assetBundle;
  20. }
  21. public string LoadAssetBundleToString(string f_strFileName)
  22. {
  23. AssetBundle assetBundle = this.LoadAssetBundle(f_strFileName);
  24. TextAsset textAsset = assetBundle.mainAsset as TextAsset;
  25. return NUty.ConvByteToString(NUty.ENCO.SHIFT_JIS, textAsset.bytes);
  26. }
  27. private AFileSystemBase m_FileSys;
  28. }