ResourcesComponentHelper.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using UnityEngine;
  7. namespace ET.Client
  8. {
  9. [FriendOf(typeof(ResourcesComponentHelper))]
  10. public static class ResourcesComponentHelperSystem
  11. {
  12. [ObjectSystem]
  13. public class ResourcesComponentHelperAwakeSystem : AwakeSystem<ResourcesComponentHelper>
  14. {
  15. protected override void Awake(ResourcesComponentHelper self)
  16. {
  17. ResourcesComponentHelper.Instance = self;
  18. }
  19. }
  20. [ObjectSystem]
  21. public class ResourcesComponentHelperDestroySystem : DestroySystem<ResourcesComponentHelper>
  22. {
  23. protected override void Destroy(ResourcesComponentHelper self)
  24. {
  25. ResourcesComponentHelper.Instance = null;
  26. }
  27. }
  28. public static async ETTask LoadSprite(this ResourcesComponentHelper self,Scene scene,string ab)
  29. {
  30. await scene.GetComponent<ResourcesLoaderComponent>().LoadAsync(ab.StringToAB());
  31. }
  32. public static Sprite GetSprite(this ResourcesComponentHelper self,string ab, string spriteName)
  33. {
  34. UnityEngine.Object spriteObj = ResourcesComponent.Instance.GetAsset(ab.StringToAB(), spriteName);
  35. if (spriteObj != null)
  36. {
  37. Texture2D texture = spriteObj as Texture2D;
  38. var sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f), 100f);
  39. return sprite;
  40. }
  41. return null;
  42. }
  43. }
  44. [ComponentOf(typeof(Scene))]
  45. public class ResourcesComponentHelper : Entity, IAwake, IDestroy
  46. {
  47. public static ResourcesComponentHelper Instance { get; set; }
  48. }
  49. }