Ejemplo n.º 1
0
        public void Load(AssetLoadRequest req)
        {
            string url = req.url;

            if (loaded.TryGetValue(url, out var info))
            {
                //已经加载完了
                info.unusedFrame = 0;
                req.assetHandle  = new AssetHandle(info.asset, refMgr.GetOrCreateRef(info.asset));
                req.Complete();
                return;
            }

            var webReq = req.GetData <UnityWebRequest>("__webRequest");

            if (webReq == null)
            {
                webReq = UnityWebRequest.Get(url);
            }
            var opt = webReq.SendWebRequest();

            opt.completed += OnRequestCompelted;

            if (loadingReqs.TryGetValue(url, out var reqs))
            {
                reqs.Add(req);
            }
            else
            {
                reqs = new List <AssetLoadRequest>();
                reqs.Add(req);
                loadingReqs[url] = reqs;
            }
        }
Ejemplo n.º 2
0
        AssetHandle LoadAssetAtEditor(string assetPath, System.Type type)
        {
            string realPath = Path.HasExtension(assetPath) ? assetPath : GetRealPath(assetPath, type);
            var    asset    = AssetDatabase.LoadAssetAtPath(realPath, type == null ? typeof(UnityEngine.Object) : type);

            if (asset == null)
            {
                Debug.LogWarning("load failed:" + assetPath);
                return(AssetHandle.invalid);
            }
            return(new AssetHandle(asset, editorAssetRefMagr.GetOrCreateRef(asset)));
        }