EditorAsset.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.IO;
  3. using UnityEditor;
  4. using UnityEngine;
  5. namespace VEngine.Editor.Simulation
  6. {
  7. public class EditorAsset : Asset
  8. {
  9. protected override void OnLoad()
  10. {
  11. }
  12. protected override void OnUnload()
  13. {
  14. if (asset == null) return;
  15. if (!(asset is GameObject))
  16. {
  17. Resources.UnloadAsset(asset);
  18. Resources.UnloadUnusedAssets();
  19. }
  20. asset = null;
  21. }
  22. protected override void OnUpdate()
  23. {
  24. if (status != LoadableStatus.Loading) return;
  25. OnLoaded(AssetDatabase.LoadAssetAtPath(pathOrURL, type));
  26. }
  27. public override void LoadImmediate()
  28. {
  29. OnLoaded(AssetDatabase.LoadAssetAtPath(pathOrURL, type));
  30. }
  31. internal static EditorAsset Create(string path, Type type)
  32. {
  33. if (!File.Exists(path)) throw new FileNotFoundException(path);
  34. return new EditorAsset
  35. {
  36. pathOrURL = path,
  37. type = type
  38. };
  39. }
  40. }
  41. }