using asap.core; using System; using System.Collections.Generic; using UnityEngine; using UniRx; public abstract class EventButtonResource : MonoBehaviour { ILoadResourceService loadResourceService; bool Checking = false; IDisposable loadResourceIdis; string resourceKey; Animation anim; public async void CheckResource(List resourceName) { if (Checking || resourceName == null || resourceName.Count == 0) { return; } Checking = true; loadResourceService = GContext.container.Resolve(); resourceKey = string.Join(",", resourceName); Debug.Log("资源Key" + resourceKey); bool isReady = await loadResourceService.CheckResourceLoadQueue(resourceKey, resourceName); if (!isReady) { anim = GetComponent(); gameObject.SetActive(false); DisposeEvent(); loadResourceIdis = GContext.OnEvent().Where(_ => _.key == resourceKey).Subscribe(LoadEventResourceEvent); //会闪一下吗? } else { anim = null; LoadEventResource(true); } } void LoadEventResourceEvent(LoadEventResourceEvent loadEvent) { Debug.Log($"LoadEventResourceEvent {loadEvent.key} {loadEvent.isSucceeded} "); DisposeEvent(); LoadEventResource(loadEvent.isSucceeded); Checking = loadEvent.isSucceeded; } void DisposeEvent() { loadResourceIdis?.Dispose(); loadResourceIdis = null; } void LoadEventResource(bool succeeded) { if (gameObject == null) { Debug.Log("下载资源回调gameObject 是空"); return; } if (succeeded) { try { if (anim!=null) { anim.Play("btn_download_show"); } OnLoadEventResource(); } catch (System.Exception e) { Debug.LogError($"Load Event Resource Exception! == {gameObject.name} \n {e}"); } } else { Debug.LogError($"Load Event Resource Failed! == {gameObject.name}"); } } protected abstract void OnLoadEventResource(); private void OnDestroy() { DisposeEvent(); } }