public void LoadCurrentData() { if (sceneNavmeshData == null) { #if UNITY_EDITOR if (Debuger_K.doDebug) { Debug.LogWarning("No data to load"); } #endif return; } #if UNITY_EDITOR if (Debuger_K.doDebug) { Debug.LogWarning("Load current data"); } Debuger_K.ClearChunksDebug(); #endif for (int i = 0; i < sceneNavmeshData.properties.Count; i++) { if (sceneNavmeshData.properties[i] == null) { Debug.LogWarning("properties == null"); continue; } PathFinder.Deserialize(sceneNavmeshData.navmesh[i], sceneNavmeshData.properties[i]); } }
public void Draw(Color color, float height) { Debuger_K.AddLine(minVector3, new Vector3(maxX, height, minY), color); Debuger_K.AddLine(minVector3, new Vector3(minX, height, maxY), color); Debuger_K.AddLine(maxVector3, new Vector3(maxX, height, minY), color); Debuger_K.AddLine(maxVector3, new Vector3(minX, height, maxY), color); }
private void RecivePathDelegate(Path path) { #if UNITY_EDITOR Debuger_K.AddLabelFormat(transform.position, "owner: {0}, valid: {1}", path.owner == _agent, path.pathType); #endif ExampleThings.PathToLineRenderer(_line, path, 0.2f); }
public void DebugIt(XZPosInt pos, AgentProperties properties) { foreach (var edge in _edges) { Debuger_K.AddTriangulatorDebugLine(pos.x, pos.z, properties, _nodes[edge.a].positionV3, _nodes[edge.b].positionV3, Color.blue); } }
public static void SceneDebug() { Debuger_K.ClearGeneric(); float gs = PathFinder.gridSize; Vector3 add = new Vector3(gs * 0.5f, 0, gs * 0.5f); StringBuilder sb = new StringBuilder(); foreach (var item in content) { sb.AppendLine(item.Value.lastUpdate.ToString()); } Debuger_K.AddLabelFormat(new Vector3(startX * gs, 0, startZ * gs), "Map space {0}\nCount {1}\n{2}", mapSpace, content.Count, sb); for (int x = startX; x < endX + 1; x++) { Debuger_K.AddLine(new Vector3(x, 0, startZ) * gs, new Vector3(x, 0, endZ) * gs, Color.blue); } for (int z = startZ; z < endZ + 1; z++) { Debuger_K.AddLine(new Vector3(startX, 0, z) * gs, new Vector3(endX, 0, z) * gs, Color.blue); } System.Random random = new System.Random(); for (int x = startX; x < endX; x++) { for (int z = startZ; z < endZ; z++) { ChunkContent content; TryGetChunkContent(x, z, out content); Vector3 p = (new Vector3(x, 0, z) * gs) + add; Debuger_K.AddLabelFormat(p, "x: {0}\nz: {1}", x, z); Color color = new Color(1, 0, 0, 0.1f); if (content != null && content.Count != 0) { color = new Color(0, 1, 0, 0.1f); } Debuger_K.AddTriangle(new Vector3(x, 0, z) * gs, (new Vector3(x + 1, 0, z) * gs), (new Vector3(x, 0, z + 1) * gs), color, false); Debuger_K.AddTriangle(new Vector3(x + 1, 0, z + 1) * gs, (new Vector3(x + 1, 0, z) * gs), (new Vector3(x, 0, z + 1) * gs), color, false); if (content != null && content.Count != 0) { Color cColor = new Color(random.Next(100) / 100f, random.Next(100) / 100f, random.Next(100) / 100f, 1f); foreach (var item in content) { Debuger_K.AddBounds(item.chunkContentBounds, cColor); Debuger_K.AddLine(p, item.chunkContentBounds.center, cColor); } } } } }
private void ShowDebuger() { Debuger_K.settings.doDebug = EditorGUILayout.Toggle(new GUIContent("Do debug", "enable debuging. debuged values you can enable down here. generic values will be debuged anyway"), Debuger_K.settings.doDebug); if (Debuger_K.settings.doDebug) { Debuger_K.settings.debugOnlyNavmesh = EditorGUILayout.Toggle(new GUIContent("Full Debug", "if false will debug only resulted navmesh. prefer debuging only navmesh. and do not use unity profiler if you enable this option or else unity will die in horribly way. also do not enable it if area are too big. memory expensive stuff here!"), Debuger_K.settings.debugOnlyNavmesh); } Debuger_K.settings.doProfilerStuff = EditorGUILayout.Toggle(new GUIContent("Do profiler", "are we using some simple profiling? cause unity dont really profile threads. if true will write lots of stuff to console"), Debuger_K.settings.doProfilerStuff); Debuger_K.settings.doDebugPaths = EditorGUILayout.Toggle(new GUIContent("Debug Paths", "If true then pathfinder will put lot's of info into paths debug. Like cell path or cost of some other info"), Debuger_K.settings.doDebugPaths); Debuger_K.settings.showSceneGUI = EditorGUILayout.Toggle(new GUIContent("Scene GUI", "Enable or disable checkboxes in scene to on/off debug of certain chunks and properties. To apply changes push Update button"), Debuger_K.settings.showSceneGUI); Debuger_K.settings.clearGenericOnUpdate = EditorGUILayout.Toggle(new GUIContent("Clear Generic on Update", "Things listed below like Dots, Lines, Meshes, or even Path considered as Generic. if you want you can disable or enable clearing it on Update"), Debuger_K.settings.clearGenericOnUpdate); GUILayout.Box("", new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(1) }); Debuger_K.GenericGUI(); Debuger_K.settings.showSelector = EditorGUILayout.Foldout(Debuger_K.settings.showSelector, "Debug options"); if (Debuger_K.settings.showSelector) { Debuger_K.SellectorGUI2(); //Debuger_K.SellectorGUI(); } }
public static void CellTester(Vector3 origin, AgentProperties properties) { Graph graph; if (TryGetGraph(ToChunkPosition(origin), properties, out graph) == false || graph.canBeUsed == false) { return; } Cell cell; bool outsideCell; Vector3 closestPosToCell; graph.GetClosestCell(origin, out cell, out outsideCell, out closestPosToCell); foreach (var pair in cell.dataContentPairs) { Debuger_K.AddLine(pair.Key, Color.magenta); if (pair.Value == null) { continue; } Cell connection = pair.Value.connection; Debuger_K.AddLabel(pair.Key.centerV3, connection.Contains(pair.Key)); } }
void OnEnable() { Debuger_K.Init(); PathFinder.Init("PathFinderMenu"); settings = PathFinder.settings; settingsDrawer = new SettingsDrawer(settings); SceneView.onSceneGUIDelegate -= this.OnSceneGUI; SceneView.onSceneGUIDelegate += this.OnSceneGUI; Repaint(); this.autoRepaintOnSceneChange = true; settingsObject = new SerializedObject(settings); targetProperties = settingsObject.FindProperty(targetPropertiesString); drawBuilder = settingsObject.FindProperty(drawBuilderString); helperName = settingsObject.FindProperty(helperNameString); useMultithread = settingsObject.FindProperty(useMultithreadString); maxThreads = settingsObject.FindProperty(maxThreadsString); terrainCollectionType = settingsObject.FindProperty(terrainCollectionTypeString); colliderCollectionType = settingsObject.FindProperty(colliderCollectionTypeString); gridSize = settingsObject.FindProperty(gridSizeString); gridHighest = settingsObject.FindProperty(gridHighestString); gridLowest = settingsObject.FindProperty(gridLowestString); //float gs = settings.gridSize; //s_Center = new Vector3((settings.startX + (settings.sizeX * 0.5f)) * gs, settings.pointerY, (settings.startX + (settings.sizeX * 0.5f)) * gs); }
void DrawBranchRecursive(QuadTreeBranch branch, float offset = 0f, float offsetDelta = 0f) { if (branch == null) { return; } Bounds2D branchBounds = branch.bounds; Debuger_K.AddBounds(branchBounds, Color.green); Vector3 curPos = branchBounds.centerVector3; for (int i = 0; i < branch.list.Count; i++) { Bounds2D countentBounds = branch.list[i].bounds; Debuger_K.AddBounds(countentBounds, Color.blue); Debuger_K.AddLine(curPos, countentBounds.centerVector3, Color.magenta); } for (int i = 0; i < 4; i++) { if (branch.branches[i] != null) { DrawBranchRecursive(branch.branches[i]); } } }
void OnGUI() { scroll = GUILayout.BeginScrollView(scroll); float curLabelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = LABEL_WIDTH; settingsObject.Update(); try { ImportantButtons(); } catch (System.Exception e) { GUILayout.Label(string.Format("Exception has ocured in importand buttons.\n\nException:\n{0}", e)); } UITools.Line(); _showSettings = EditorGUILayout.Foldout(_showSettings, "Settings"); if (_showSettings) { try { ShowSettings(); } catch (System.Exception e) { GUILayout.Label(string.Format("Exception has ocured while showing settings.\n\nException:\n{0}", e)); } } UITools.Line(); _showDebuger = EditorGUILayout.Foldout(_showDebuger, "Debuger"); if (_showDebuger) { try { ShowDebuger(); } catch (System.Exception e) { GUILayout.Label(string.Format("Exception has ocured while showing debuger.\n\nException:\n{0}", e)); } } UITools.Line(); EditorGUIUtility.labelWidth = curLabelWidth; GUILayout.EndScrollView(); if (GUI.changed) { EditorUtility.SetDirty(settings); Debuger_K.SetSettingsDirty(); Repaint(); } settingsObject.ApplyModifiedProperties(); }
void OnEnable() { Debuger_K.Init(); settings = PathFinderSettings.LoadSettings(); SceneView.onSceneGUIDelegate -= this.OnSceneGUI; SceneView.onSceneGUIDelegate += this.OnSceneGUI; Repaint(); this.autoRepaintOnSceneChange = true; }
private void AddColliderGenericCPU(Collider collider) { var gameObjectArea = collider.transform.GetComponent <AreaGameObject>(); Area area; if (gameObjectArea != null) { area = PathFinder.GetArea(gameObjectArea.areaInt); } else { if (PathFinder.settings.checkRootTag) { area = PathFinderSettings.tagAssociations[collider.transform.root.tag]; } else { area = PathFinderSettings.tagAssociations[collider.transform.tag]; } } if (collider is BoxCollider) { shapeDataGenericCPU.Add(new ShapeDataBox(collider as BoxCollider, area)); } else if (collider is SphereCollider) { shapeDataGenericCPU.Add(new ShapeDataSphere(collider as SphereCollider, area)); } else if (collider is CapsuleCollider) { shapeDataGenericCPU.Add(new ShapeDataCapsule(collider as CapsuleCollider, area)); } else if (collider is CharacterController) { shapeDataGenericCPU.Add(new ShapeDataCharacterControler(collider as CharacterController, area)); } else if (collider is MeshCollider) { shapeDataGenericCPU.Add(new ShapeDataMesh(collider as MeshCollider, area)); } else { Debug.LogFormat("Collider type on {0} currently not supported. Tell developer what is going on", collider.gameObject.name); return; } #if UNITY_EDITOR if (Debuger_K.doDebug && Debuger_K.debugOnlyNavMesh == false) { Debuger_K.AddColliderBounds(template.gridPosition.x, template.gridPosition.z, template.properties, collider); } #endif }
void Update() { if (properties == null) { return; } RaycastHit raycastHit; if (!Physics.Raycast(transform.position, Vector3.down, out raycastHit, 10)) { return; } Vector3 p = raycastHit.point; Debug.DrawLine(transform.position, p, Color.red); //Debuger_K.ClearGeneric(); RaycastHitNavMesh raycastHitNavMesh; for (int i = 0; i < tests; i++) { float x = Mathf.Cos((i / (float)tests) * 2 * Mathf.PI); float z = Mathf.Sin((i / (float)tests) * 2 * Mathf.PI); //var q = Quaternion.LookRotation(transform.forward + new Vector3(x, 0, z), Vector3.up); PathFinder.Raycast(p, new Vector3(x, 0, z), properties, out raycastHitNavMesh); if (raycastHitNavMesh.isOnGraph) { Debuger_K.AddLine(p, raycastHitNavMesh.point, Color.blue); Debuger_K.AddLabel(raycastHitNavMesh.point, "H"); } } //PathFinder.Raycast(p, transform.forward * -1, properties, out raycastHitNavMesh); //if (raycastHitNavMesh.isOnGraph) { // Debuger_K.AddLine(p, raycastHitNavMesh.point, Color.blue); // Debuger_K.AddLabel(raycastHitNavMesh.point, "B"); //} //PathFinder.Raycast(p, transform.transform.right * -1, properties, out raycastHitNavMesh); //if (raycastHitNavMesh.isOnGraph) { // Debuger_K.AddLine(p, raycastHitNavMesh.point, Color.blue); // Debuger_K.AddLabel(raycastHitNavMesh.point, "L"); //} //PathFinder.Raycast(p, transform.right, properties, out raycastHitNavMesh); //if (raycastHitNavMesh.isOnGraph) { // Debuger_K.AddLine(p, raycastHitNavMesh.point, Color.blue); // Debuger_K.AddLabel(raycastHitNavMesh.point, "R"); //} }
public void DebugByDebuger() { for (int i = 0; i < pathNodes.Count; i++) { Debuger_K.AddDot(pathNodes[i], Color.red); Debuger_K.AddLabelFormat(pathNodes[i], "{0} {1}", i, pathNodes[i]); } for (int i = 0; i < pathNodes.Count - 1; i++) { Debuger_K.AddLine(pathNodes[i], pathNodes[i + 1], Color.red); } }
void OnGUI() { scroll = GUILayout.BeginScrollView(scroll); float curLabelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = LABEL_WIDTH; try { ImportantButtons(); } catch (System.Exception e) { GUILayout.Label(string.Format("Exception has ocured in importand buttons.\n\nException:\n{0}", e)); } GUILayout.Box("", new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(1) }); _showSettings = EditorGUILayout.Foldout(_showSettings, "Settings"); if (_showSettings) { try { ShowSettings(); } catch (System.Exception e) { GUILayout.Label(string.Format("Exception has ocured while showing settings.\n\nException:\n{0}", e)); } } GUILayout.Box("", new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(1) }); _showDebuger = EditorGUILayout.Foldout(_showDebuger, "Debuger"); if (_showDebuger) { try { ShowDebuger(); } catch (System.Exception e) { GUILayout.Label(string.Format("Exception has ocured while showing debuger.\n\nException:\n{0}", e)); } } GUILayout.Box("", new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(1) }); EditorGUIUtility.labelWidth = curLabelWidth; GUILayout.EndScrollView(); if (GUI.changed) { EditorUtility.SetDirty(settings); Debuger_K.SetSettingsDirty(); Repaint(); } }
IEnumerator DebugerUpdateCoroutine() { while (true) { yield return(wfeof); DebugerUpdate(); if (Debuger_K.settings.clearGenericOnUpdate) { Debuger_K.ClearGeneric(); } } }
public static void CallThisWhenSceneObjectWasGone() { if (_sceneInstance == null)//if it's already null then do nothing { return; } Debug.Log("PathFinder: scene object was destroyed. clearing data and debug"); _sceneInstance = null; ClearAll(); #if UNITY_EDITOR Debuger_K.ClearGeneric(); Debuger_K.ClearChunksDebug(); #endif }
public void DebugGraph() { Debuger_K.AddCells(x, z, properties, cells); Debuger_K.AddCovers(x, z, properties, covers); Debuger_K.AddPortalBases(x, z, properties, portalBases); if (battleGrid != null) { Debuger_K.AddBattleGrid(x, z, properties, battleGrid); } if (Debuger_K.settings.autoUpdateSceneView) { Debuger_K.UpdateSceneImportantThings(); } }
private static void SetInterconnection(Graph graph1, Graph graph2, Cell cell1, Cell cell2, Vector3 node1, Vector3 node2) { Vector3 intersection; SomeMath.ClampedRayIntersectXZ(cell1.centerVector3, cell2.centerVector3 - cell1.centerVector3, node1, node2, out intersection); float cell1Cost = Vector3.Distance(cell1.centerVector3, intersection) * cell1.area.cost; float cell2Cost = Vector3.Distance(cell2.centerVector3, intersection) * cell2.area.cost; Vector3 leftPos, rightPos; if (SomeMath.LinePointSideMathf(new Vector2(node1.x, node1.z), new Vector2(node2.x, node2.z), cell1.centerVector2) > 0) { leftPos = node2; rightPos = node1; } else { leftPos = node1; rightPos = node2; } //Debuger_K.AddLabel(SomeMath.MidPoint(leftPos, cell1.centerV3), "L"); //Debuger_K.AddLabel(SomeMath.MidPoint(rightPos, cell1.centerV3), "R"); //Debuger_K.AddLabel(SomeMath.MidPoint(rightPos, cell2.centerV3), "L"); //Debuger_K.AddLabel(SomeMath.MidPoint(leftPos, cell2.centerV3), "R"); CellContentData C1C2data = new CellContentData(leftPos, rightPos); CellContentData C2C1data = new CellContentData(rightPos, leftPos); CellContentGenericConnection C1C2 = new CellContentGenericConnection(C1C2data, cell1, cell2, true, cell1Cost, cell2Cost, intersection); CellContentGenericConnection C2C1 = new CellContentGenericConnection(C2C1data, cell2, cell1, true, cell2Cost, cell1Cost, intersection); cell1.SetContent(C1C2); cell2.SetContent(C2C1); cell1.graph.AddEdgeToMap(cell1, cell2, C1C2data); cell2.graph.AddEdgeToMap(cell2, cell1, C2C1data); #if UNITY_EDITOR if (Debuger_K.doDebug) { Debuger_K.AddEdgesInterconnected(graph1.x, graph1.z, graph1.properties, C1C2); Debuger_K.AddEdgesInterconnected(graph2.x, graph2.z, graph2.properties, C2C1); } #endif }
void OnSceneGUI(SceneView sceneView) { Event curEvent = Event.current; Color col = Handles.color; Handles.color = Color.red; Handles.DrawLine(pointer, pointer + Vector3.up); Handles.color = col; if ((sellectStart | sellectEnd)) { RaycastHit hit; if (Physics.Raycast(HandleUtility.GUIPointToWorldRay(curEvent.mousePosition), out hit)) { var somePos = PathFinder.ToChunkPosition(hit.point); if (sellectStart) { settings.startX = somePos.x; settings.startZ = somePos.z; } if (sellectEnd) { settings.sizeX = Mathf.Max(1, somePos.x - settings.startX + 1); settings.sizeZ = Mathf.Max(1, somePos.z - settings.startZ + 1); } pointer = hit.point; } if (curEvent.type == EventType.MouseDown && curEvent.button == 0) { sellectStart = false; sellectEnd = false; } Repaint(); } Debuger_K.DrawDebugLabels(); Handles.BeginGUI(); Debuger_K.DrawSceneGUI(); Handles.EndGUI(); }
void Update() { OnUpdate(); if (Debuger_K.settings.clearGenericOnUpdate) { Debuger_K.ClearGeneric(); } //Debuger_K.AddDot(new Vector3( // UnityEngine.Random.Range(0, 10.0f), // UnityEngine.Random.Range(0, 10.0f), // UnityEngine.Random.Range(0, 10.0f)), // Color.red, // UnityEngine.Random.Range(0.005f, 0.03f)); //curTest++; //if(curTest > maxTest) { // curTest = 0; // Debuger_K.ClearDots(); //} }
//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); } }
void OnEnable() { Debuger_K.ForceInit(); Shader dotShader = PFDSettings.GetDotShader(); Shader lineShader = PFDSettings.GetLineShader(); Shader trisShader = PFDSettings.GetTrisShader(); data = new MaterialAndBufferHolder[7]; data[(int)Indexes.ImportantDot] = new MaterialAndBufferHolder(dotShader, dotShaderParameterName, dotStride); data[(int)Indexes.ImportantLine] = new MaterialAndBufferHolder(lineShader, lineShaderParameterName, lineStride); data[(int)Indexes.ImportantTris] = new MaterialAndBufferHolder(trisShader, trisShaderParameterName, trisStride); data[(int)Indexes.Path] = new MaterialAndBufferHolder(lineShader, lineShaderParameterName, lineStride); data[(int)Indexes.GenericDot] = new MaterialAndBufferHolder(dotShader, dotShaderParameterName, dotStride); data[(int)Indexes.GenericLine] = new MaterialAndBufferHolder(lineShader, lineShaderParameterName, lineStride); data[(int)Indexes.GenericMesh] = new MaterialAndBufferHolder(trisShader, trisShaderParameterName, trisStride); EditorApplication.update -= OnUpdate; EditorApplication.update += OnUpdate; //StartCoroutine(ClearDebug()); }
//on unity something void DebugerOnEnable() { Debuger_K.ForceInit(); InitDebugBuffers(); gizmosMesh = new Mesh() { vertices = gizmosVerts, triangles = gizmosTris }; gizmosMesh.RecalculateNormals(); if (Application.isPlaying == false) { EditorApplication.update -= DebugerUpdate; EditorApplication.update += DebugerUpdate; } StartCoroutine(DebugerUpdateCoroutine()); }
protected void FunnelPath(CellPath path, Vector3 endV3) { List <Cell> cellPath = path.path; List <CellContent> cellPathConnections = path.connections; #if UNITY_EDITOR if (Debuger_K.debugPath) { for (int i = 0; i < cellPath.Count - 1; i++) { Debuger_K.AddPath(cellPath[i].centerV3 + Vector3.up, cellPath[i + 1].centerV3 + Vector3.up, Color.magenta, 0.1f); } } #endif int keyGate = 0; while (true) { if (keyGate >= cellPathConnections.Count) { break; } int curKeyGate; List <CellContentGenericConnection> gateSiquence = new List <CellContentGenericConnection>(); for (curKeyGate = keyGate; curKeyGate < cellPathConnections.Count; curKeyGate++) { var c = cellPathConnections[curKeyGate]; if (c is CellContentGenericConnection) { gateSiquence.Add((CellContentGenericConnection)c); } else { break; } } if (keyGate != curKeyGate) { DoFunnelIteration(funnelPath.lastV3, curKeyGate == cellPathConnections.Count ? endV3 : (cellPathConnections[curKeyGate] as CellContentPointedConnection).enterPoint, gateSiquence); } if (curKeyGate != cellPathConnections.Count) { if (cellPathConnections[curKeyGate] is CellContentPointedConnection) { CellContentPointedConnection ju = cellPathConnections[curKeyGate] as CellContentPointedConnection; if (ju.jumpState == ConnectionJumpState.jumpUp) { funnelPath.AddMove(ju.lowerStandingPoint, (MoveState)(int)ju.from.passability); funnelPath.AddJumpUp(ju.lowerStandingPoint, ju.axis); funnelPath.AddMove(ju.exitPoint, (MoveState)(int)ju.connection.passability); } else { funnelPath.AddMove(ju.enterPoint, (MoveState)(int)ju.from.passability); funnelPath.AddMove(ju.axis, (MoveState)(int)ju.from.passability); funnelPath.AddJumpDown(ju.axis, ju.lowerStandingPoint); funnelPath.AddMove(ju.exitPoint, (MoveState)(int)ju.connection.passability); } } else { Debug.LogErrorFormat("idk type of CellConnectionAbstract node {0}", cellPathConnections[curKeyGate].GetType().Name); } } keyGate = curKeyGate + 1; } funnelPath.AddMove(endV3, (MoveState)(int)cellPath[cellPath.Count - 1].passability); #if UNITY_EDITOR if (Debuger_K.debugPath) { var resultNodes = funnelPath.nodes; for (int i = 0; i < resultNodes.Count - 1; i++) { Debuger_K.AddPath(resultNodes[i].positionV3, resultNodes[i + 1].positionV3, Color.green); } //for (int i = 0; i < resultNodes.Count; i++) { // Debuger3.AddDot(resultNodes[i].positionV3, Color.green, 0.03f, DebugGroup.path); // Debuger3.AddLabel(resultNodes[i].positionV3, resultNodes[i].ToString(), DebugGroup.path); //} } #endif funnelPath.RemoveFirst(); }
private void GeneratePaths() { CellPath path = new CellPath(startCell, start_v3); if (startCell == endCell) { potentialPaths.Add(path); return; } #if UNITY_EDITOR float totalDist = Debuger_K.doDebug ? Vector3.Distance(start_v3, end_v3) : 0f; #endif path.h = EuclideanDistance(start_v3); excluded.Clear(); excluded.Add(startCell); foreach (var connection in startCell.connections) { CellPath newPath = new CellPath(path, connection); newPath.g = connection.Cost(properties, ignoreCrouchCost); if (connection is CellContentPointedConnection) { newPath.h = EuclideanDistance((connection as CellContentPointedConnection).exitPoint); } else { newPath.h = EuclideanDistance(connection.connection); } AddCellNode(newPath); } int limit = 0; while (true) { limit++; if (limit > 1500) { Debug.Log("limit > 1500"); break; } CellPath current = TakeCellNode(); if (current == null) { break; } Cell currentCell = current.last; if (currentCell == endCell) { potentialPaths.Add(current); #if UNITY_EDITOR if (Debuger_K.doDebug) { float lerped = Mathf.InverseLerp(0, totalDist, Vector3.Distance(end_v3, currentCell.centerV3)); Debuger_K.AddPath(current.path[current.path.Count - 2].centerV3 + Vector3.up, current.path[current.path.Count - 1].centerV3 + Vector3.up, new Color(lerped, 1 - lerped, 0, 1f)); } #endif if (potentialPaths.Count >= maxPaths) { break; } else { continue; } } if (excluded.Contains(currentCell)) { continue; } else { excluded.Add(currentCell); } #if UNITY_EDITOR if (Debuger_K.doDebug) { float lerped = Mathf.InverseLerp(0, totalDist, Vector3.Distance(end_v3, currentCell.centerV3)); Debuger_K.AddPath(current.path[current.path.Count - 2].centerV3 + (Vector3.up * 0.3f), current.path[current.path.Count - 1].centerV3 + (Vector3.up * 0.3f), new Color(lerped, 1 - lerped, 0, 1f)); } #endif foreach (var connection in currentCell.connections) { Cell newCell = connection.connection; if (current.Contains(newCell) == false) { CellPath newPath = new CellPath(current, connection); #if UNITY_EDITOR if (Debuger_K.debugPath) { Debuger_K.AddLabel(SomeMath.MidPoint(current.last.centerV3, newCell.centerV3), connection.Cost(properties, ignoreCrouchCost), DebugGroup.path); } #endif newPath.g = current.g + connection.Cost(properties, ignoreCrouchCost); if (connection is CellContentPointedConnection) { newPath.h = EuclideanDistance((connection as CellContentPointedConnection).exitPoint); //Debuger3.AddLabel((connection as CellPointedConnection).exitPoint, newPath.h); } else { newPath.h = EuclideanDistance(connection.connection); } AddCellNode(newPath); } } } }
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; } }
public CSRasterization2DResult Rasterize(Vector3[] verts, int[] tris, int sizeX, int sizeZ, float chunkPosX, float chunkPosZ, float voxelSize, float maxSlopeCos, bool debug = false) { if (tris.Length == 0) { return(null); } int dsLength = tris.Length / 3; int dsTargetLength = Mathf.Max(Mathf.CeilToInt((float)dsLength / (float)cellSizeX), 1) * cellSizeX; DataSegment2D[] ds = new DataSegment2D[dsTargetLength]; int sizeTotal = sizeX * sizeZ; int offsetX = Mathf.RoundToInt(chunkPosX / voxelSize); int offsetZ = Mathf.RoundToInt(chunkPosZ / voxelSize); for (int i = 0; i < tris.Length; i += 3) { Vector3 A = verts[tris[i]]; Vector3 B = verts[tris[i + 1]]; Vector3 C = verts[tris[i + 2]]; //making data segments //data segment represent: //triangle index //expected passablity based on inclanation //min and max indexes in grid to check it presence ds[i / 3] = new DataSegment2D( i, (CalculateWalk(A, B, C, maxSlopeCos) ? 3 : 1), //if true then walkable else slope; Mathf.Clamp(Mathf.FloorToInt(SomeMath.Min(A.x, B.x, C.x) / voxelSize) - offsetX, 0, sizeX), //minX Mathf.Clamp(Mathf.CeilToInt(SomeMath.Max(A.x, B.x, C.x) / voxelSize) - offsetX, 0, sizeX), //maxX Mathf.Clamp(Mathf.FloorToInt(SomeMath.Min(A.z, B.z, C.z) / voxelSize) - offsetZ, 0, sizeZ), //minZ Mathf.Clamp(Mathf.CeilToInt(SomeMath.Max(A.z, B.z, C.z) / voxelSize) - offsetZ, 0, sizeZ) //maxZ ); } int kernel = CS.FindKernel("Rasterize"); ComputeBuffer vertsBuffer = new ComputeBuffer(verts.Length, sizeof(float) * 3); ComputeBuffer trisBuffer = new ComputeBuffer(tris.Length, sizeof(int)); ComputeBuffer voxelBuffer = new ComputeBuffer(sizeTotal, Voxel2D.stride); ComputeBuffer dataSegmentBuffer = new ComputeBuffer(dsTargetLength, DataSegment2D.stride); CS.SetInt("SizeX", sizeX); CS.SetInt("SizeZ", sizeZ); CS.SetVector("ChunkPos", new Vector4(chunkPosX, 0, chunkPosZ, 0)); CS.SetFloat("VoxelSize", voxelSize); CS.SetBuffer(kernel, "CurTris", trisBuffer); CS.SetBuffer(kernel, "CurVerts", vertsBuffer); CS.SetBuffer(kernel, "Result", voxelBuffer); CS.SetBuffer(kernel, "TargetSegments", dataSegmentBuffer); vertsBuffer.SetData(verts); trisBuffer.SetData(tris); Voxel2D[] voxels = new Voxel2D[sizeTotal]; for (int i = 0; i < sizeTotal; i++) { voxels[i].passability = -1; } voxelBuffer.SetData(voxels); dataSegmentBuffer.SetData(ds); CS.Dispatch(kernel, dsTargetLength / cellSizeX, 1, 1); voxelBuffer.GetData(voxels); CSRasterization2DResult result = new CSRasterization2DResult(voxels); //debug #if UNITY_EDITOR if (debug) { Debuger_K.AddMesh(verts, tris, new Color(1, 0, 1, 0.1f)); //implementation of things goint on in compute shader foreach (var dataSet in ds) { Vector3 A = verts[tris[dataSet.index]]; Vector3 B = verts[tris[dataSet.index + 1]]; Vector3 C = verts[tris[dataSet.index + 2]]; for (int x = dataSet.minX; x < dataSet.maxX; x++) { for (int z = dataSet.minZ; z < dataSet.maxZ; z++) { float pointX = (x * voxelSize) + chunkPosX; float pointZ = (z * voxelSize) + chunkPosZ; //if (SomeMath.LineSide(B.x, B.z, A.x, A.z, pointX, pointZ) <= 0.001 & // SomeMath.LineSide(A.x, A.z, C.x, C.z, pointX, pointZ) <= 0.001 & // SomeMath.LineSide(C.x, C.z, B.x, B.z, pointX, pointZ) <= 0.001) { // float height = SomeMath.CalculateHeight(A, B, C, pointX, pointZ); // Debuger_K.AddDot(new Vector3((x * voxelSize) + chunkPosX, height, (z * voxelSize) + chunkPosZ)); // Debuger_K.AddLine(A, new Vector3((x * voxelSize) + chunkPosX, 0, (z * voxelSize) + chunkPosZ), Color.green); // Debuger_K.AddLine(B, new Vector3((x * voxelSize) + chunkPosX, 0, (z * voxelSize) + chunkPosZ), Color.green); // Debuger_K.AddLine(C, new Vector3((x * voxelSize) + chunkPosX, 0, (z * voxelSize) + chunkPosZ), Color.green); //} //else { // Debuger_K.AddLine(A, new Vector3((x * voxelSize) + chunkPosX, 0, (z * voxelSize) + chunkPosZ), Color.red); // Debuger_K.AddLine(B, new Vector3((x * voxelSize) + chunkPosX, 0, (z * voxelSize) + chunkPosZ), Color.red); // Debuger_K.AddLine(C, new Vector3((x * voxelSize) + chunkPosX, 0, (z * voxelSize) + chunkPosZ), Color.red); //} if (SomeMath.PointInTriangleSimple(A, B, C, pointX, pointZ)) { float height = SomeMath.CalculateHeight(A, B, C, pointX, pointZ); Debuger_K.AddDot(new Vector3((x * voxelSize) + chunkPosX, height, (z * voxelSize) + chunkPosZ)); //Debuger_K.AddLine(A, new Vector3((x * voxelSize) + chunkPosX, 0, (z * voxelSize) + chunkPosZ), Color.green); //Debuger_K.AddLine(B, new Vector3((x * voxelSize) + chunkPosX, 0, (z * voxelSize) + chunkPosZ), Color.green); //Debuger_K.AddLine(C, new Vector3((x * voxelSize) + chunkPosX, 0, (z * voxelSize) + chunkPosZ), Color.green); } else { //Debuger_K.AddLine(A, new Vector3((x * voxelSize) + chunkPosX, 0, (z * voxelSize) + chunkPosZ), Color.red); //Debuger_K.AddLine(B, new Vector3((x * voxelSize) + chunkPosX, 0, (z * voxelSize) + chunkPosZ), Color.red); //Debuger_K.AddLine(C, new Vector3((x * voxelSize) + chunkPosX, 0, (z * voxelSize) + chunkPosZ), Color.red); } } } } //for (int x = 0; x < sizeX; x++) { // for (int z = 0; z < sizeZ; z++) { // var curVoxel = voxels[x + (z * sizeX)]; // if (curVoxel.exist) { // Debuger_K.AddDot(new Vector3((x * voxelSize) + chunkPosX, curVoxel.height, (z * voxelSize) + chunkPosZ)); // } // } //} } #endif vertsBuffer.Dispose(); trisBuffer.Dispose(); voxelBuffer.Dispose(); dataSegmentBuffer.Dispose(); return(result); }
void OnDestroy() { EditorUtility.SetDirty(settings); SceneView.onSceneGUIDelegate -= this.OnSceneGUI; Debuger_K.SetSettingsDirty(); }
private void ImportantButtons() { //properties settings.targetProperties = (AgentProperties)EditorGUILayout.ObjectField(new GUIContent("Properties", "Build navmesh using this properties"), settings.targetProperties, typeof(AgentProperties), false); //sellected chunks EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("start x:", GUILayout.MaxWidth(45)); settings.startX = EditorGUILayout.IntField(settings.startX); EditorGUILayout.LabelField("z:", GUILayout.MaxWidth(15)); settings.startZ = EditorGUILayout.IntField(settings.startZ); if (!sellectStart) { if (GUILayout.Button("sellect")) { sellectStart = true; } } else { GUILayout.Label("click"); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("size x:", GUILayout.MaxWidth(45)); settings.sizeX = EditorGUILayout.IntField(settings.sizeX); EditorGUILayout.LabelField("z:", GUILayout.MaxWidth(15)); settings.sizeZ = EditorGUILayout.IntField(settings.sizeZ); if (!sellectEnd) { if (GUILayout.Button("Sellect")) { sellectEnd = true; } } else { GUILayout.Label("Click"); } EditorGUILayout.EndHorizontal(); //upper row of cool buttons GUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent("Build", "Build navmesh in sellected area"))) { if (settings.targetProperties == null) { Debug.LogWarning("forgot to add properties"); return; } PathFinder.QueueGraph( settings.startX, settings.startZ, settings.targetProperties, settings.sizeX, settings.sizeZ); } if (GUILayout.Button(new GUIContent("Remove", "Remove navmesh from sellected area. Only target area will be removed."))) { PathFinder.RemoveGraph( settings.startX, settings.startZ, settings.targetProperties, settings.sizeX, settings.sizeZ, _redoRemovedGraphs); } _redoRemovedGraphs = GUILayout.Toggle(_redoRemovedGraphs, new GUIContent("", "Queue removed again? If true then we refresh sellected chunks"), GUILayout.MaxWidth(18)); if (GUILayout.Button(new GUIContent("Clear", "Remove all NavMesh. Also stop all work"))) { PathFinder.ClearAll(); Debuger_K.ClearChunksDebug(); } GUILayout.EndHorizontal(); //net row of cool buttons about serialization GUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent("Save", "Save all current navmesh into SceneNavmeshData. If it not exist then suggest to create one and pass reference to it into scene helper."))) { PathFinder.SaveCurrentSceneData(); } if (GUILayout.Button(new GUIContent("Load", "Load current SceneNavmeshData from scene helper"))) { PathFinder.LoadCurrentSceneData(); } if (GUILayout.Button(new GUIContent("Delete", "Remove all serialized data from current NavMesh data. Scriptable object remain in project"))) { PathFinder.ClearCurrentData(); } GUILayout.EndHorizontal(); }