Ejemplo n.º 1
0
        // 全平台加载
        // 加载流文件(remote==false时先从persistentData读,没有找到则从streamingAssets读,带后缀)
        public void LoadStream(string path, LoadedHandler onLoaded,
                               bool async            = true, bool remote = false, bool isFullPath = false,
                               LoadPriority priority = LoadPriority.Normal)
        {
            string fullpath = path;

            if (!remote)
            {
                if (!isFullPath)
                {
                    fullpath = SearchPath(path, false, false, false);
                }
            }
            else
            {
                // 从服务器加载,一定是异步的
                async = true;
            }

            m_task.AddLoadTask(null, Loader.LoaderType.Stream, fullpath, remote, (group, data) => {
                if (onLoaded != null)
                {
                    onLoaded(data);
                }
            }, async, priority);
        }
Ejemplo n.º 2
0
 // 加载资源
 public void LoadAsset(string path, Type type, LoadedHandler onLoaded,
                       bool async            = true, bool persistent = false, bool inData = true,
                       LoadPriority priority = LoadPriority.Normal)
 {
     //Logger.Log(string.Format("LoadAsset: {0} - {1}", path, async));
     if (ConstantData.EnableAssetBundle)
     {
         string abName = m_mapping.GetAssetBundleNameFromAssetPath(path);
         if (string.IsNullOrEmpty(abName))
         {
             Logger.LogError(string.Format("找不到资源所对应的ab文件:{0}", path));
             if (onLoaded != null)
             {
                 onLoaded(null);
             }
         }
         else
         {
             string assetName = Path.GetFileName(path);
             LoadAssetFromBundle(null, abName, assetName, type, (group, data) => {
                 if (onLoaded != null)
                 {
                     onLoaded(data);
                 }
             }, async, persistent, priority);
         }
     }
     else
     {
         LoadAssetFile(path, onLoaded, type, async, inData, priority);
     }
 }
Ejemplo n.º 3
0
        // 加载关卡
        public void LoadScene(string name, LoadedHandler onLoaded, bool async = true, bool additive = false)
        {
            LoaderGroup group = m_task.PopGroup(LoadPriority.High);

            if (!additive)
            {
                m_task.AddLoadTask(group, Loader.LoaderType.Scene, "Empty", null, null, async);
            }

            if (ConstantData.EnableAssetBundle)
            {
                string path = string.Format("Scene/{0}", name).ToLower();

                LoadAssetBundle(group, path, (group1, data1) => {
                    m_task.AddLoadTask(group1, Loader.LoaderType.Scene, name, additive, (group2, data2) => {
                        if (onLoaded != null)
                        {
                            onLoaded(data2);
                        }
                    }, async, group.Priority, true);
                }, async);
            }
            else
            {
                m_task.AddLoadTask(group, Loader.LoaderType.Scene, name, additive, (group1, data1) => {
                    if (onLoaded != null)
                    {
                        onLoaded(data1);
                    }
                }, async);
            }
        }
Ejemplo n.º 4
0
 // 加载资源(Resource目录下,不带后缀)
 public void LoadResource(string path, LoadedHandler onLoaded,
                          bool async = true, LoadPriority priority = LoadPriority.Normal)
 {
     m_task.AddLoadTask(null, Loader.LoaderType.Resource, path, null, (group, data) => {
         if (onLoaded != null)
         {
             onLoaded(data);
         }
     }, async, priority);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ResultsHandlerViewModel"/>
        /// class.
        /// </summary>
        /// <param name="handler">The <see cref="LoadedHandler"/> to be presented</param>
        public ResultsHandlerViewModel(LoadedHandler handler)
        {
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }

            Name    = handler.DisplayName;
            Handler = handler.Handler;
        }
Ejemplo n.º 6
0
        // ------------------------------------------------------------------------------------------
        // 文件/目录是否存在
        private bool CheckFileExist(string path, LoadedHandler onLoaded, bool isFile = true)
        {
            bool exist = isFile ? File.Exists(path) : Directory.Exists(path);

            if (!exist)
            {
                // 不存在
                if (onLoaded != null)
                {
                    onLoaded(null);
                }

                return(false);
            }

            return(true);
        }
Ejemplo n.º 7
0
        public void AddHandler(Type messageType, object handler)
        {
            List<LoadedHandler> handlersForMessage;

            var loadedHandler = new LoadedHandler
            {
                Instance = handler,
                Invocation = (handlerInstance, message) => HandlerInvocationCache.InvokeHandle(handlerInstance, message)
            };

            if (!messageHandlers.TryGetValue(messageType, out handlersForMessage))
            {
                messageHandlers[messageType] = new List<LoadedHandler> { loadedHandler };
            }
            else
            {
                handlersForMessage.Add(loadedHandler);
            }
        }
Ejemplo n.º 8
0
        // 加载AssetBundle(先从persistentData读,没有找到则从streamingAssets读)
        public void LoadBundle(string path, LoadedHandler onLoaded,
                               bool async            = true, bool persistent = false, bool manifest = true,
                               LoadPriority priority = LoadPriority.Normal)
        {
            path = path.ToLower();
            LoadAssetBundle(null, path, (group, data) => {
                AssetBundle ab = null;

                AssetBundleInfo info = data as AssetBundleInfo;
                if (info != null)
                {
                    ab = info.Bundle;
                }

                if (onLoaded != null)
                {
                    onLoaded(ab);
                }
            }, async, persistent, manifest, priority);
        }
Ejemplo n.º 9
0
        // ------------------------------------------------------------------------------------------
        // 编辑器专用加载
        // 加载Assets目录下的文件(编辑器专用,带后缀)
        public void LoadFile(string path, LoadedHandler onLoaded,
                             bool async = true, bool inData = true, LoadPriority priority = LoadPriority.Normal)
        {
#if !UNITY_EDITOR && !UNITY_STANDALONE
            Logger.LogError("LoadFile为编辑器专用方法!");
            return;
#endif

            string fullpath = string.Format("{0}/{1}", inData ? ConstantData.DataFullPath : Application.dataPath, path);
            if (!CheckFileExist(fullpath, onLoaded))
            {
                return;
            }

            m_task.AddLoadTask(null, Loader.LoaderType.Stream, fullpath, false, (group, data) => {
                if (onLoaded != null)
                {
                    onLoaded(data);
                }
            }, async, priority);
        }
Ejemplo n.º 10
0
        public void AddHandler(Type messageType, object handler)
        {
            List <LoadedHandler> handlersForMessage;

            var loadedHandler = new LoadedHandler
            {
                Instance   = handler,
                Invocation = (handlerInstance, message) => HandlerInvocationCache.InvokeHandle(handlerInstance, message)
            };

            if (!messageHandlers.TryGetValue(messageType, out handlersForMessage))
            {
                messageHandlers[messageType] = new List <LoadedHandler> {
                    loadedHandler
                };
            }
            else
            {
                handlersForMessage.Add(loadedHandler);
            }
        }
Ejemplo n.º 11
0
 public static void Load(LoadedHandler loadedHandler)
 {
     new Task(() =>
     {
         List <StickerCategory> categories = StickerAPI.GetCategories();
         foreach (StickerCategory cate in categories)
         {
             LoadedCategories.TryAdd(cate.ID, cate);
             List <Sticker> stickers = StickerAPI.GetStickerCategory(cate.ID);
             foreach (Sticker sticker in stickers)
             {
                 LoadedStickers.TryAdd(sticker.ID, sticker);
                 cate.Stickers.Add(sticker);
             }
         }
         if (loadedHandler != null)
         {
             Application.Current.Dispatcher.Invoke(() => loadedHandler());
         }
     }).Start();
 }
Ejemplo n.º 12
0
 public virtual void Dispose()
 {
     onLoader = null;
 }