Пример #1
0
        public void AddLoadTask(LoaderType type, string path, object param, UnityAction <object> callback, bool async)
        {
            if (type != LoaderType.Scene && type != LoaderType.Bundle)
            {
                if (CheckWaitLoading(path, callback) != null)
                {
                    return;
                }
            }

            Loader ldr = AddLoadTask(type, path, param, (loader, data) =>
            {
                if (callback != null)
                {
                    callback(data);
                }

                if (type != LoaderType.Scene && type != LoaderType.Bundle)
                {
                    WaitLoadingFinish(path, data);
                }
            }, async);

            //只有异步加载才有所谓等待列表
            if (async && type != LoaderType.Scene)
            {
                SetWaitLoader(path, ldr);
            }
        }
Пример #2
0
        private Loader AddLoadTask(LoaderType type, string path, object param, UnityAction <Loader, object> callback, bool async)
        {
            Loader loader = LoaderPool.Get(type);

            loader.Init(path, param, OnLoadProgress, callback, async);

            if (!async)
            {
                m_Loaders.Add(loader);
                loader.Load();
            }
            else
            {
                m_LoaderQueue.Enqueue(loader);
                if (m_CountTotal != 0)
                {
                    ++m_CountTotal;
                }
            }

            if (0 == m_Loaders.Count)
            {
                CheckNextTask();
            }

            return(loader);
        }
Пример #3
0
        /// <summary>
        /// Opens an Xml file and loads it up using BasicHostLoader (inherits from
        /// BasicDesignerLoader)
        /// </summary>
        public HostControl GetNewHost(string fileName)
        {
            if (fileName == null || !File.Exists(fileName))
            {
                MessageBox.Show("FileName is incorrect: " + fileName);
            }

            LoaderType loaderType = LoaderType.NoLoader;

            if (fileName.EndsWith("xml"))
            {
                loaderType = LoaderType.BasicDesignerLoader;
            }

            if (loaderType == LoaderType.NoLoader || loaderType == LoaderType.CodeDomDesignerLoader)
            {
                throw new Exception("File cannot be opened. Please check the type or extension of the file. Supported format is Xml");
            }

            HostSurface   hostSurface = (HostSurface)this.CreateDesignSurface(this.ServiceContainer);
            IDesignerHost host        = (IDesignerHost)hostSurface.GetService(typeof(IDesignerHost));

            BasicHostLoader basicHostLoader = new BasicHostLoader(fileName);

            hostSurface.BeginLoad(basicHostLoader);
            hostSurface.Loader = basicHostLoader;
            hostSurface.Initialize();
            return(new HostControl(hostSurface));
        }
        //运行环境载入项目文件时调用的函数
        public HostControl LoadNewHost(string fileName)
        {
            if (fileName == null || !File.Exists(fileName))
            {
                MessageBox.Show("文件名不正确: " + fileName);
            }

            LoaderType loaderType = LoaderType.NoLoader;

            if (fileName.EndsWith("xml"))
            {
                loaderType = LoaderType.BasicDesignerLoader;
            }

            if (loaderType == LoaderType.NoLoader || loaderType == LoaderType.CodeDomDesignerLoader)
            {
                throw new Exception("文件打不开,请确认后缀名是xml!");
            }

            HostSurface   hostSurface = (HostSurface)this.CreateDesignSurface(this.ServiceContainer);
            IDesignerHost host        = (IDesignerHost)hostSurface.GetService(typeof(IDesignerHost));

            basicHostLoader = new BasicHostLoader(fileName, true);
            hostSurface.BeginLoad(basicHostLoader);
            hostSurface.Loader = basicHostLoader;
            hostSurface.Initialize();
            return(new HostControl(hostSurface));
        }
Пример #5
0
 /// <summary>
 /// Register pending loader
 /// </summary>
 /// <param name="loader">loader type that is working right now</param>
 public void RegisterActiveLoader(LoaderType loader)
 {
     lock (_lock)
     {
         _activeLoaders.Add(loader);
     }
 }
Пример #6
0
        public HostControl GetNewHost(Type rootComponentType, LoaderType loaderType)
        {
            if (loaderType == LoaderType.NoLoader)
            {
                return(GetNewHost(rootComponentType));
            }

            HostSurface   hostSurface = (HostSurface)this.CreateDesignSurface(this.ServiceContainer);
            IDesignerHost host        = (IDesignerHost)hostSurface.GetService(typeof(IDesignerHost));

            switch (loaderType)
            {
            case LoaderType.BasicDesignerLoader:
                BasicHostLoader basicHostLoader = new BasicHostLoader(rootComponentType);
                hostSurface.BeginLoad(basicHostLoader);
                hostSurface.Loader = basicHostLoader;
                break;

            case LoaderType.CodeDomDesignerLoader:
                CodeDomHostLoader codeDomHostLoader = new CodeDomHostLoader();
                hostSurface.BeginLoad(codeDomHostLoader);
                hostSurface.Loader = codeDomHostLoader;
                break;

            default:
                throw new Exception("Loader is not defined: " + loaderType.ToString());
            }

            hostSurface.Initialize();
            return(new HostControl(hostSurface));
        }
Пример #7
0
 public SubSystem(string id, LoaderType loader, string[] initFiles, string[] initPaths, string[] extensions, string[] excludePaths)
     : base(id, 0)
 {
     _loader = loader;
     _initFiles = new List<string>();
     if (initFiles != null)
     {
         _initFiles.AddRange(initFiles);
     }
     _initPaths = new List<string>();
     if (initPaths != null)
     {
         _initPaths.AddRange(initPaths);
     }
     _extensions = new List<string>();
     if (extensions != null)
     {
         _extensions.AddRange(extensions);
     }
     _excludePaths = new List<string>();
     if (excludePaths != null)
     {
         _excludePaths.AddRange(excludePaths);
     }
 }
        internal void SelectLoader(LoaderType type)
        {
            if (_loader != null)
            {
                _loader.Dispose();
            }

            switch (type)
            {
            case LoaderType.Coroutine:
                GameObject go = new GameObject("ESAFCoroutineLoader");
                go.transform.SetParent(this.transform);
                _loader = go.AddComponent <CoroutineLoader>();

                Logger.log.Debug("Using coroutines to load BeatmapDetails objects");
                break;

            case LoaderType.SeparateThread:
                go = new GameObject("ESAFThreadedLoader");
                go.transform.SetParent(this.transform);
                _loader = go.AddComponent <ThreadedLoader>();

                Logger.log.Debug("Using separate thread to load BeatmapDetails objects");
                break;
            }
        }
Пример #9
0
        /// <summary>
        /// 获得加载器
        /// </summary>
        /// <param name="type">类型</param>
        /// <param name="path">路径</param>
        /// <param name="param">附加参数</param>
        /// <param name="async">异步</param>
        /// <returns>加载器</returns>
        public Loader GetLoader(LoaderType type, string path, object param, bool async)
        {
            if (!m_DicLoaderDatas.TryGetValue(path, out LoaderData loaderData))
            {
                loaderData = LoaderDataPool.Get(type);

                if (loaderData == null)
                {
                    loaderData = new LoaderData
                    {
                        referenceCount    = 0,
                        loader            = LoaderPool.Get(type),
                        completeCallbacks = new List <LoadCompleteCallback>()
                    };
                }

                loaderData.loader.Init(path, param, null, OnLoadCompleted, async);
                m_DicLoaderDatas.Add(path, loaderData);
            }

            if (!async)
            {
                loaderData.loader.async = false;
            }

            ++loaderData.referenceCount;
            return(loaderData.loader);
        }
Пример #10
0
        /// <summary>
        /// 添加加载任务
        /// </summary>
        /// <param name="group">加载组</param>
        /// <param name="type">类型</param>
        /// <param name="path">路径</param>
        /// <param name="param">附加参数</param>
        /// <param name="completeCallback">回调</param>
        /// <param name="async">异步</param>
        /// <param name="priority">优先级</param>
        /// <param name="insert">插入</param>
        /// <returns></returns>
        public void AddLoadTask(LoaderGroup group, LoaderType type, string path, object param,
                                LoaderGroupCompleteCallback completeCallback, bool async,
                                LoadPriority priority = LoadPriority.Normal, bool insert = false)
        {
            if (!async)
            {
                Loader loader = GetLoader(type, path, param, false);
                PushCallback(loader, (data) =>
                {
                    completeCallback?.Invoke(group, data);
                });
                loader.Start();

                ReleaseLoader(loader);

                return;
            }

            if (group == null)
            {
                group = PopGroup(priority);
            }

            group.Add(type, path, param, completeCallback, true, insert);
        }
Пример #11
0
 /// <summary>
 /// Unregister pending loader
 /// </summary>
 /// <param name="loader">loader type</param>
 public void UnregisterLoader(LoaderType loader)
 {
     lock (_lock)
     {
         _activeLoaders.Remove(loader);
         ProcessResults();
     }
 }
Пример #12
0
 /// <summary>
 /// Notify all subscribers about success
 /// </summary>
 public void OnSuccess(LoaderType loader)
 {
     lock (_lock)
     {
         _loadResults.Add(new LoadResult {
             Loader = loader
         });
         UnregisterLoader(loader);
     }
 }
Пример #13
0
 /// <summary>
 /// Notify all subscribers about error
 /// </summary>
 /// <param name="loader">type of the loader</param>
 /// <param name="ex">exception</param>
 public void OnError(LoaderType loader, Exception ex)
 {
     lock (_lock)
     {
         _loadResults.Add(new LoadResult {
             Loader = loader, Error = ex
         });
         UnregisterLoader(loader);
     }
 }
Пример #14
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hash = 17;
         hash = hash * 23 + SqlHash;
         hash = hash * 23 + Type.GetHashCode();
         hash = hash * 23 + LoaderType.GetHashCode();
         return(hash);
     }
 }
Пример #15
0
        public static IConfigLoader CreateConfigLoader(LoaderType type)
        {
            switch (type)
            {
#if UNITY_EDITOR
            case LoaderType.AssetDatabase:
                return(new AssetDatabaseLoader.ConfigLoader());
#endif
            default:
                return(new AssetBundleLoader.ConfigLoader());
            }
        }
Пример #16
0
        public static IMeshLoader CreateMeshLoader(LoaderType type, MeshAtlasType atlasType)
        {
            switch (type)
            {
#if UNITY_EDITOR
            case LoaderType.AssetDatabase:
                return(new AssetDatabaseLoader.MeshLoader(atlasType));
#endif
            default:
                return(new AssetBundleLoader.MeshLoader());
            }
        }
    public static NodeDataLoader createLoader(LoaderType type, string resourcePath)
    {
        switch (type)
        {
        case LoaderType.OsmLoader:
            return(new OsmLoader(resourcePath));

        case LoaderType.HDMapLoader:
            return(new HDmapLoader(resourcePath));

        default:
            return(null);
        }
    }
Пример #18
0
        /// <summary>
        /// Notify any listeners of completion of the load, or of any exceptions
        /// that occurred during loading.
        /// </summary>
        /// <param name="loader"></param>
        /// <param name="ex"></param>
        private void NotifyCompletion(ValueLoader loader, Exception ex)
        {
            IUpdatable iupd = ValueInternal as IUpdatable;

            if (iupd != null)
            {
                iupd.IsUpdating = false;
            }

            ModelItemBase mib = ValueInternal as ModelItemBase;

            if (mib != null)
            {
                try
                {
                    mib.OnLoadCompleted(ex, false);
                }
                catch (Exception)
                {
                }
            }

            LoaderType loaderType = loader != null ? loader.LoaderType : LoaderType.CacheLoader;

            //  UpdateCompletionHandler makes sure to call handler on UI thread
            //
            try
            {
                if (ex == null)
                {
                    NextCompletedAction.OnSuccess(loaderType);

                    if (_proxyComplitionCallback != null)
                    {
                        _proxyComplitionCallback(this);
                    }
                }
                else
                {
                    NextCompletedAction.OnError(loaderType, ex);
                }
            }
            finally
            {
                // free our value root
                //
                _rootedValue = null;
            }
        }
Пример #19
0
        public static LoaderData Get(LoaderType type)
        {
            LoaderData loaderData = null;

            switch (type)
            {
            case LoaderType.Asset:
                loaderData = s_AssetLoaderDataPool.Get();
                break;

            case LoaderType.BundleAsset:
                loaderData = s_BundleAssetLoaderDataPool.Get();
                break;

            case LoaderType.Bundle:
                if (ConstantData.enableAssetBundle)
                {
                    loaderData = s_CacheBundleLoaderDataPool.Get();
                }
                else
                {
                    loaderData = s_BundleLoaderDataPool.Get();
                }
                break;

            case LoaderType.Resource:
                loaderData = s_ResourceLoaderDataPool.Get();
                break;

            case LoaderType.Scene:
                loaderData = s_SceneLoaderDataPool.Get();
                break;

            case LoaderType.Stream:
                loaderData = s_StreamLoaderDataPool.Get();
                break;
            }

            if (null != loaderData && null == loaderData.loader)
            {
                loaderData.loader = LoaderPool.Get(type);
            }

            return(loaderData);
        }
Пример #20
0
        public Loader GetLoader(LoaderType type = LoaderType.Async)
        {
            Loader loader = null;

            //同步下载器
            if (type == LoaderType.Sync)
            {
                loader = loaderGo.AddComponent <SyncLoader>();
            }
            //异步下载器
            else
            {
                loader = loaderGo.AddComponent <AsyncLoader>();
            }

            loader.Init();
            return(loader);
        }
Пример #21
0
        public static ILoader GetLoader(LoaderType type, string appKey, string sourceLocation, string group)
        {
            switch (type)
            {
            case LoaderType.Manual:
                return(new ManualLoader(appKey, group));

            case LoaderType.RemoteWeb:
                return(String.IsNullOrEmpty(sourceLocation) ? new RemoteWebLoader(appKey, group) : new RemoteWebLoader(appKey, sourceLocation, group));

            case LoaderType.XmlFile:
            default:
                if (String.IsNullOrEmpty(sourceLocation))
                {
                    throw new LoadConfigException(type, appKey, "No SourceLocation found");
                }
                return(new XmlFileLoader(appKey, sourceLocation, group));
            }
        }
Пример #22
0
        /// <summary>
        /// Add a package/path for group, group is created if it doesn't exist.  For Internal or LocalStream, this is a directory.
        /// </summary>
        public void AddToGroup(string group, string path, LoaderType type, int priority)
        {
            List <Package> packageRefs;

            if (!mGroups.TryGetValue(group, out packageRefs))
            {
                packageRefs = new List <Package>();
                mGroups.Add(group, packageRefs);
            }

            //ensure path hasn't been added for this group
            for (int i = 0; i < packageRefs.Count; i++)
            {
                if (packageRefs[i].loader.rootPath == path)
                {
                    return;
                }
            }

            //get package from global
            for (int i = 0; i < mPackages.Count; i++)
            {
                if (mPackages[i].loader.rootPath == path)
                {
                    mPackages[i].counter++;
                    packageRefs.Add(mPackages[i]);
                    packageRefs.Sort(mPackagePriorityCompare);
                    return;
                }
            }

            //add new package
            Package newPack = new Package(path, type, priority);

            //add to global packages
            mPackages.Add(newPack);
            mPackages.Sort(mPackagePriorityCompare);

            //add to package reference
            packageRefs.Add(newPack);
            packageRefs.Sort(mPackagePriorityCompare);
        }
Пример #23
0
        /// <summary>
        /// Starts a loader with the specified loader type and the amount in miliseconds to sleep the main thread
        /// in order to visualize work.
        /// </summary>
        /// <param name="loader">The loader type defined by the <see cref="LoaderType"/> enum. </param>
        /// <param name="sleepMiliseconds">When not specified, default will be 500. </param>
        public static void StartLoader(LoaderType loader, int sleepMiliseconds = 500)
        {
            _currentLoaderRunning = loader;

            switch (loader)
            {
            case LoaderType.Loader: @default:
                InvokeLoader(_loaderWindow ?? (_loaderWindow = new LoaderWindow()));
                break;

            case LoaderType.SplashScreen:
                InvokeLoader(_splashWindow ?? (_splashWindow = new SplashWindow()));
                break;

            default:
                goto @default;
            }

            Thread.Sleep(sleepMiliseconds);
        }
Пример #24
0
            public Package(string path, LoaderType type, int _priority)
            {
                switch (type)
                {
                case LoaderType.Internal:
                    loader = new ResourceLoaderInternal(path);
                    break;

                case LoaderType.LocalBundle:
                    loader = new ResourceLoaderLocalBundle(path);
                    break;

                case LoaderType.OnlineBundle:
                    loader = new ResourceLoaderOnlineBundle(path);
                    break;
                }

                counter           = 1;
                loadQueue         = false;
                priority          = _priority;
                processedRequests = new Dictionary <string, ResourceLoader.Request>();
            }
Пример #25
0
        public static Loader Get(LoaderType type)
        {
            switch (type)
            {
            case LoaderType.Stream:
                return(s_StreamLoaderPool.Get());

            case LoaderType.Asset:
                return(s_AssetLoaderPool.Get());

            case LoaderType.Resources:
                return(s_ResourceLoaderPool.Get());

            case LoaderType.Bundle:
                return(s_BundleLoaderPool.Get());

            case LoaderType.Scene:
                return(s_SceneLoaderPool.Get());
            }

            return(null);
        }
Пример #26
0
        /// <summary>
        /// 添加任务
        /// </summary>
        /// <param name="type">类型</param>
        /// <param name="path">路径</param>
        /// <param name="param">附加参数</param>
        /// <param name="completeCallback">回调</param>
        /// <param name="async">异步</param>
        /// <param name="insert">插队</param>
        public void Add(LoaderType type, string path, object param, LoaderGroupCompleteCallback completeCallback,
                        bool async, bool insert)
        {
            LoaderInfo loaderInfo = new LoaderInfo
            {
                loader           = loaderTask.GetLoader(type, path, param, async),
                completeCallback = completeCallback
            };

            if (insert)
            {
                m_ListLoaderInfos.Insert(0, loaderInfo);
            }
            else
            {
                m_ListLoaderInfos.Add(loaderInfo);
            }

            if (isLoading && isFinish)
            {
                isFinish = false;
                LoadNext();
            }
        }
Пример #27
0
 protected Loader(LoaderType type)
 {
     this.type = type;
 }
Пример #28
0
 public LoaderRequest(string[] urlList, LoaderType[] typeList)
 {
     this.urlList = urlList;
     this.typeList = typeList;
 }
Пример #29
0
 public LoaderRequest(string url, LoaderType type)
 {
     this.url = url;
     this.type = type;
 }
Пример #30
0
        protected UnityAction <Loader, object> m_ActionLoaded;  // 完成回调

        protected Loader(LoaderType type)
        {
            m_Type = type;
        }
 public LoadConfigException(LoaderType loaderType, string appKey, Exception innerException)
     : base(String.Format("Fail loading  {0} via {1}. Details: {2}", appKey, loaderType.ToString(), innerException.ToString()))
 {
 }
 public LoadConfigException(LoaderType loaderType, string appKey, string reason)
     : base(String.Format("Fail loading  {0} via {1}. Reason: {2}", appKey, loaderType.ToString(), reason))
 {
 }
Пример #33
0
        private static IEnumerator LoaderGlobalCoroutine()
        {
            while (true)
            {
                if (loaderList.Count > 0)
                {
                    foreach (Loader loader in loaderList)
                    {
                        if (loader.www.isDone)
                        {
                            loaderList.Remove(loader);

                            if (string.IsNullOrEmpty(loader.www.error))
                            {
                                Debug.Log("Loader complete:" + loader.request.url);

                                if (loader.callback != null)
                                {
                                    LoaderResponse response = new LoaderResponse();
                                    response.isSuccessful = true;
                                    response.request      = loader.request;
                                    response.extraData    = loader.extraData;

                                    LoaderType type = loader.request.type;
                                    if (type == LoaderType.Text)
                                    {
                                        response.text = loader.www.text;
                                    }
                                    else if (type == LoaderType.Byte)
                                    {
                                        response.bytes = loader.www.bytes;
                                    }
                                    else if (type == LoaderType.Texture)
                                    {
                                        response.texture2D = loader.www.texture;
                                    }
                                    else if (type == LoaderType.AssetBundle)
                                    {
                                        response.assetBundle = loader.www.assetBundle;
                                        garbageList.Add(response.assetBundle);
                                    }
                                    else
                                    {
                                        // Do nothing
                                    }

                                    loader.callback(response);
                                }
                            }
                            else
                            {
                                Debug.LogError("Loader error:" + loader.www.error);

                                if (loader.callback != null)
                                {
                                    LoaderResponse response = new LoaderResponse();
                                    response.isSuccessful = false;
                                    response.error        = loader.www.error;
                                    response.request      = loader.request;
                                    response.extraData    = loader.extraData;

                                    loader.callback(response);
                                }
                            }
                            break;
                        }
                    }
                }

                yield return(null);
            }
        }