Beispiel #1
0
        public AbstractEntity[] GetChildrenStrictly(Type childType)
        {
            List <AbstractEntity> list = new List <AbstractEntity>();

            try
            {
                if (!this.typeToChildListDict.ContainsKey(childType))
                {
                    return(list.ToArray());
                }
                var childList = typeToChildListDict[childType];
                for (var i = 0; i < childList.Count; i++)
                {
                    var child = childList[i];
                    if (!child.IsDestroyed())
                    {
                        list.Add(child);
                    }
                }

                return(list.ToArray());
            }
            finally
            {
                list.Clear();
                PoolCatManagerUtil.Despawn(list);
            }
        }
Beispiel #2
0
        public Action <P0, P1> AddListener(string eventName, Action <P0, P1> handler)
        {
            var handlerInfo = PoolCatManagerUtil.Spawn <KeyValuePairCat <Action <P0, P1>, bool> >().Init(handler, true);

            listenerDict.Add(eventName, handlerInfo);
            return(handler);
        }
Beispiel #3
0
 protected override void OnDone()
 {
     base.OnDone();
     Broadcast(null, AssetBundleEventNameConst.On_AssetBundleAsyncLoader_Done, this);
     this.Destroy();
     PoolCatManagerUtil.Despawn(this);
 }
        public AbstractEntity AddChildWithoutInit(string childKey, Type childType)
        {
            if (childKey != null && keyToChildDict.ContainsKey(childKey))
            {
                LogCat.error("duplicate add child:{0},{1}", childKey, childType);
                return(null);
            }

            bool isKeyUsingParentIdPool = childKey == null;

            if (isKeyUsingParentIdPool)
            {
                childKey = childKeyIdPool.Get().ToString();
                //再次检查键值
                if (keyToChildDict.ContainsKey(childKey))
                {
                    LogCat.error("duplicate add child:{0},{1}", childKey, childType);
                    return(null);
                }
            }

            var child = PoolCatManagerUtil.Spawn(childType) as AbstractEntity;

            child.key = childKey;
            child.isKeyUsingParentIdPool = isKeyUsingParentIdPool;
            return(AddChild(child));
        }
Beispiel #5
0
 public string KK()
 {
     using (var scope = PoolCatManagerUtil.SpawnScope <StringBuilderScope>(s => s.Init(5)))
     {
         scope.stringBuilder.Append("4566");
         return(scope.stringBuilder.ToString());
     }
 }
Beispiel #6
0
        // 从服务器下载网页内容,需提供完整url,非AB(不计引用计数、不缓存),Creater使用后记得回收
        public ResourceWebRequester DownloadFileAsyncNoCache(string url)
        {
            var resourceWebRequester = PoolCatManagerUtil.Spawn <ResourceWebRequester>();

            resourceWebRequester.Init(url, true);
            resourceWebRequesterAllDict[url] = resourceWebRequester;
            resourceWebRequesterWaitingQueue.Enqueue(resourceWebRequester);
            return(resourceWebRequester);
        }
 public void Reset()
 {
     onSuccessCallback = null;
     onFailCallback    = null;
     onDoneCallback    = null;
     if (_resultInfo != null)
     {
         PoolCatManagerUtil.Despawn(_resultInfo);
     }
     _resultInfo = null;
 }
Beispiel #8
0
        public IEnumerator Initialize()
        {
            if (Application.isEditor && EditorModeConst.IsEditorMode)
            {
                yield break;
            }

            manifest       = new Manifest();
            assetPathMap   = new AssetPathMap();
            assetBundleMap = new AssetBundleMap();

            // 说明:同时请求资源可以提高加载速度
            var manifestRequest =
                DownloadFileAsyncNoCache(
                    manifest.assetBundleName.WithRootPath(FilePathConst.PersistentAssetBundleRoot));
            var assetPathMapRequest =
                DownloadFileAsyncNoCache(
                    BuildConst.AssetPathMap_File_Name.WithRootPath(FilePathConst.PersistentAssetBundleRoot));
            var assetBundleMapRequest =
                DownloadFileAsyncNoCache(
                    BuildConst.AssetBundleMap_File_Name.WithRootPath(FilePathConst.PersistentAssetBundleRoot));

            yield return(manifestRequest);

            if (manifestRequest.error.IsNullOrWhiteSpace())
            {
                var assetBundle = manifestRequest.assetBundle;
                manifest.LoadFromAssetBundle(assetBundle);
                assetBundle.Unload(false);
                manifestRequest.Destroy();
                PoolCatManagerUtil.Despawn(manifestRequest);
            }


            yield return(assetPathMapRequest);

            if (assetPathMapRequest.error.IsNullOrWhiteSpace())
            {
                assetPathMap.Initialize(assetPathMapRequest.text);
                assetPathMapRequest.Destroy();
                PoolCatManagerUtil.Despawn(assetPathMapRequest);
            }

            yield return(assetBundleMapRequest);

            if (assetBundleMapRequest.error.IsNullOrWhiteSpace())
            {
                assetBundleMap.Initialize(assetBundleMapRequest.text);
                assetBundleMapRequest.Destroy();
                PoolCatManagerUtil.Despawn(assetBundleMapRequest);
            }

            LogCat.Log("AssetMananger init finished");
        }
Beispiel #9
0
        /// <summary>
        /// duration needRunCount 里面随便一个触碰底线都会结束
        /// </summary>
        /// <param name="func">返回false表示不继续执行,结束</param>
        /// <param name="interval">触发间隔  0 每帧都触发</param>
        /// <param name="needRunCount">触发次数 0:一直触发</param>
        /// <param name="duration">整个过程的时间 不会包含delay</param>
        /// <param name="delay">第一次的延迟时间</param>
        /// <param name="mode"></param>
        /// <param name="parent"></param>
        /// <param name="priority"></param>
        public Timer AddTimer(Func <object[], bool> updateFunc, float delay = 0, float interval = 0,
                              int needRunCount         = 0,
                              UpdateModeCat updateMode = UpdateModeCat.Update, bool isUseUnscaledDeltaTime = false, int priority = 1,
                              params object[] updateFuncArgs)
        {
            Timer timer = PoolCatManagerUtil.Spawn <Timer>();

            timer.Init(updateFunc, delay, interval, needRunCount, updateMode, isUseUnscaledDeltaTime,
                       priority, updateFuncArgs);
            return(AddTimer(timer));
        }
 void __AddChildRelationship(AbstractEntity child)
 {
     keyToChildDict[child.key] = child;
     typeToChildListDict.GetOrAddDefault(child.GetType(), () => PoolCatManagerUtil.Spawn <List <AbstractEntity> >())
     .Add(child);
     childKeyList.Add(child.key);
     if (!childTypeList.Contains(child.GetType()))
     {
         childTypeList.Add(child.GetType());
     }
 }
Beispiel #11
0
 void _AddComponentRelationship(AbstractComponent component)
 {
     keyToComponentDict[component.key] = component;
     typeToComponentListDict.GetOrAddDefault(component.GetType(),
                                             () => PoolCatManagerUtil.Spawn <List <AbstractComponent> >())
     .Add(component);
     componentKeyList.Add(component.key);
     if (!componentTypeList.Contains(component.GetType()))
     {
         componentTypeList.Add(component.GetType());
     }
 }
Beispiel #12
0
        void _OnDespawn_Component()
        {
            keyToComponentDict.Clear();
            foreach (var componentList in typeToComponentListDict.Values)
            {
                componentList.Clear();
                PoolCatManagerUtil.Despawn(componentList);
            }

            typeToComponentListDict.Clear();
            componentKeyList.Clear();
            componentTypeList.Clear();
        }
Beispiel #13
0
        public IEnumerator LoadAssetPathMap()
        {
            var assetPathMapRequestUrl = BuildConst.AssetPathMap_File_Name.WithRootPath(urlRoot);
            var assetPathMapRequest    = Client.instance.assetBundleManager.DownloadFileAsyncNoCache(assetPathMapRequestUrl);

            yield return(assetPathMapRequest);

            if (assetPathMapRequest.error.IsNullOrWhiteSpace())
            {
                assetPathMap.Initialize(assetPathMapRequest.text);
            }
            assetPathMapRequest.Destroy();
            PoolCatManagerUtil.Despawn(assetPathMapRequest);
        }
Beispiel #14
0
        public IEnumerator LoadResVersion()
        {
            var resVersionRequestUrl = BuildConst.ResVersionFileName.WithRootPath(urlRoot);
            var resVersionRequest    = Client.instance.assetBundleManager.DownloadFileAsyncNoCache(resVersionRequestUrl);

            yield return(resVersionRequest);

            if (resVersionRequest.error.IsNullOrWhiteSpace())
            {
                resVersion = resVersionRequest.text;
            }
            resVersionRequest.Destroy();
            PoolCatManagerUtil.Despawn(resVersionRequest);
        }
        private void OnAssetAsyncLoaderDone(AssetAsyncLoader assetAsyncLoader)
        {
            if (!assetAsyncloaderProcessingList.Contains(assetAsyncLoader))
            {
                return;
            }

            //解除对assetAsyncLoader的引用
            assetAsyncLoader.assetCat.SubRefCount();

            assetAsyncloaderProcessingList.Remove(assetAsyncLoader);
            assetAsyncLoader.Destroy();
            PoolCatManagerUtil.Despawn(assetAsyncLoader);
        }
Beispiel #16
0
        public IEnumerator LoadAssetPathRefContentJson()
        {
            var assetPathRefContentJsonRequestURL        = AssetPathRefConst.SaveFileName.WithRootPath(urlRoot);
            var assetPathRefContentJsonRequestURLRequest =
                Client.instance.assetBundleManager.DownloadFileAsyncNoCache(assetPathRefContentJsonRequestURL);

            yield return(assetPathRefContentJsonRequestURLRequest);

            if (assetPathRefContentJsonRequestURLRequest.error.IsNullOrWhiteSpace())
            {
                assetPathRefContentJson = assetPathRefContentJsonRequestURLRequest.text;
            }
            assetPathRefContentJsonRequestURLRequest.Destroy();
            PoolCatManagerUtil.Despawn(assetPathRefContentJsonRequestURLRequest);
        }
        public void RemoveAllChildren()
        {
            var toRemoveChildKeyList = PoolCatManagerUtil.Spawn <List <string> >();

            toRemoveChildKeyList.Capacity = this.childKeyList.Count;
            toRemoveChildKeyList.AddRange(this.childKeyList);
            for (var i = 0; i < toRemoveChildKeyList.Count; i++)
            {
                var childKey = toRemoveChildKeyList[i];
                RemoveChild(childKey);
            }

            toRemoveChildKeyList.Clear();
            PoolCatManagerUtil.Despawn(toRemoveChildKeyList);
        }
        public void RemoveAllComponents()
        {
            var toRemoveComponentKeyList = PoolCatManagerUtil.Spawn <List <string> >();

            toRemoveComponentKeyList.Capacity = this.componentKeyList.Count;
            toRemoveComponentKeyList.AddRange(componentKeyList);
            for (var i = 0; i < toRemoveComponentKeyList.Count; i++)
            {
                var componentKey = toRemoveComponentKeyList[i];
                RemoveComponent(componentKey);
            }

            toRemoveComponentKeyList.Clear();
            PoolCatManagerUtil.Despawn(toRemoveComponentKeyList);
        }
Beispiel #19
0
        void _OnDespawn_Child()
        {
            keyToChildDict.Clear();
            foreach (var childList in typeToChildListDict.Values)
            {
                childList.Clear();
                PoolCatManagerUtil.Despawn(childList);
            }

            typeToChildListDict.Clear();
            childKeyList.Clear();
            childTypeList.Clear();
            _parent = null;
            isKeyUsingParentIdPool = false;
        }
Beispiel #20
0
        /// <summary>
        /// 添加到对应的TimerList中
        /// </summary>
        /// <param name="timer"></param>
        public void RemoveTimer(Timer timer, int?index = null)
        {
            List <Timer> timerList = this.GetTimerList(timer.updateMode);

            if (index != null)
            {
                timerList.RemoveAt(index.Value);
            }
            else
            {
                timerList.Remove(timer);
            }

            timer.Finish();
            PoolCatManagerUtil.Despawn(timer);
        }
Beispiel #21
0
        public IEnumerator LoadManifest()
        {
            var manifestRequestURL = BuildConst.ManifestBundle_Path.WithRootPath(urlRoot);

            manifestRequest = Client.instance.assetBundleManager.DownloadFileAsyncNoCache(manifestRequestURL);
            yield return(manifestRequest);

            if (manifestRequest.error.IsNullOrWhiteSpace())
            {
                manifest.LoadFromAssetBundle(manifestRequest.assetBundle);
                manifest.SaveBytes(manifestRequest.bytes);
                manifestRequest.assetBundle.Unload(false);
            }

            manifestRequest.Destroy();
            PoolCatManagerUtil.Despawn(manifestRequest);
        }
Beispiel #22
0
        protected void AddNeighbor(List <AStarNode> neighborList, Vector2Int basePoint, int dx, int dy)
        {
            int newX = basePoint.x + dx;
            int newY = basePoint.y + dy;

            // 测试边界
            if (!IsInRange(newX, newY))
            {
                return;
            }

            // 跳过不能通过的障碍
            if (!CanPass(newX, newY))
            {
                return;
            }

            // 当前点(p.x,p.y)与该检测邻居点(new_x,new_y)如果是斜线的话, 垂直于当前点(p.x,p.y)与该检测邻居点(new_x,new_y)对角线的两个点中其中一个是阻挡的,则该检测邻居点忽略,不考虑
            // 判断左上角邻居节点
            if (dx == -1 && dy == 1 && IsSkiped(DirectionInfoUtil.GetDirectionInfo(dx, dy), newX, newY))
            {
                return;
            }

            // 判断左下角邻居节点
            if (dx == -1 && dy == -1 && IsSkiped(DirectionInfoUtil.GetDirectionInfo(dx, dy), newX, newY))
            {
                return;
            }

            // 判断右上角邻居节点
            if (dx == 1 && dy == 1 && IsSkiped(DirectionInfoUtil.GetDirectionInfo(dx, dy), newX, newY))
            {
                return;
            }

            // 判断右下角邻居节点
            if (dx == 1 && dy == -1 && IsSkiped(DirectionInfoUtil.GetDirectionInfo(dx, dy), newX, newY))
            {
                return;
            }

            var neighbor_node = PoolCatManagerUtil.Spawn <AStarNode>(null, astarNode => astarNode.Init(newX, newY));

            neighborList.Add(neighbor_node);
        }
Beispiel #23
0
        public AbstractEntity[] GetChildren(Type childType)
        {
            List <AbstractEntity> list = PoolCatManagerUtil.Spawn <List <AbstractEntity> >();

            try
            {
                foreach (var child in ForeachChild(childType))
                {
                    list.Add(child);
                }
                return(list.ToArray());
            }
            finally
            {
                list.Clear();
                PoolCatManagerUtil.Despawn(list);
            }
        }
Beispiel #24
0
 private void OnResourceWebRequesterDone(ResourceWebRequester resourceWebRequester)
 {
     if (!resourceWebRequesterProcessingList.Contains(resourceWebRequester))
     {
         return;
     }
     resourceWebRequesterProcessingList.Remove(resourceWebRequester);
     resourceWebRequesterAllDict.RemoveByFunc((k, v) => v == resourceWebRequester);
     // 无缓存,不计引用计数、Creater使用后由上层回收,所以这里不需要做任何处理
     if (!resourceWebRequester.isNotCache)
     {
         var assetBundleCat = resourceWebRequester.assetBundleCat;
         // 解除webRequester对AB持有的引用
         assetBundleCat?.SubRefCount();
         resourceWebRequester.Destroy();
         PoolCatManagerUtil.Despawn(resourceWebRequester);
     }
 }
Beispiel #25
0
        //max_reload_count 失败的重新load的最大次数
        public IEnumerator DownloadFileAsync(string downloadURL, string filePath, int maxReloadCount, int curReloadCount = 0)
        {
            var resourceWebRequester = DownloadFileAsyncNoCache(downloadURL, filePath);

            curReloadCount++;
            yield return(resourceWebRequester);

            while (curReloadCount < maxReloadCount)
            {
                if (!resourceWebRequester.error.IsNullOrWhiteSpace())
                {
                    LogCat.LogError(resourceWebRequester.error);
                    resourceWebRequester.Destroy();
                    PoolCatManagerUtil.Despawn(resourceWebRequester);
                    resourceWebRequester = DownloadFileAsyncNoCache(downloadURL, filePath);
                    yield return(resourceWebRequester);
                }
                curReloadCount++;
            }
        }
Beispiel #26
0
        private bool CreateAssetBundleAsync(string assetBundleName)
        {
            if (__IsAssetBundleLoadSuccess(assetBundleName) || resourceWebRequesterAllDict.ContainsKey(assetBundleName))
            {
                return(false);
            }


            // webRequester持有的引用,webRequester结束后会删除该次引用(在AssetBunldeMananger中的OnProsessingWebRequester的进行删除本次引用操作)
            var assetBundleCat = new AssetBundleCat(assetBundleName);

            assetBundleCat.AddRefCount();
            AddAssetBundleCat(assetBundleCat);

            var resourceWebRequester = PoolCatManagerUtil.Spawn <ResourceWebRequester>();
            var url = assetBundleName.WithRootPath(FilePathConst.PersistentAssetBundleRoot);

            resourceWebRequester.Init(assetBundleCat, url);
            resourceWebRequesterAllDict[assetBundleName] = resourceWebRequester;
            resourceWebRequesterWaitingQueue.Enqueue(resourceWebRequester);

            return(true);
        }
Beispiel #27
0
        // 异步请求Assetbundle资源
        private BaseAssetBundleAsyncLoader __LoadAssetBundleAsync(string assetBundleName)
        {
            if (Application.isEditor && EditorModeConst.IsEditorMode)
            {
                return(new EditorAssetBundleAsyncLoader(assetBundleName));
            }

            var assetBundleAsyncLoader = PoolCatManagerUtil.Spawn <AssetBundleAsyncLoader>();

            assetBundleAsyncLoaderProcessingList.Add(assetBundleAsyncLoader);
            var dependanceNames = manifest.GetAllDependencies(assetBundleName);
            List <AssetBundleCat> dependanceAssetBundleCatList = new List <AssetBundleCat>();

            for (var i = 0; i < dependanceNames.Length; i++)
            {
                var dependanceName = dependanceNames[i];
                CreateAssetBundleAsync(dependanceName);
                var dependanceAssetBundleCat = __GetAssetBundleCat(dependanceName);
                // A依赖于B,A对B持有引用
                dependanceAssetBundleCat.AddRefCount();
                dependanceAssetBundleCatList.Add(dependanceAssetBundleCat);
            }

            CreateAssetBundleAsync(assetBundleName);
            var assetBundleCat = __GetAssetBundleCat(assetBundleName);

            for (var i = 0; i < dependanceAssetBundleCatList.Count; i++)
            {
                var dependanceAssetBundleCat = dependanceAssetBundleCatList[i];
                assetBundleCat.AddDependenceAssetBundleCat(dependanceAssetBundleCat);
            }

            assetBundleAsyncLoader.Init(assetBundleCat);
            // 添加assetBundleAsyncLoader加载器对AB持有的引用,assetBundleAsyncLoader结束后会删除该次引用(在AssetBunldeMananger中的OnProsessingAssetBundleAsyncLoader的进行删除本次引用操作)
            assetBundleCat.AddRefCount();
            return(assetBundleAsyncLoader);
        }
Beispiel #28
0
        private void OnResourceWebRequesterDone(ResourceWebRequester resourceWebRequester)
        {
            //    LogCat.LogError("kkkkkkkkkkkkkkk:"+resourceWebRequester.url);
            if (!downloadingRequestList.Contains(resourceWebRequester))
            {
                return;
            }

            if (!resourceWebRequester.error.IsNullOrWhiteSpace())
            {
                LogCat.LogError("Error when downloading file : " + resourceWebRequester.cache.Get <string>("file_path") +
                                "\n from url : " +
                                resourceWebRequester.url + "\n err : " + resourceWebRequester.error);
                needDownloadList.Add(resourceWebRequester.cache.Get <string>("file_path"));
            }
            else
            {
                downloadingRequestList.Remove(resourceWebRequester);
                needDownloadDict[resourceWebRequester.cache.Get <string>("file_path")]["is_finished"]     = true;
                needDownloadDict[resourceWebRequester.cache.Get <string>("file_path")]["downloded_bytes"] =
                    needDownloadDict[resourceWebRequester.cache.Get <string>("file_path")]["total_bytes"];
                var filePath = resourceWebRequester.cache.Get <string>("file_path")
                               .WithRootPath(FilePathConst.PersistentAssetBundleRoot);
                StdioUtil.WriteFile(filePath, resourceWebRequester.bytes);
            }

            resourceWebRequester.Destroy();
            PoolCatManagerUtil.Despawn(resourceWebRequester);

            //    LogCat.LogError("ffffffffffffaaaaaaa:"+downloadingRequest.Count);
            //    LogCat.LogError("ffffffffffffbbbbbbb:" + needDownloadList.Count);
            if (downloadingRequestList.Count == 0 && needDownloadList.Count == 0)
            {
                isUpdatingRes = false;
            }
        }
        public BaseAssetAsyncLoader LoadAssetAsync(string assetPath, Action <AssetCat> onLoadSuccessCallback = null,
                                                   Action <AssetCat> onLoadFailCallback = null, Action <AssetCat> onLoadDoneCallback = null,
                                                   object callbackCause = null)
        {
            AssetCat assetCat;

            if (Application.isEditor && EditorModeConst.IsEditorMode ||
                assetPath.Contains(FilePathConst.ResourcesFlag)
                )
            {
                assetCat = __GetOrAddAssetCat(assetPath);
                onLoadSuccessCallback?.Invoke(assetCat);
                onLoadDoneCallback?.Invoke(assetCat);
                return(new EditorAssetAsyncLoader(assetCat));
            }

            var assetBundleName = assetPathMap.GetAssetBundleName(assetPath);

            if (assetBundleName == null)
            {
                LogCat.error(string.Format("{0}没有设置成ab包", assetPath));
            }

            if (assetCatDict.ContainsKey(assetPath))
            {
                assetCat = GetAssetCat(assetPath);
                //已经加载成功
                if (assetCat.IsLoadSuccess())
                {
                    onLoadSuccessCallback?.Invoke(assetCat);
                    onLoadDoneCallback?.Invoke(assetCat);
                    return(null);
                }

                //加载中
                assetCat.AddOnLoadSuccessCallback(onLoadSuccessCallback, callbackCause);
                assetCat.AddOnLoadFailCallback(onLoadFailCallback, callbackCause);
                assetCat.AddOnLoadDoneCallback(onLoadDoneCallback, callbackCause);
                return(assetAsyncloaderProcessingList.Find(assetAsyncloader =>
                                                           assetAsyncloader.assetCat.assetPath.Equals(assetPath)));
            }

            //没有加载
            var assetAsyncLoader = PoolCatManagerUtil.Spawn <AssetAsyncLoader>();

            assetCat = new AssetCat(assetPath);
            __AddAssetCat(assetPath, assetCat);
            //添加对assetAsyncLoader的引用
            assetCat.AddRefCount();
            assetCat.AddOnLoadSuccessCallback(onLoadSuccessCallback, callbackCause);
            assetCat.AddOnLoadFailCallback(onLoadFailCallback, callbackCause);
            assetCat.AddOnLoadDoneCallback(onLoadDoneCallback, callbackCause);

            var assetBundleLoader = __LoadAssetBundleAsync(assetBundleName);

            assetAsyncLoader.Init(assetCat, assetBundleLoader);
            //asset拥有对assetBundle的引用
            var assetBundleCat = assetBundleLoader.assetBundleCat;

            assetBundleCat.AddRefCount();

            assetCat.assetBundleCat = assetBundleCat;

            assetAsyncloaderProcessingList.Add(assetAsyncLoader);
            return(assetAsyncLoader);
        }
Beispiel #30
0
 public static void Despawn(this object self)
 {
     PoolCatManagerUtil.Despawn(self);
 }