123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Object = UnityEngine.Object;
- public class AssetRequest : Reference,IEnumerator
- {
- private List<Object> _requires;
- public Type assetType;
- public LoadedCallback completed;
- public string name;
- AssetBundle assetbundle;
- public AssetRequest()
- {
- asset = null;
- LoadState = AssetLoadState.Init;
- }
- public AssetLoadState LoadState { get; protected set; }
- protected void Complete()
- {
- if(completed != null)
- {
- completed(this);
- completed = null;
- }
- }
- public virtual bool isDone
- {
- get { return LoadState == AssetLoadState.Loaded || LoadState == AssetLoadState.Unload; }
- }
- public virtual float progress
- {
- get { return 1; }
- }
- public virtual string error { get; protected set; }
- public string text { get; protected set; }
- public byte[] bytes { get; protected set; }
- public Object asset { get; internal set; }
- private bool checkRequires
- {
- get { return _requires != null; }
- }
- private void UpdateRequires()
- {
- for (var i = 0; i < _requires.Count; i++)
- {
- var item = _requires[i];
- if (item != null)
- continue;
- Release();
- _requires.RemoveAt(i);
- i--;
- }
- if (_requires.Count == 0)
- _requires = null;
- }
- internal virtual void Load()
- {
- #if UNITY_EDITOR
- LoadModule.loadDelegate = UnityEditor.AssetDatabase.LoadAssetAtPath;
- if (LoadModule.runtimeMode == false && LoadModule.loadDelegate != null)
- {
- asset = LoadModule.loadDelegate(name, assetType);
-
- }
- #else
- string[] path = name.Split('/');
- string[] icon = path[path.Length-1].Split('.');
- string pa = icon[0];
- //assetbundle = LoadModule.GetAssetBundle(pa);
- //if(assetbundle == null)
- //{
- // AssetBundle ab = AssetBundle.LoadFromFile(pa);//속潼渡齡竟AB관
-
- // if (ab != null)
- // {
- // LoadModule.AddAssetBundle(pa, ab);
- // }
- // assetbundle = ab;
- //}
- asset = MaterialsManager.Instance.LoadView(pa);
-
- //asset = assetbundle.LoadAsset<GameObject>(icon[icon.Length-1]);//속潼渡齡竟
- #endif
- if (asset == null)
- {
- error = "error! file not exist:" + name;
- Debug.LogError(error);
- return;
- }
- LoadState = AssetLoadState.Loaded;
- Complete();
- }
-
-
- internal virtual void Unload()
- {
- if (asset == null)
- return;
- if (!LoadModule.runtimeMode)
- if (!(asset is GameObject))
- Resources.UnloadAsset(asset);
- asset = null;
- LoadState = AssetLoadState.Unload;
- }
- internal virtual bool Update()
- {
- if (checkRequires)
- UpdateRequires();
- if (!isDone)
- return true;
- if (completed == null)
- return false;
- try
- {
- completed.Invoke(this);
- }
- catch (Exception ex)
- {
- Debug.LogException(ex);
- }
- completed = null;
- return false;
- }
- internal virtual void LoadImmediate() { }
- #region IEnumerator implementation
- public bool MoveNext()
- {
- return !isDone;
- }
- public void Reset()
- {
-
- }
- // Start is called before the first frame update
- void Start()
- {
-
- }
- // Update is called once per frame
- public object Current
- {
- get { return null; }
- }
- #endregion
- }
|