private void ShowSettings() { if (settings == null) { settings = PathFinderSettings.LoadSettings(); } settings.helperName = EditorGUILayout.TextField(new GUIContent("Helper name", "pathfinder need object in scene in order to use unity API. you can specify it's name here"), settings.helperName); settings.useMultithread = EditorGUILayout.Toggle(new GUIContent("Multithread", "you can on/off multithreading for debug purpose. cause debuging threads is pain"), settings.useMultithread); if (settings.useMultithread) { settings.maxThreads = EditorGUILayout.IntField(new GUIContent("Max threads", "limit how much threads are used"), settings.maxThreads); } settings.terrainCollectionType = (TerrainCollectorType)EditorGUILayout.EnumPopup(new GUIContent("Terrain collection", "UnityWay - Collect data from terrain using Terrain.SampleHeight and TerrainData.GetSteepness. It's fast but it's all in main thread.\nCPU - Collect data by some fancy math using CPU. Not that fast but fully threaded.\nComputeShader - Superfast but in big chunks can be slow cause moving data from GPU is not that fast."), settings.terrainCollectionType); settings.colliderCollectionType = (ColliderCollectorType)EditorGUILayout.EnumPopup(new GUIContent("Collider collection", "CPU - Collect data using CPU rasterization. It's threaded so no FPS drops here. \nComputeShader - Collect data by ComputeShader. Superfast but in big chunks can be slow cause moving data from GPU is not that fast."), settings.colliderCollectionType); settings.gridSize = EditorGUILayout.FloatField(new GUIContent("World grid size", "Chunk size in world space. Good values are 10, 15, 20 etc."), settings.gridSize); settings.gridHighest = EditorGUILayout.IntField(new GUIContent("Chunk max height", "For autocreating chunks. World space value is grid size * this value."), settings.gridHighest); if (settings.gridHighest < settings.gridLowest) { settings.gridHighest = settings.gridLowest; } settings.gridLowest = EditorGUILayout.IntField(new GUIContent("Chunk min height", "For autocreating chunks. World space value is grid size * this value."), settings.gridLowest); if (settings.gridLowest > settings.gridHighest) { settings.gridLowest = settings.gridHighest; } settings.DrawAreaEditor(); }
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); }
private void ShowSettings() { if (settings == null) { settings = PathFinderSettings.LoadSettings(); } EditorGUILayout.PropertyField(helperName, helperNameContent); if (useMultithread.boolValue) { GUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(useMultithread, useMultithreadContent); EditorGUIUtility.labelWidth = 80; EditorGUILayout.PropertyField(maxThreads, maxThreadsContent); EditorGUIUtility.labelWidth = LABEL_WIDTH; GUILayout.EndHorizontal(); } else { EditorGUILayout.PropertyField(useMultithread, useMultithreadContent); } EditorGUILayout.PropertyField(terrainCollectionType, terrainCollectionTypeContent); EditorGUILayout.PropertyField(colliderCollectionType, colliderCollectionTypeContent); float someFloat; EditorGUI.BeginChangeCheck(); someFloat = EditorGUILayout.FloatField(gridSizeContent, gridSize.floatValue); if (EditorGUI.EndChangeCheck()) { settings.gridSize = someFloat; PathFinder.gridSize = someFloat; } GUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(gridLowest, gridLowestContent); EditorGUIUtility.labelWidth = 30; EditorGUILayout.PropertyField(gridHighest, gridHighestContent); EditorGUIUtility.labelWidth = LABEL_WIDTH; GUILayout.EndHorizontal(); if (gridHighest.intValue < gridLowest.intValue) { gridHighest.intValue = gridLowest.intValue; } if (gridLowest.intValue > gridHighest.intValue) { gridLowest.intValue = gridHighest.intValue; } UITools.Line(); settingsDrawer.DrawAreaEditor(); }
void OnEnable() { Debuger_K.Init(); settings = PathFinderSettings.LoadSettings(); SceneView.onSceneGUIDelegate -= this.OnSceneGUI; SceneView.onSceneGUIDelegate += this.OnSceneGUI; Repaint(); this.autoRepaintOnSceneChange = true; }
/// <summary> /// Creates a new graph from current geometry input /// </summary> /// <param name="settings">Settings</param> /// <returns>Returns the new graph</returns> public override IGraph CreateGraph(PathFinderSettings settings) { // Prepare input data this.ChunkyMesh = ChunkyTriMesh.Build(this); // Create graph var graph = new Graph() { Input = this, Settings = settings as BuildSettings, }; // Generate navigation meshes and gueries for each agent foreach (var agent in graph.Settings.Agents) { var nm = NavMesh.Build(this, graph.Settings, agent); var mmQuery = new NavMeshQuery(); mmQuery.Init(nm, graph.Settings.MaxNodes); graph.MeshQueryDictionary.Add(agent, mmQuery); } return(graph); }
/// <summary> /// Creates a new graph /// </summary> /// <param name="settings">Settings</param> /// <returns>Returns the new graph</returns> public override IGraph CreateGraph(PathFinderSettings settings) { var grid = new Grid { Input = this, BuildSettings = settings as GridGenerationSettings }; var triangles = this.GetTriangles(); var bbox = GeometryUtil.CreateBoundingBox(triangles); Dictionary <Vector2, GridCollisionInfo[]> dictionary = new Dictionary <Vector2, GridCollisionInfo[]>(); float fxSize = (bbox.Maximum.X - bbox.Minimum.X) / grid.BuildSettings.NodeSize; float fzSize = (bbox.Maximum.Z - bbox.Minimum.Z) / grid.BuildSettings.NodeSize; int xSize = fxSize > (int)fxSize ? (int)fxSize + 1 : (int)fxSize; int zSize = fzSize > (int)fzSize ? (int)fzSize + 1 : (int)fzSize; for (float x = bbox.Minimum.X; x < bbox.Maximum.X; x += grid.BuildSettings.NodeSize) { for (float z = bbox.Minimum.Z; z < bbox.Maximum.Z; z += grid.BuildSettings.NodeSize) { GridCollisionInfo[] info = null; Ray ray = new Ray() { Position = new Vector3(x, bbox.Maximum.Y + 0.01f, z), Direction = Vector3.Down, }; bool intersects = Intersection.IntersectAll( ray, triangles, true, out Vector3[] pickedPoints, out Triangle[] pickedTriangles,
public SettingsDrawer(PathFinderSettings settings) { this.settings = settings; CheckPointer(); }
//return if scene object was loaded public static bool Init() { if (!_areInit) { _areInit = true; //asume init was in main thread _mainThreadID = Thread.CurrentThread.ManagedThreadId; } if (Thread.CurrentThread.ManagedThreadId != _mainThreadID) { return(false); } if (_settings == null) { _settings = PathFinderSettings.LoadSettings(); foreach (var item in _settings.areaLibrary) { _hashData.AddAreaHash(item); } #if UNITY_EDITOR if (Debuger_K.doDebug) { Debug.LogFormat("settings init"); } #endif } if (_sceneInstance == null || _sceneInstance.gameObject == null) { try { GameObject go = GameObject.Find(_settings.helperName); if (go == null) { go = new GameObject(_settings.helperName); } _sceneInstance = go.GetComponent <PathFinderScene>(); if (_sceneInstance == null) { _sceneInstance = go.AddComponent <PathFinderScene>(); } _sceneInstance.AddCoroutine((int)NavMeshTaskType.navMesh, TemplatePopulationLoop()); _sceneInstance.AddCoroutine((int)NavMeshTaskType.graphFinish, ChunkConnection()); _sceneInstance.AddCoroutine((int)NavMeshTaskType.disconnect, ChunkDisconnection()); _sceneInstance.InitComputeShaderRasterization3D(_settings.ComputeShaderRasterization3D); _sceneInstance.InitComputeShaderRasterization2D(_settings.ComputeShaderRasterization2D); _sceneInstance.Init(); } catch (Exception e) { Debug.LogError(e); throw; } return(true); } else { return(false); } }