public GeneralXZData(XZPosInt chunkPos, AgentProperties properties) { this.gridPosition = chunkPos; this.properties = properties; if (properties == null) { throw new NullReferenceException("Agent properties can't be null when creating GeneralXZData"); } }
public static void RemoveGraph(Bounds bounds, AgentProperties properties, bool createNewGraphAfter = true) { float offset = properties.radius * properties.offsetMultiplier; Vector3 v3Offset = new Vector3(offset, 0, offset); XZPosInt min = ToChunkPosition(bounds.min - v3Offset); XZPosInt max = ToChunkPosition(bounds.max + v3Offset); VectorInt.Vector2Int size = new VectorInt.Vector2Int(Math.Max(1, max.x - min.x + 1), Math.Max(1, max.z - min.z + 1)); RemoveGraph(min.x, min.z, properties, size.x, size.y, createNewGraphAfter); }
//remove graph //function to remove graph at some space //IMPORTANT: if bool createNewGraphAfter == true then pathfinder are also add this graph to generation queue after it was removed public static void RemoveGraph(XZPosInt pos, AgentProperties properties, bool createNewGraphAfter = true) { Init(); if (_acceptingWork == false) { return; } lock (_allTemplatesDestructive) { if (_allTemplatesDestructive.Exists(x => x.Match(pos, properties))) { return; //already in progress } } Graph graph; if (TryGetGraph(pos, properties, out graph)) { TemplateChunkDisconnection template = new TemplateChunkDisconnection(graph); _allTemplatesDestructive.Add(template); template.SetCallBack(() => { #if UNITY_EDITOR Debuger_K.UpdateSceneImportantThings(); Debuger_K.ClearChunksDebug(pos.x, pos.z, properties); #endif lock (_chunkData) { _chunkData.Remove(new GeneralXZData(pos, properties)); } _allTemplatesDestructive.Remove(template); if (createNewGraphAfter) { QueueNavMeshTemplateToPopulation(pos, properties); } }); _disconnectionQueue.Enqueue(template); } }
//give me Graph public static bool GetGraph(XZPosInt pos, AgentProperties properties, out Graph graph) { Init(); lock (_chunkData) { GeneralXZData key = new GeneralXZData(pos, properties); if (_chunkData.TryGetValue(key, out graph)) { return(true); } else { if (AreTemplateInProcess(pos, properties) == false) { QueueNavMeshTemplateToPopulation(pos, properties); } return(false); } } }
private static void QueueNavMeshTemplateToPopulation(XZPosInt pos, AgentProperties properties) { if (_acceptingWork == false) { return; } //Debug.Log("queue 1 " + pos); NavMeshTemplateRecast template = new NavMeshTemplateRecast(_chunkRange, pos, properties); Action <Graph> callBack = (Graph graph) => { //Debug.Log("callback 1 " + pos); QueueFinishGraphInMainThread(graph); }; template.SetCallBack(callBack); _allTemplatesCreative[new GeneralXZData(pos, properties)] = template; lock (_navMeshTemplateQueue) _navMeshTemplateQueue.Enqueue(template); }
public static bool TryGetGraphFrom(XZPosInt pos, Directions direction, AgentProperties properties, out Graph graph) { switch (direction) { case Directions.xPlus: return(TryGetGraph(pos.x + 1, pos.z, properties, out graph)); case Directions.xMinus: return(TryGetGraph(pos.x - 1, pos.z, properties, out graph)); case Directions.zPlus: return(TryGetGraph(pos.x, pos.z + 1, properties, out graph)); case Directions.zMinus: return(TryGetGraph(pos.x, pos.z - 1, properties, out graph)); default: Debug.LogError("defaul direction are not exist"); graph = null; return(false); } }
public GeneralXZData(int x, int z, AgentProperties properties) { this.chunkPos = new XZPosInt(x, z); this.properties = properties; }
public GeneralXZData(XZPosInt chunkPos, AgentProperties properties) { this.chunkPos = chunkPos; this.properties = properties; }
public ChunkData(XZPosInt pos, YRangeInt range) : this(pos.x, pos.z, range.min, range.max) { }
void OnSceneGUI(SceneView sceneView) { Event curEvent = Event.current; Color col = Handles.color; Handles.color = Color.red; //float gs = settings.gridSize; AreaPointer targetData = settings.areaPointer * settings.gridSize; bool isMoved; targetData = MyHandles.DrawData(targetData, 2.5f, settings.gridSize, out isMoved); if (PathFinderSettings.isAreaPointerMoving) { settings.areaPointer = targetData / settings.gridSize; EditorUtility.SetDirty(settings); SceneView.RepaintAll(); } if (curEvent.type == EventType.Used) { PathFinderSettings.isAreaPointerMoving = isMoved; } Handles.color = col; if (sellectorMove) { XZPosInt pointerPos; RaycastHit hit; Ray ray = HandleUtility.GUIPointToWorldRay(curEvent.mousePosition); if (Physics.Raycast(ray, out hit)) { pointerPos = PathFinder.ToChunkPosition(hit.point); } else { Vector3 intersection; if (Math3d.LinePlaneIntersection(out intersection, ray.origin, ray.direction, Vector3.up, new Vector3())) { pointerPos = PathFinder.ToChunkPosition(intersection); } else { pointerPos = new XZPosInt(); } } settingsDrawer.MovePointer(new AreaPointer(pointerPos.x, pointerPos.z, pointerPos.x + 1, pointerPos.z + 1, hit.point.y)); if (curEvent.type == EventType.MouseDown && curEvent.button == 0) { sellectorMove = false; } Repaint(); SceneView.RepaintAll(); } //if (RVOPF.RVOSimulator.instance.debug) { // foreach (var cone in RVOPF.RVOSimulator.instance.collisionCones) { // if (cone.agent == null | cone.other == null) // continue; // Vector3 offset = new Vector3(0, cone.heightOffset, 0); // Vector3 agentPos = cone.agent.positionV3 + offset; // float agentY = agentPos.y; // Vector3 conePos = new Vector3(cone.position.x, agentY, cone.position.y); // Vector3 coneDir = new Vector3(cone.direction.x, agentY, cone.direction.y); // Handles.color = Color.green; // Handles.DrawLine(agentPos, conePos); // Handles.color = Color.red; // Handles.DrawLine(cone.other.positionV3, conePos); // Handles.color = new Color(cone.color.r, cone.color.g, cone.color.b, 0.1f); // Handles.DrawLine(conePos, conePos + coneDir); // float v = Vector2.SignedAngle(Vector2.up, cone.direction); // Quaternion q1 = Quaternion.AngleAxis(v, new Vector3(0, 0, 1)); // Quaternion q2 = Quaternion.AngleAxis(v + cone.angle, new Vector3(0, 0, 1)); // Quaternion q3 = Quaternion.AngleAxis(v - cone.angle, new Vector3(0, 0, 1)); // float targetDistance = Vector2.Distance(cone.agent.positionV2, cone.other.positionV2) + cone.other.radius + cone.agent.radius; // Vector2 P1 = q1 * Vector2.up * targetDistance; // Vector2 P2 = q2 * Vector2.up * targetDistance; // Vector2 P3 = q3 * Vector2.up * targetDistance; // Handles.DrawSolidArc(conePos, Vector3.up, new Vector3(P2.x, 0, P2.y), cone.angle * 2, targetDistance); // Handles.color = cone.color; // Handles.DrawLine(conePos, conePos + new Vector3(P2.x, 0, P2.y)); // Handles.DrawLine(conePos, conePos + new Vector3(P3.x, 0, P3.y)); // Handles.color = Color.black; // Handles.DrawWireDisc(cone.other.positionV3 + offset, Vector3.up, cone.other.radius); // Handles.DrawWireDisc(cone.other.positionV3 + offset, Vector3.up, cone.other.radius + cone.agent.radius); // Handles.DrawLine(cone.other.positionV3, cone.other.positionV3 + offset); // } //} Debuger_K.DrawDebugLabels(); Handles.BeginGUI(); Debuger_K.DrawSceneGUI(); Handles.EndGUI(); }
public NavMeshTemplateRecast(Dictionary <XZPosInt, YRangeInt> chunkRange, XZPosInt gridPosition, AgentProperties properties) : base(gridPosition, properties) { this.chunkRange = chunkRange; }
//try give me Graph public static bool TryGetGraph(XZPosInt pos, AgentProperties properties, out Graph graph) { return(_chunkData.TryGetValue(new GeneralXZData(pos, properties), out graph)); }
private static bool AreTemplateInProcess(XZPosInt position, AgentProperties properties) { lock (_allTemplatesCreative) { return(_allTemplatesCreative.ContainsKey(new GeneralXZData(position, properties))); } }
public bool Match(XZPosInt gridPosition, AgentProperties properties) { return(this.gridPosition == gridPosition && this.properties == properties); }
public NavMeshTemplateCreation(Dictionary <XZPosInt, YRangeInt> chunkRange, AreaPassabilityHashData hashData, XZPosInt gridPosition, AgentProperties properties) { this.gridPosition = gridPosition; this.hashData = hashData; this.properties = properties; this.chunkRange = chunkRange; }
public static void QueueGraph(XZPosInt pos, VectorInt.Vector2Int size, AgentProperties properties) { QueueGraph(pos.x, pos.z, properties, size.x, size.y); }
public static void QueueGraph(XZPosInt pos, AgentProperties properties) { QueueGraph(pos.x, pos.z, properties); }
public WorkTemplate(XZPosInt gridPosition, AgentProperties properties) { this.stop = false; this.gridPosition = gridPosition; this.properties = properties; }
public ChunkData(XZPosInt pos) : this(pos.x, pos.z, 0, 0) { }
public NavMeshTemplateDestruction(XZPosInt pos, AgentProperties properties, bool queueNewGraphAfter) : this(new GeneralXZData(pos, properties), properties) { }
public static void Deserialize(SerializedNavmesh target, AgentProperties properties) { //remove all data if it exist lock (_chunkData) { List <XZPosInt> removeList = new List <XZPosInt>(); foreach (var graph in _chunkData.Values) { if (graph.properties == properties) { removeList.Add(graph.gridPosition); } } foreach (var pos in removeList) { _chunkData.Remove(new GeneralXZData(pos, properties)); } NavmeshLayerDeserializer deserializer = new NavmeshLayerDeserializer(target, properties); var deserializedStuff = deserializer.Deserialize(); //create chunk if needed and clamp size if it outside foreach (var deserialized in deserializedStuff) { XZPosInt pos = deserialized.chunkPosition; YRangeInt curRange; if (_chunkRange.TryGetValue(pos, out curRange)) { _chunkRange[pos] = new YRangeInt( Mathf.Min(curRange.min, deserialized.chunkMinY), Mathf.Max(curRange.max, deserialized.chunkMaxY)); } else { _chunkRange.Add(pos, new YRangeInt(deserialized.chunkMinY, deserialized.chunkMaxY)); } } List <Graph> graphs = new List <Graph>(); //put graphs inside chunks foreach (var deserialized in deserializedStuff) { //Chunk chunk = _chunkData[deserialized.chunkPosition]; XZPosInt pos = deserialized.chunkPosition; YRangeInt ran = _chunkRange[pos]; Graph graph = deserialized.graph; graph.SetChunkAndProperties(new ChunkData(pos, ran), properties); _chunkData[new GeneralXZData(pos, properties)] = graph; graph.SetAsCanBeUsed(); graphs.Add(graph); } //connect chunks foreach (var graph in graphs) { for (int i = 0; i < 4; i++) { Graph neighbour; if (TryGetGraphFrom(graph.gridPosition, (Directions)i, properties, out neighbour)) { graph.SetNeighbour((Directions)i, neighbour); } } #if UNITY_EDITOR if (Debuger_K.doDebug) { graph.DebugGraph(); } #endif } } }