JD2022-TU1/main/phone_apps/JDCompanionApp/Assets/Scripts/ResourceLoading/LoadWorker.cs

59 lines
No EOL
1.5 KiB
C#

using Network;
using UnityEngine;
namespace ResourceLoading
{
public class LoadWorker : MonoBehaviour
{
private Resource _resource;
private ILoadingCoroutine _loader;
private ConsoleServer _resourceServer;
private bool _useDiskCache;
private bool _triggerNewLoad;
// Use this for initialization
public void Start()
{
Reset();
}
// Update is called once per frame
public void Update()
{
if (_triggerNewLoad)
{
StartCoroutine(_loader.Exec(_resource.URI, _resourceServer, _useDiskCache));
_triggerNewLoad = false;
}
}
internal ILoadingCoroutine Loader { get { return _loader; } }
internal Resource LoadingResource { get { return _resource; } }
internal void Load(Resource resource, ConsoleServer resourceServer, ILoadingCoroutine loader, bool useDiskCache)
{
if (_resource == null)
{
_resource = resource;
_loader = loader;
_resourceServer = resourceServer;
_useDiskCache = useDiskCache;
_triggerNewLoad = true;
}
else
{
Debug.LogError("Launching new load task while the previous has not yet been finished!");
}
}
internal void Reset()
{
_resource = null;
_loader = null;
_triggerNewLoad = false;
}
}
} // namespace JDCompanionApp.Resources