Esempio n. 1
0
        public void GetResourceAsync(string path, BKAction <UnityEngine.Object> onComplete)
        {
            if (assetList.ContainsKey(path))
            {
                onComplete((assetList[path].RefTarget() as UnityEngine.Object));
                return;
            }

            var ab = GetAssetBundle(path);

            if (ab == null)
            {
                onComplete(null);
                return;
            }

            IResourceFile file = resourceTable.GetResourceFile(path);

            if (file == null)
            {
                BundleToAsset(path, file, ab, ab);
                onComplete(ab);
                return;
            }

            CoroutineMgr.StartCoroutine(DoGetResourceAsync(file, ab, onComplete));
        }
Esempio n. 2
0
        public IEnumerator Update(BKAction onComplete = null)
        {
            this.onComplete = onComplete;

            var loader = LoaderMgr.Load(localVersionPath);

            loader.isCheckRedirectError = true;

            loader.onComplete += ld =>
            {
                if (ld.hasError)
                {
                    //TODO tip
                    DoComplete(true);
                    return;
                }

                localVersion = new VersionCfgMgr();
                if (localVersion.Init(ld.text))
                {
                    LoadVersion(localVersion.versionAddr);
                }
                else
                {
                    //TODO tip
                    DoComplete(true);
                }
            };

            while (!isComplete)
            {
                yield return(null);
            }
        }
Esempio n. 3
0
        public void GetResourceAsync <T>(string path, BKAction <T> onComplete) where T : UnityEngine.Object
        {
            if (assetList.ContainsKey(path))
            {
                onComplete((T)(assetList[path].RefTarget()));
                return;
            }

            var ab = GetAssetBundle(path);

            if (ab == null)
            {
                onComplete(default(T));
                return;
            }

            IResourceFile file = resourceTable.GetResourceFile(path);

            if (file == null)
            {
                BundleToAsset(path, file, ab, ab);
                onComplete((T)Convert.ChangeType(ab, typeof(T)));
                return;
            }

            CoroutineMgr.StartCoroutine(DoGetResourceAsync <T>(file, ab, onComplete));
        }
Esempio n. 4
0
        public static int SetInterval(int frameInterval, BKAction action)
        {
            if (action == null)
            {
                return(0);
            }

            if (frameInterval <= 0)
            {
                action.Invoke();
                frameInterval = 1;
            }

            while (intervals.ContainsKey(intervalId))
            {
                intervalId++;
                if (intervalId == int.MaxValue)
                {
                    intervalId = 1;
                }
            }

            intervals.Add(intervalId, new TickItem(frameInterval, action));
            return(intervalId);
        }
Esempio n. 5
0
        IEnumerator DoGetAllResourcesAsync <T>(AssetBundle ab, BKAction <T[]> onComplete)
            where T : UnityEngine.Object
        {
            var req = ab.LoadAllAssetsAsync <T>();

            yield return(req);

            onComplete((T[])req.allAssets);
        }
Esempio n. 6
0
        public static void RemoveMessageListener(uint opcode, BKAction <IMessage> messageHanlder)
        {
            BKEvent <IMessage> item;

            if (messages.TryGetValue(opcode, out item))
            {
                item.RemoveListener(messageHanlder);
            }
        }
Esempio n. 7
0
        IEnumerator DoGetResourceAsync(IResourceFile file, AssetBundle ab, BKAction <UnityEngine.Object> onComplete)
        {
            var req = ab.LoadAssetAsync(file.idInPack, GetResourceType(file.type));

            yield return(req);

            var obj = req.asset;

            BundleToAsset(file.srcFile, file, ab, obj);
            onComplete(obj);
        }
Esempio n. 8
0
        public static void AddMessageListener(uint opcode, BKAction <IMessage> messageHanlder)
        {
            BKEvent <IMessage> item;

            if (!messages.TryGetValue(opcode, out item))
            {
                item = new BKEvent <IMessage>();
                messages.Add(opcode, item);
            }
            item.AddListener(messageHanlder);
        }
Esempio n. 9
0
        IEnumerator DoGetResourceAsync <T>(IResourceFile file, AssetBundle ab, BKAction <T> onComplete)
            where T : UnityEngine.Object
        {
            var req = ab.LoadAssetAsync <T>(file.idInPack);

            yield return(req);

            var obj = (T)req.asset;

            BundleToAsset(file.srcFile, file, ab, obj);
            onComplete(obj);
        }
Esempio n. 10
0
        public void GetAllResourcesAsync <T>(int number, BKAction <T[]> onComplete) where T : UnityEngine.Object
        {
            var file = resourceTable.GetResourceFile(number);

            if (file != null)
            {
                GetAllResourcesAsync <T>(file.srcFile, onComplete);
            }
            else
            {
                onComplete(null);
            }
        }
Esempio n. 11
0
        public void GetResourceAsync(int number, BKAction <UnityEngine.Object> onComplete)
        {
            var file = resourceTable.GetResourceFile(number);

            if (file != null)
            {
                GetResourceAsync(file.srcFile, onComplete);
            }
            else
            {
                onComplete(null);
            }
        }
Esempio n. 12
0
        public void Invoke()
        {
            if (this.action != null)
            {
                this.action.Invoke();
            }

            if (this.onceAction != null)
            {
                this.onceAction.Invoke();
                this.onceAction = null;
            }
        }
Esempio n. 13
0
        public Loader Load(string path, BKAction <string> onComplete = null,
                           bool cache = false)
        {
            var bReturn = false;

            if (string.IsNullOrEmpty(path))
            {
                bReturn = true;
                Debug.LogWarning("LocalResMgr.load, path is empty");
            }
            if (HasResource(path))
            {
                bReturn = true;
                UpdateCache(path, cache);
            }
            if (bReturn)
            {
                if (onComplete != null)
                {
                    onComplete(path);
                }
                return(null);
            }

            var file   = resourceTable.GetResourceFile(path);
            var loader = file == null?LoaderMgr.Load(path) :
                             LoaderMgr.Load(file.targetFile, file.version, file.size);

            loader.onComplete += ld =>
            {
                if (!ld.hasError)
                {
                    AddResource(path, ld.GetOrgAssetBundle(), cache);
                }

                if (onComplete != null)
                {
                    onComplete(path);
                }

                ld.Dispose();
            };

            return(loader);
        }
Esempio n. 14
0
        public void GetAllResourcesAsync <T>(string path, BKAction <T[]> onComplete) where T : UnityEngine.Object
        {
            IResourceFile file = resourceTable.GetResourceFile(path);

            if (file != null && file.singleDirectResource && assetList.ContainsKey(file.srcFile))
            {
                onComplete(new T[] { (T)assetList[file.srcFile].RefTarget() });
                return;
            }

            var ab = GetAssetBundle(path);

            if (ab == null)
            {
                return;
            }

            CoroutineMgr.StartCoroutine(DoGetAllResourcesAsync <T>(ab, onComplete));
        }
Esempio n. 15
0
 public static void GetResourceAsync <T>(int number, BKAction <T> onComplete) where T : UnityEngine.Object
 {
     impl.GetResourceAsync <T>(number, onComplete);
 }
Esempio n. 16
0
 public static void GetResourceAsync(int number, BKAction <UnityEngine.Object> onComplete)
 {
     impl.GetResourceAsync(number, onComplete);
 }
Esempio n. 17
0
 public static void GetAllResourcesAsync <T>(string path, BKAction <T[]> onComplete) where T : UnityEngine.Object
 {
     impl.GetAllResourcesAsync <T>(path, onComplete);
 }
Esempio n. 18
0
 public static void GetAllResourcesAsync(string path, BKAction <UnityEngine.Object[]> onComplete)
 {
     impl.GetAllResourcesAsync(path, onComplete);
 }
Esempio n. 19
0
 public static BatchLoader LoadBatch(ICollection <string> pathes, BKAction <ICollection <string> > onComplete = null, bool cache = false)
 {
     return(impl.LoadBatch(pathes, onComplete, cache));
 }
Esempio n. 20
0
 public static BatchLoader LoadWithDependencies(string path, BKAction <string> onComplete = null, bool cache = false)
 {
     return(impl.LoadWithDependencies(path, onComplete, cache));
 }
Esempio n. 21
0
 public static Loader Load(string path, BKAction <string> onComplete = null, bool cache = false)
 {
     return(impl.Load(path, onComplete, cache));
 }
Esempio n. 22
0
 public override void RemoveAllListeners()
 {
     this.action     = null;
     this.onceAction = null;
 }
Esempio n. 23
0
 /// <summary>
 /// remove event Listener, or BKEvent -= action
 /// </summary>
 public void RemoveListener(BKAction action)
 {
     this.action     -= action;
     this.onceAction -= action;
 }
Esempio n. 24
0
 /// <summary>
 /// action will be removed after calling once
 /// </summary>
 public void AddOnceListener(BKAction action)
 {
     this.action += action;
 }
Esempio n. 25
0
 public TickItem(int frame, BKAction action)
 {
     this.frame  = frame;
     this.action = action;
     last        = 0f;
 }
Esempio n. 26
0
        public BatchLoader LoadWithDependencies(string path, BKAction <string> onComplete = null, bool cache = false)
        {
            if (HasResource(path))
            {
                return(null);
            }

            var batch = LoaderMgr.LoadBatch();
            var file  = resourceTable.GetResourceFile(path);

            if (file == null)
            {
                batch.AddLoader(path);
            }
            else
            {
                if (file.dependencies != null)
                {
                    foreach (var filestr in file.dependencies)
                    {
                        var file2 = resourceTable.GetResourceFile(filestr);
                        if (!HasResource(file2))
                        {
                            batch.AddLoader(file2.targetFile, file2.version, file2.size);
                        }
                    }
                }

                batch.AddLoader(file.targetFile, file.version, file.size);
            }

            if (batch.GetLoaders().Count == 0)
            {
                batch.DisposeImmediate();
                if (onComplete != null)
                {
                    onComplete(path);
                }
                return(null);
            }

            batch.onComplete += bt =>
            {
                foreach (var item in bt.GetLoaders())
                {
                    if (!item.Value.hasError)
                    {
                        AddResource(item.Key, item.Value.GetOrgAssetBundle(), cache);
                    }
                }

                if (onComplete != null)
                {
                    onComplete(path);
                }

                bt.Dispose();
            };

            return(batch);
        }
Esempio n. 27
0
 public TickItem(float time, BKAction action)
 {
     this.time   = time;
     this.action = action;
     last        = Time.time;
 }