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)); }
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); }
// 从服务器下载网页内容,需提供完整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); }
/// <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()); } }
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()); } }
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); }
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); }
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); }
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); } }
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); }
// 异步请求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); }
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); }
public List <Vector2Int> Find(Vector2Int startPoint, Vector2Int goalPoint) { Reset(); // 为起点赋初值 AStarNode startNode = PoolCatManagerUtil.Spawn <AStarNode>(null, astarNode => astarNode.Init(startPoint.x, startPoint.y)); startNode.h = GetH(startPoint, goalPoint); startNode.f = startNode.h + startNode.g; AddNodeToOpenList(startNode); while (openHeap.Size > 0) { // 寻找开启列表中F值最低的格子。我们称它为当前格 AStarNode checkNode = openHeap.Pop(); // 把目标格添加进了开启列表,这时候路径被找到 if (checkNode.pos.Equals(goalPoint)) { return(Solve(checkNode)); } // 获得当前附近的节点集合 SetNeighborList(checkNode.pos); foreach (var neighborNode in neighborList) { float neighborG = checkNode.g + GetG(checkNode.pos, neighborNode.pos); if (handledDict.ContainsKey(neighborNode.pos)) { var oldNeighborNode = handledDict[neighborNode.pos]; if (neighborG < oldNeighborNode.g) { switch (handledDict[neighborNode.pos].astarInListType) { case AStarNodeInListType.Close_List: neighborNode.parent = checkNode; neighborNode.g = neighborG; neighborNode.h = GetH(neighborNode.pos, goalPoint); neighborNode.f = neighborNode.g + neighborNode.h; //更新neighbor_node的值 AddNodeToOpenList(neighborNode); oldNeighborNode.Despawn(); break; case AStarNodeInListType.Open_List: neighborNode.parent = checkNode; neighborNode.g = neighborG; neighborNode.h = GetH(neighborNode.pos, goalPoint); neighborNode.f = neighborNode.g + neighborNode.h; //更新neighbor_node的值 openHeap.Remove(oldNeighborNode); AddNodeToOpenList(neighborNode); oldNeighborNode.Despawn(); break; } } else { //舍弃的进行回收 neighborNode.Despawn(); } } else { neighborNode.parent = checkNode; neighborNode.g = neighborG; neighborNode.h = GetH(neighborNode.pos, goalPoint); neighborNode.f = neighborNode.g + neighborNode.h; AddNodeToOpenList(neighborNode); // 排序插入 } } // 把当前格切换到关闭列表 AddNodeToCloseList(checkNode); } return(null); }
public AbstractComponent AddComponentWithoutInit(string componentKey, Type componentType) { var component = PoolCatManagerUtil.Spawn(componentType) as AbstractComponent; return(AddComponent(component, componentKey)); }