using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using UnityEngine; namespace ET.Client { [FriendOf(typeof(ResourcesComponentHelper))] public static class ResourcesComponentHelperSystem { [ObjectSystem] public class ResourcesComponentHelperAwakeSystem : AwakeSystem { protected override void Awake(ResourcesComponentHelper self, params object[] param) { ResourcesComponentHelper.Instance = self; } } [ObjectSystem] public class ResourcesComponentHelperDestroySystem : DestroySystem { protected override void Destroy(ResourcesComponentHelper self) { ResourcesComponentHelper.Instance = null; } } public static async ETTask LoadSprite(this ResourcesComponentHelper self,Scene scene,string ab) { await scene.GetComponent().LoadAsync(ab.StringToAB()); } public static Sprite GetSprite(this ResourcesComponentHelper self,string ab, string spriteName) { UnityEngine.Object spriteObj = ResourcesComponent.Instance.GetAsset(ab.StringToAB(), spriteName); if (spriteObj != null) { if (spriteObj == null) Debug.LogError("@@@9 spriteObj == null "); if (spriteObj is Sprite) { return spriteObj as Sprite; } else if (spriteObj is Texture2D) { Texture2D texture = spriteObj as Texture2D; var sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f), 100f); return sprite; } } return null; } public static async ETTask LoadAssetAsync(this ResourcesComponentHelper self, Scene scene, string ab) { await scene.GetComponent().LoadAsync(ab.StringToAB()); } public static UnityEngine.Object GetAssetAsync(this ResourcesComponentHelper self, string ab, string subAB) { return ResourcesComponent.Instance.GetAsset(ab.StringToAB(), subAB); } } [ComponentOf(typeof(Scene))] public class ResourcesComponentHelper : Entity, IAwake, IDestroy { public static ResourcesComponentHelper Instance { get; set; } } }