/// <summary> /// create new edge if it not exist /// </summary> public EdgeTemp this[int volume, int hash] { get { VectorInt.Vector2Int key = new VectorInt.Vector2Int(volume, hash); EdgeTemp result; if (edges.TryGetValue(key, out result) == false) { result = new EdgeTemp(this, volume, hash); result.SetFlag(EdgeTempFlags.Directed, true); edges[key] = result; } return(result); } set { edges[new VectorInt.Vector2Int(volume, hash)] = value; } }
public static T[][] Take(VectorInt.Vector2Int size) { T[][] result = null; lock (poolDictionary) { Stack <T[][]> stack; if (poolDictionary.TryGetValue(size, out stack) == false) { stack = new Stack <T[][]>(); poolDictionary.Add(size, stack); for (int i = 0; i < INITIAL_POOL_SIZE; i++) { stack.Push(Create(size)); } } result = stack.Count > 0 ? stack.Pop() : Create(size); } return(result); }
public static ShapeCollector GetFromPool(VectorInt.Vector2Int size, NavMeshTemplateCreation template) { ShapeCollector result = null; lock (poolDictionary) { Stack <ShapeCollector> stack; if (poolDictionary.TryGetValue(size, out stack) == false) { stack = new Stack <ShapeCollector>(); poolDictionary.Add(size, stack); for (int i = 0; i < INITIAL_POOL_SIZE; i++) { stack.Push(new ShapeCollector(size)); } } result = stack.Count > 0 ? stack.Pop() : new ShapeCollector(size); } result.Init(template); return(result); }
private void CheckChunkPath() { Vector3 closestPos; GetChunkValues(end_v3, out endGraph, out endCell, out closestPos, snapToNavMesh); #if UNITY_EDITOR if (Debuger_K.debugPath) { Debuger_K.AddLine(end_v3, closestPos, Color.red); Debuger_K.AddLine(end_v3, endCell.centerV3, Color.cyan); } #endif end_v3 = closestPos; if (PathFinder.ToChunkPosition(start_v3) == PathFinder.ToChunkPosition(end_v3)) { return; } VectorInt.Vector2Int targetPosition = endGraph.positionChunk; ClearGraphList(); AddGraphNode(new GraphPathSimple(startGraph, Vector2.Distance(start_v3, end_v3))); HashSet <Graph> usedGraphs = new HashSet <Graph>(); for (int v = 0; v < 10; v++) { if (base.linkedGraph.Count == 0) { UnityEngine.Debug.Log("no path. count"); break; } GraphPathSimple current = TakeGraphNode(); Graph currentGraph = current.graph; //Debuger3.AddLine(start_v3, currentGraph.positionWorldCenter, Color.red); //Debuger3.AddLabel(currentGraph.positionWorldCenter, linkedGrap.Count); if (currentGraph.positionChunk == targetPosition) { break; } for (int dir = 0; dir < 4; dir++) { Graph neighbourGraph; while (true) { if (PathFinder.GetGraphFrom(currentGraph.gridPosition, (Directions)dir, properties, out neighbourGraph) && neighbourGraph.canBeUsed) { break; } Thread.Sleep(10); } if (neighbourGraph != null && usedGraphs.Contains(neighbourGraph) == false) { AddGraphNode(new GraphPathSimple(neighbourGraph, Vector3.Distance(end_v3, neighbourGraph.positionCenter))); usedGraphs.Add(neighbourGraph); } } } if (endGraph == null) { Debug.LogWarning("graph path > 500"); Debug.LogWarning("chunk path result are null"); return; } }
private static T[][] Create(VectorInt.Vector2Int size) { return(Create(size.x, size.y)); }
public void SetPosition(VectorInt.Vector2Int mapPos, Vector3 pos) { mapX = mapPos.x; mapZ = mapPos.y; SetPosition(pos); }
private ShapeCollector(VectorInt.Vector2Int size) { this.sizeX = size.x; this.sizeZ = size.y; this.size = size; }