EditorAsset.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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)) Resources.UnloadAsset(asset);
  16. asset = null;
  17. }
  18. protected override void OnUpdate()
  19. {
  20. if (status != LoadableStatus.Loading) return;
  21. OnLoaded(AssetDatabase.LoadAssetAtPath(pathOrURL, type));
  22. }
  23. public override void LoadImmediate()
  24. {
  25. OnLoaded(AssetDatabase.LoadAssetAtPath(pathOrURL, type));
  26. }
  27. internal static EditorAsset Create(string path, Type type)
  28. {
  29. if (!File.Exists(path)) throw new FileNotFoundException(path);
  30. return new EditorAsset
  31. {
  32. pathOrURL = path,
  33. type = type
  34. };
  35. }
  36. }
  37. }