Esempio n. 1
0
        private static void LoadCreateRequestAssets(List <Resource> list, MonoBehaviour mono, Action loaded)
        {
            //var resources = new List<Resource>();
            //foreach (var res in list)
            //{
            //    if (res.IsDone || res.IsLoading)
            //        continue;
            //    var path = WithSuffix(res.RelativePath);
            //    var fileName = String.Concat(SystemConfig.ResourceFolder, path);
            //    res.fileData = Utils.LoadByteFile(fileName);//FileAccessManager.LoadBytes(path);
            //    if (res.fileData != null && res.fileData.Length != 0)
            //        resources.Add(res);
            //    else
            //        Debug.LogError("Load file failure: " + path);
            //}
            //mono.StartCoroutine(DoLoadCreateRequestAssets(resources, loaded));
            var resources = new List <Resource>();

            foreach (var res in list)
            {
                if (res.IsDone)
                {
                    continue;
                }
                resources.Add(res);
            }
            Action action = () =>
            {
                var loadedResources = new List <Resource>();
                foreach (var res in resources)
                {
                    var path = WithSuffix(res.RelativePath);
                    //var fileName = String.Concat(SystemConfig.ResourceFolder, path);
                    //res.fileData = Utils.LoadByteFile(fileName);//FileAccessManager.LoadBytes(path);
                    res.fileData = FileAccessManager.LoadBytes(path);
                    if (res.fileData != null && res.fileData.Length != 0)
                    {
                        loadedResources.Add(res);
                    }
                    else
                    {
                        Debug.LogError("Load file failure: " + path);
                    }
                }
                TimerHeap.AddTimer(0, 0, () => mono.StartCoroutine(DoLoadCreateRequestAssets(loadedResources, loaded)));
            };

#if UNITY_IPHONE
            action();
#else
            action.BeginInvoke(null, null);
#endif
        }
Esempio n. 2
0
        public static IEnumerator LoadResource(Resource resource, Action loaded)
        {
            if (resource.IsDone)
            {
                if (loaded != null)
                {
                    loaded();
                }
                yield break;
            }
            var list = new List <Resource>();
            var sw   = new System.Diagnostics.Stopwatch();

            sw.Start();
            list.AddRange(GetDeepDependencies(resource.RelativePath));
            list.Add(resource);
            list = list.Distinct().ToList();
            sw.Stop();
            //Debug.Log("sw.ElapsedMilliseconds: " + sw.ElapsedMilliseconds);
            int index = 0;

            //Debug.Log("list.Count: " + list.Count);
            while (index < list.Count)
            {
                var res = list[index];
                index++;
                if (res.IsDone)
                {
                    yield return(null);
                }
                else
                {
                    var path = WithSuffix(res.RelativePath);

                    if (SystemSwitch.UseFileSystem)
                    {
                        //var fileName = String.Concat(SystemConfig.ResourceFolder, path);
                        //var resourceData = Utils.LoadByteFile(fileName);
                        var resourceData = FileAccessManager.LoadBytes(path);
                        var cr           = AssetBundle.LoadFromMemoryAsync(resourceData);
                        yield return(cr);

                        res.createRequest = cr;
                        if (res.createRequest.assetBundle != null)
                        {
                            res.createRequest.assetBundle.LoadAllAssets();
                        }
                    }
                    else
                    {
                        var www = new WWW(String.Concat(SystemConfig.ASSET_FILE_HEAD, SystemConfig.ResourceFolder, path));
                        //Debug.Log(res.RelativePath);
                        yield return(www);

                        res.www = www;
                        if (res.www.assetBundle != null)
                        {
                            res.www.assetBundle.LoadAllAssets();
                        }
                    }
                }
            }
            if (loaded != null)
            {
                loaded();
            }
        }
Esempio n. 3
0
 public static byte[] LoadBytes(string fileName)
 {
     return(SystemSwitch.ReleaseMode ? FileAccessManager.LoadBytes(fileName) : Utils.LoadByteResource(fileName));
 }