示例#1
0
        public override IEnumerator DownLoad()
        {
            // Check fatal
            if (LoadState != EWebLoadState.None)
            {
                throw new Exception($"Web file download state is not none state. {URL}");
            }

            LoadState = EWebLoadState.Loading;

            // 下载文件
            CacheRequest = new UnityWebRequest(URL, UnityWebRequest.kHttpVerbGET);
            DownloadHandlerFile handler = new DownloadHandlerFile(SavePath);

            handler.removeFileOnAbort    = true;
            CacheRequest.downloadHandler = handler;
            CacheRequest.disposeDownloadHandlerOnDispose = true;
            CacheRequest.timeout = ResDefine.WebRequestTimeout;
            yield return(CacheRequest.SendWebRequest());

            // Check error
            if (CacheRequest.isNetworkError || CacheRequest.isHttpError)
            {
                LogSystem.Log(ELogType.Warning, $"Failed to download web file : {URL} Error : {CacheRequest.error}");
                LoadState = EWebLoadState.LoadFailed;
            }
            else
            {
                LoadState = EWebLoadState.LoadSucceed;
            }

            // Invoke callback
            LoadCallback?.Invoke(this);
        }
示例#2
0
        public override void Update()
        {
            if (IsDone())
            {
                return;
            }

            if (LoadState == EAssetFileLoadState.None)
            {
                LoadState = EAssetFileLoadState.LoadAssetFile;
            }

            // 1. 加载主资源对象
            if (LoadState == EAssetFileLoadState.LoadAssetFile)
            {
                // Load resource folder file
                System.Type systemType = AssetSystem.MakeSystemType(AssetType);
                if (systemType == null)
                {
                    _cacheRequest = Resources.LoadAsync(LoadPath);
                }
                else
                {
                    _cacheRequest = Resources.LoadAsync(LoadPath, systemType);
                }

                LoadState = EAssetFileLoadState.CheckAssetFile;
            }

            // 2. 检测AssetObject加载结果
            if (LoadState == EAssetFileLoadState.CheckAssetFile)
            {
                if (_cacheRequest.isDone == false)
                {
                    return;
                }
                _mainAsset = _cacheRequest.asset;

                // Check scene
                if (AssetType == EAssetType.Scene)
                {
                    LoadState = EAssetFileLoadState.LoadAssetFileOK;
                    LoadCallback?.Invoke(this);
                    return;
                }

                // Check error
                if (_mainAsset == null)
                {
                    LogSystem.Log(ELogType.Warning, $"Failed to load resource file : {LoadPath}");
                    LoadState = EAssetFileLoadState.LoadAssetFileFailed;
                    LoadCallback?.Invoke(this);
                }
                else
                {
                    LoadState = EAssetFileLoadState.LoadAssetFileOK;
                    LoadCallback?.Invoke(this);
                }
            }
        }
示例#3
0
        protected virtual void LoadAssetAsync <T>(AssetCacheType AssetType, string AssetPath, Action <bool> Callback = null) where T : UnityEngine.Object
        {
            AssetPath = AssetPath.ToLower();
            if (AssetCacheExisted(AssetPath))
            {
                Callback?.Invoke(true);
                return;
            }

            if (!AssetLoadCallbackList_.ContainsKey(AssetPath))
            {
                AssetLoadCallbackList_.Add(AssetPath, new List <Action <bool> > {
                    Callback
                });

                LoadAssetCacheCompletedAsync <T>(AssetType, AssetPath, (IsLoaded) =>
                {
                    foreach (var LoadCallback in AssetLoadCallbackList_[AssetPath])
                    {
                        LoadCallback?.Invoke(IsLoaded);
                    }

                    AssetLoadCallbackList_.Remove(AssetPath);
                });
            }
            else
            {
                AssetLoadCallbackList_[AssetPath].Add(Callback);
            }
        }
        public void LoadFromFileAndHide()
        {
            Deck newDeck = Deck.Parse(CardGameManager.Current, DeckFiles[SelectedFilePath], CardGameManager.Current.DeckFileType, GetDeckText());

            LoadCallback?.Invoke(newDeck);
            Hide();
        }
示例#5
0
        private static GameObject PopGameObject(string path, PrefabInfo prefabInfo, Transform parent, LoadCallback callback)
        {
            GameObject        go   = null;
            List <GameObject> pool = null;

            if (m_Pools.TryGetValue(path, out pool))
            {
                if (pool.Count > 0)
                {
                    go = pool[0];
                    pool.RemoveAt(0);
                    go.transform.SetParent(parent);
                }
            }

            if (null == go)
            {
                go      = GameObject.Instantiate(prefabInfo.prefab, parent);
                go.name = path;
            }

            go.SetActive(true);

            ++prefabInfo.count;

            if (null != callback)
            {
                callback.Invoke(go);
            }

            return(go);
        }
示例#6
0
        public override void Update()
        {
#if UNITY_EDITOR
            if (IsDone())
            {
                return;
            }

            if (LoadState == EAssetFileLoadState.None)
            {
                LoadState = EAssetFileLoadState.LoadAssetFile;
            }

            // 1. 加载主资源对象
            if (LoadState == EAssetFileLoadState.LoadAssetFile)
            {
                // Load from database
                System.Type systemType = AssetSystem.MakeSystemType(AssetType);
                string      assetPath  = GetDatabaseAssetPath(LoadPath);
                _mainAsset = UnityEditor.AssetDatabase.LoadAssetAtPath(assetPath, systemType);
                LoadState  = EAssetFileLoadState.CheckAssetFile;

                // 注意:为了模拟异步加载效果,这里直接返回
                return;
            }

            // 2. 检测AssetObject加载结果
            if (LoadState == EAssetFileLoadState.CheckAssetFile)
            {
                // Check scene
                if (AssetType == EAssetType.Scene)
                {
                    LoadState = EAssetFileLoadState.LoadAssetFileOK;
                    LoadCallback?.Invoke(this);
                    return;
                }

                // Check error
                if (_mainAsset == null)
                {
                    LogSystem.Log(ELogType.Warning, $"Failed to load database file : {LoadPath}");
                    LoadState = EAssetFileLoadState.LoadAssetFileFailed;
                    LoadCallback?.Invoke(this);
                }
                else
                {
                    LoadState = EAssetFileLoadState.LoadAssetFileOK;
                    LoadCallback?.Invoke(this);
                }
            }
#else
            throw new Exception("AssetDatabaseLoader only support unity editor.");
#endif
        }
示例#7
0
        public bool LoadLuaSession(string path)
        {
            var file = new FileInfo(path);

            if (file.Exists)
            {
                Clear();
                using (var sr = file.OpenText())
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        if (line.StartsWith("---"))
                        {
                            Add(LuaFile.SeparatorInstance);
                        }
                        else
                        {
                            var scriptPath = line.Substring(2, line.Length - 2);
                            if (!Path.IsPathRooted(scriptPath))
                            {
                                var directory = Path.GetDirectoryName(path);
                                scriptPath = Path.GetFullPath(Path.Combine(directory, scriptPath));
                            }

                            Add(new LuaFile(scriptPath)
                            {
                                State = !Global.Config.DisableLuaScriptsOnLoad && line.Substring(0, 1) == "1"
                                                                         ? LuaFile.RunState.Running
                                                                         : LuaFile.RunState.Disabled
                            });
                        }
                    }
                }

                Global.Config.RecentLuaSession.Add(path);
                ForEach(lua => Global.Config.RecentLua.Add(lua.Path));

                _filename = path;
                LoadCallback?.Invoke();

                return(true);
            }

            return(false);
        }
        public override IEnumerator DownLoad()
        {
            // Check fatal
            if (string.IsNullOrEmpty(PostContent))
            {
                throw new Exception($"Web post content is null or empty. {URL}");
            }

            // Check fatal
            if (LoadState != EWebLoadState.None)
            {
                throw new Exception($"Web post download state is not none state. {URL}");
            }

            LoadState = EWebLoadState.Loading;

            // 投递数据
            byte[] bodyRaw = Encoding.UTF8.GetBytes(PostContent);

            // 下载文件
            CacheRequest = new UnityWebRequest(URL, UnityWebRequest.kHttpVerbPOST);
            UploadHandlerRaw      uploadHandler   = new UploadHandlerRaw(bodyRaw);
            DownloadHandlerBuffer downloadhandler = new DownloadHandlerBuffer();

            CacheRequest.uploadHandler   = uploadHandler;
            CacheRequest.downloadHandler = downloadhandler;
            CacheRequest.disposeDownloadHandlerOnDispose = true;
            CacheRequest.timeout = ResDefine.WebRequestTimeout;
            yield return(CacheRequest.SendWebRequest());

            // Check error
            if (CacheRequest.isNetworkError || CacheRequest.isHttpError)
            {
                LogSystem.Log(ELogType.Warning, $"Failed to request web post : {URL} Error : {CacheRequest.error}");
                LoadState = EWebLoadState.LoadFailed;
            }
            else
            {
                LoadState = EWebLoadState.LoadSucceed;
            }

            // Invoke callback
            LoadCallback?.Invoke(this);
        }
示例#9
0
        public void LoadFromFileAndHide()
        {
            string deckText = string.Empty;

            try
            {
                deckText = File.ReadAllText(DeckFiles[SelectedFileName]);
            }
            catch (Exception e)
            {
                Debug.LogError(DeckLoadErrorMessage + e.Message);
            }

            Deck newDeck = Deck.Parse(CardGameManager.Current, SelectedFileName, CardGameManager.Current.DeckFileType, deckText);

            LoadCallback?.Invoke(newDeck);
            ResetCancelButton();
            Hide();
        }
示例#10
0
        public override IEnumerator DownLoad()
        {
            // Check fatal
            if (LoadState != EWebLoadState.None)
            {
                throw new Exception($"Web bundle download state is not none state. {URL}");
            }

            LoadState = EWebLoadState.Loading;

            // 下载文件
#if UNITY_2017_4
            CacheRequest = UnityWebRequest.GetAssetBundle(URL);
#else
            CacheRequest = UnityWebRequestAssetBundle.GetAssetBundle(URL);
#endif
            CacheRequest.disposeDownloadHandlerOnDispose = true;
            CacheRequest.timeout = ResDefine.WebRequestTimeout;
            yield return(CacheRequest.SendWebRequest());

            // Check error
            if (CacheRequest.isNetworkError || CacheRequest.isHttpError)
            {
                LogSystem.Log(ELogType.Warning, $"Failed to download web bundle : {URL} Error : {CacheRequest.error}");
                LoadState = EWebLoadState.LoadFailed;
            }
            else
            {
                CacheBundle = DownloadHandlerAssetBundle.GetContent(CacheRequest);
                if (CacheBundle == null)
                {
                    LoadState = EWebLoadState.LoadFailed;
                }
                else
                {
                    LoadState = EWebLoadState.LoadSucceed;
                }
            }

            // Invoke callback
            LoadCallback?.Invoke(this);
        }
示例#11
0
        public override void Update()
        {
            // 轮询更新所有对象加载器
            if (LoadState == EAssetFileLoadState.LoadAssetFileOK)
            {
                UpdateAllAssetObjectLoader();
            }

            if (IsDone())
            {
                return;
            }

            if (LoadState == EAssetFileLoadState.None)
            {
                LoadState = EAssetFileLoadState.LoadDepends;
            }

            // 1. 加载所有依赖项
            if (LoadState == EAssetFileLoadState.LoadDepends)
            {
                string[] dependencies = AssetSystem.BundleMethod.GetDirectDependencies(_manifestPath);
                if (dependencies.Length > 0)
                {
                    foreach (string dpManifestPath in dependencies)
                    {
                        string          dpLoadPath = AssetSystem.BundleMethod.GetAssetBundleLoadPath(dpManifestPath);
                        AssetFileLoader dpLoader   = AssetSystem.GetFileLoader(false, dpLoadPath, null, dpManifestPath);
                        _depends.Add(dpLoader);
                    }
                }
                LoadState = EAssetFileLoadState.CheckDepends;
            }

            // 2. 检测所有依赖完成状态
            if (LoadState == EAssetFileLoadState.CheckDepends)
            {
                foreach (var dpLoader in _depends)
                {
                    if (dpLoader.IsDone() == false)
                    {
                        return;
                    }
                }
                LoadState = EAssetFileLoadState.LoadAssetFile;
            }

            // 3. 加载AssetBundle
            if (LoadState == EAssetFileLoadState.LoadAssetFile)
            {
#if UNITY_EDITOR
                // 注意:Unity2017.4编辑器模式下,如果AssetBundle文件不存在会导致编辑器崩溃,这里做了预判。
                if (System.IO.File.Exists(LoadPath) == false)
                {
                    LogSystem.Log(ELogType.Warning, $"Not found assetBundle file : {LoadPath}");
                    LoadState = EAssetFileLoadState.LoadAssetFileFailed;
                    LoadCallback?.Invoke(this);
                    return;
                }
#endif

                // Load assetBundle file
                _cacheRequest = AssetBundle.LoadFromFileAsync(LoadPath);
                LoadState     = EAssetFileLoadState.CheckAssetFile;
            }

            // 4. 检测AssetBundle加载结果
            if (LoadState == EAssetFileLoadState.CheckAssetFile)
            {
                if (_cacheRequest.isDone == false)
                {
                    return;
                }
                _cacheBundle = _cacheRequest.assetBundle;

                // Check scene
                if (IsStreamScene)
                {
                    LoadState = EAssetFileLoadState.LoadAssetFileOK;
                    LoadCallback?.Invoke(this);
                    return;
                }

                // Check error
                if (_cacheBundle == null)
                {
                    LogSystem.Log(ELogType.Warning, $"Failed to load assetBundle file : {LoadPath}");
                    LoadState = EAssetFileLoadState.LoadAssetFileFailed;
                    LoadCallback?.Invoke(this);
                }
                else
                {
                    LoadState = EAssetFileLoadState.LoadAssetFileOK;
                    LoadCallback?.Invoke(this);
                }
            }
        }