1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- 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<ResourcesComponentHelper>
- {
- protected override void Awake(ResourcesComponentHelper self, params object[] param)
- {
- ResourcesComponentHelper.Instance = self;
- }
- }
-
- [ObjectSystem]
- public class ResourcesComponentHelperDestroySystem : DestroySystem<ResourcesComponentHelper>
- {
- protected override void Destroy(ResourcesComponentHelper self)
- {
- ResourcesComponentHelper.Instance = null;
-
- }
- }
- public static async ETTask LoadSprite(this ResourcesComponentHelper self,Scene scene,string ab)
- {
- await scene.GetComponent<ResourcesLoaderComponent>().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<ResourcesLoaderComponent>().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; }
-
- }
- }
|