| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 | using System.Collections.Generic;using UnityEngine;namespace VEngine{    public class Dependencies : Loadable    {        protected readonly List<Bundle> bundles = new List<Bundle>();        protected Bundle mainBundle;        public AssetBundle assetBundle => mainBundle?.assetBundle;        protected override void OnLoad()        {            if (!Versions.GetDependencies(pathOrURL, out var info, out var infos))            {                Finish("Dependencies not found");                return;            }            if (info == null)            {                Finish("info == null");                return;            }            mainBundle = Bundle.LoadInternal(info, mustCompleteOnNextFrame);            bundles.Add(mainBundle);            if (infos != null && infos.Length > 0)                foreach (var item in infos)                    bundles.Add(Bundle.LoadInternal(item, mustCompleteOnNextFrame));        }        public override void LoadImmediate()        {            if (isDone) return;            foreach (var request in bundles) request.LoadImmediate();        }        protected override void OnUnload()        {            if (bundles.Count > 0)            {                foreach (var item in bundles)                    if (string.IsNullOrEmpty(item.error))                        item.Release();                bundles.Clear();            }            mainBundle = null;        }        protected override void OnUpdate()        {            if (status == LoadableStatus.Loading)            {                var totalProgress = 0f;                var allDone = true;                foreach (var child in bundles)                {                    totalProgress += child.progress;                    if (!string.IsNullOrEmpty(child.error))                    {                        status = LoadableStatus.FailedToLoad;                        error = child.error;                        progress = 1;                        return;                    }                    if (child.isDone) continue;                    allDone = false;                    break;                }                progress = totalProgress / bundles.Count * 0.5f;                if (allDone)                {                    if (assetBundle == null)                    {                        Finish("assetBundle == null");                        return;                    }                    Finish();                }            }        }    }}
 |