| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Events;
- public class ResourceManager : BaseManager<ResourceManager>
- {
- public T Load<T>(string name) where T : Object
- {
- T res = Resources.Load<T>(name);
- return res;
- }
- public void LoadAsync<T>(string name, UnityAction<T> action = null) where T : Object
- {
- MonoManager.GetInstance().StartCoroutine(ReallyLoadResourceAsyn<T>(name, action));
- }
- private IEnumerator ReallyLoadResourceAsyn<T>(string name, UnityAction<T> action = null) where T : Object
- {
- ResourceRequest r = Resources.LoadAsync<T>(name);
- yield return r;
- if (r.asset != null)
- {
- if (action != null)
- {
- if (r.asset is GameObject)
- {
- action((GameObject.Instantiate(r.asset)) as T);
- }
- else
- {
- action(r.asset as T);
- }
- }
- }
- else
- {
- Debug.Log(name + ": null");
- }
- }
- }
|