├── NavMesh ├── Assembly-CSharp-Editor-vs.csproj ├── Assembly-CSharp-Editor.csproj ├── Assembly-CSharp-vs.csproj ├── Assembly-CSharp.csproj ├── Assets │ ├── Gizmos.meta │ ├── Gizmos │ │ ├── 010.tif │ │ └── 010.tif.meta │ ├── New Terrain.asset │ ├── New Terrain.asset.meta │ ├── Scripts.meta │ ├── Scripts │ │ ├── NavMesh.meta │ │ └── NavMesh │ │ │ ├── Circle.cs │ │ │ ├── Circle.cs.meta │ │ │ ├── DEBUG.cs │ │ │ ├── DEBUG.cs.meta │ │ │ ├── Editor.meta │ │ │ ├── Editor │ │ │ ├── EditorNavMesh.cs │ │ │ └── EditorNavMesh.cs.meta │ │ │ ├── Line2D.cs │ │ │ ├── Line2D.cs.meta │ │ │ ├── NMath.cs │ │ │ ├── NMath.cs.meta │ │ │ ├── NavEditArea.cs │ │ │ ├── NavEditArea.cs.meta │ │ │ ├── NavEditAreaGroup.cs │ │ │ ├── NavEditAreaGroup.cs.meta │ │ │ ├── NavEditAreaManager.cs │ │ │ ├── NavEditAreaManager.cs.meta │ │ │ ├── NavMeshGen.cs │ │ │ ├── NavMeshGen.cs.meta │ │ │ ├── NavMonoEditor.cs │ │ │ ├── NavMonoEditor.cs.meta │ │ │ ├── NavNode.cs │ │ │ ├── NavNode.cs.meta │ │ │ ├── NavTriangle.cs │ │ │ ├── NavTriangle.cs.meta │ │ │ ├── NavUtil.cs │ │ │ ├── NavUtil.cs.meta │ │ │ ├── Polygon.cs │ │ │ ├── Polygon.cs.meta │ │ │ ├── Seeker.cs │ │ │ ├── Seeker.cs.meta │ │ │ ├── Triangle.cs │ │ │ ├── Triangle.cs.meta │ │ │ ├── WayPoint.cs │ │ │ └── WayPoint.cs.meta │ ├── Terrain.prefab │ ├── Terrain.prefab.meta │ ├── Test.unity │ ├── Test.unity.meta │ ├── data.meta │ └── data │ │ ├── map.navmesh │ │ ├── map.navmesh.meta │ │ ├── map.unwalk │ │ ├── map.unwalk.meta │ │ ├── map1.navmesh │ │ ├── map1.navmesh.meta │ │ ├── map1.unwalk │ │ ├── map1.unwalk.meta │ │ ├── map2.navmesh │ │ ├── map2.navmesh.meta │ │ ├── map2.unwalk │ │ ├── map2.unwalk.meta │ │ ├── map3.navmesh │ │ ├── map3.navmesh.meta │ │ ├── map3.unwalk │ │ └── map3.unwalk.meta ├── Library │ ├── AnnotationManager │ ├── AssetImportState │ ├── AssetServerCacheV3 │ ├── AssetVersioning.db │ ├── BuildPlayer.prefs │ ├── BuildSettings.asset │ ├── CurrentLayout.dwlt │ ├── EditorUserBuildSettings.asset │ ├── EditorUserSettings.asset │ ├── FailedAssetImports.txt │ ├── InspectorExpandedItems.asset │ ├── MonoManager.asset │ ├── ProjectSettings.asset │ ├── ScriptAssemblies │ │ ├── Assembly-CSharp-Editor.dll │ │ ├── Assembly-CSharp-Editor.dll.mdb │ │ ├── Assembly-CSharp.dll │ │ ├── Assembly-CSharp.dll.mdb │ │ └── CompilationCompleted.txt │ ├── ScriptMapper │ ├── ShaderCache.db │ ├── ShaderCache │ │ ├── 4 │ │ │ ├── 48682794dd6853836c7e7474aaa659f2.bin │ │ │ └── 4f3692287816d020b19ddc922e965711.bin │ │ ├── 8 │ │ │ └── 852147239167e337d561a23df0952531.bin │ │ └── 9 │ │ │ └── 9004e6c5f266fb4d0b148f1b9580e527.bin │ ├── assetDatabase3 │ ├── expandedItems │ ├── guidmapper │ ├── metadata │ │ ├── 15 │ │ │ └── 15cb92e5905c64052a38c79aa0b18ee6 │ │ ├── 16 │ │ │ └── 1684dad0daf904e53b22c786e405379d │ │ ├── 23 │ │ │ └── 2353ad324112f41e7aacc436578d4230 │ │ ├── 27 │ │ │ └── 27a306fbcdc134268a83acefb2471e7d │ │ ├── 30 │ │ │ └── 30d14ebf6e7474757879475d3243fbc3 │ │ ├── 51 │ │ │ └── 512fd4ccbdd4f417dbd23011bda72173 │ │ ├── 52 │ │ │ └── 52cc90dfdfc5a46ebb6097ce8ce0f995 │ │ ├── 58 │ │ │ └── 5893d4aa496c846ce8f337085ed506e4 │ │ ├── 65 │ │ │ ├── 65182398383394d1d97ec3f4d816081d │ │ │ └── 655accde9495346568817b86f2289ed9 │ │ ├── 66 │ │ │ └── 663438ac623fa4b43b3e1c9d7631738e │ │ ├── 91 │ │ │ └── 91d827081ccfb4b4fbe579a80f79ee4d │ │ ├── 94 │ │ │ └── 9450ef14c695a44b694409d92fc97bca │ │ ├── 00 │ │ │ ├── 00000000000000001000000000000000 │ │ │ ├── 00000000000000002000000000000000 │ │ │ ├── 00000000000000003000000000000000 │ │ │ ├── 00000000000000004000000000000000 │ │ │ ├── 00000000000000004100000000000000 │ │ │ ├── 00000000000000005000000000000000 │ │ │ ├── 00000000000000005100000000000000 │ │ │ ├── 00000000000000006000000000000000 │ │ │ ├── 00000000000000006100000000000000 │ │ │ ├── 00000000000000007000000000000000 │ │ │ ├── 00000000000000008000000000000000 │ │ │ ├── 00000000000000009000000000000000 │ │ │ ├── 0000000000000000a000000000000000 │ │ │ ├── 0000000000000000b000000000000000 │ │ │ ├── 0000000000000000c000000000000000 │ │ │ └── 008984c8f730746c482b6d815d59e612 │ │ ├── 05 │ │ │ └── 05737f79bb9524dc692895de2fc552ee │ │ ├── 09 │ │ │ └── 09a73ede791c04bb69f7d24c93b3412e │ │ ├── 2a │ │ │ └── 2ad203620231e4b1eb2af329d95c9f39 │ │ ├── 2b │ │ │ └── 2b409f535139e43b3b4983d323336cf3 │ │ ├── 3c │ │ │ └── 3cd0266cbe221422db4d7e095c033513 │ │ ├── 4e │ │ │ └── 4e55186f51e804e608f6e280e82fdfdf │ │ ├── 7a │ │ │ └── 7a250d6273fbe46268300c56cd6d7a99 │ │ ├── 7c │ │ │ └── 7c82556b8752449eca5e7560b9403753 │ │ ├── 8a │ │ │ └── 8a750640b06be4fd48be182eed970b9b │ │ ├── a4 │ │ │ └── a47f0c4eba7dd40af85b87445eeb1c94 │ │ ├── ab │ │ │ ├── ab6722932481e4b63a7ac125771e53e7 │ │ │ └── ab9480d4abf85435696be004e46e6884 │ │ ├── ac │ │ │ └── ac097c6f3a6434803844dc1a641c4d7b │ │ ├── bc │ │ │ └── bc75ff7cf00364728a0b1369c0be6a2f │ │ ├── bd │ │ │ └── bdbf485e36ad348dd9ebb2c7705adb29 │ │ ├── ca │ │ │ ├── cacdda3f09d3f4c9fba33a9d32c9ea55 │ │ │ └── cae94ac1d62804a11a3f7881db9e8cb4 │ │ ├── d6 │ │ │ └── d6eb707f8ae0c493d88969fcee802895 │ │ ├── da │ │ │ └── dad57801c7fd74dc284b1261ddf59300 │ │ └── ee │ │ │ └── eee6f2420f021466e8922035a25fce06 │ └── shadercompiler-1.log ├── NavMesh-csharp.sln ├── NavMesh.sln ├── NavMesh.userprefs ├── ProjectSettings │ ├── AudioManager.asset │ ├── DynamicsManager.asset │ ├── EditorBuildSettings.asset │ ├── EditorSettings.asset │ ├── GraphicsSettings.asset │ ├── InputManager.asset │ ├── NavMeshLayers.asset │ ├── NetworkManager.asset │ ├── Physics2DSettings.asset │ ├── ProjectSettings.asset │ ├── QualitySettings.asset │ ├── TagManager.asset │ └── TimeManager.asset └── Temp │ ├── UnityLockfile │ ├── UnityTempFile-26208dfc0b3d54075b7672f761fa93ca │ └── UnityTempFile-d2c3f16fcb2504e9a9feb83b84c044d3 └── README.md /NavMesh/Assembly-CSharp-Editor-vs.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 10.0.20506 7 | 2.0 8 | {C87A5162-27DA-D4EA-7AC8-6CF152A7091A} 9 | Library 10 | Properties 11 | 12 | Assembly-CSharp-Editor 13 | v3.5 14 | 512 15 | Assets 16 | 17 | 18 | true 19 | full 20 | false 21 | Temp\bin\Debug\ 22 | DEBUG;TRACE;UNITY_4_5_0;UNITY_4_5;UNITY_STANDALONE_OSX;ENABLE_MICROPHONE;ENABLE_TEXTUREID_MAP;ENABLE_UNITYEVENTS;ENABLE_NEW_HIERARCHY ;ENABLE_AUDIO_FMOD;UNITY_STANDALONE;ENABLE_MONO;ENABLE_TERRAIN;ENABLE_SUBSTANCE;ENABLE_GENERICS;INCLUDE_WP8SUPPORT;ENABLE_MOVIES;ENABLE_WWW;ENABLE_IMAGEEFFECTS;ENABLE_WEBCAM;INCLUDE_METROSUPPORT;RENDER_SOFTWARE_CURSOR;ENABLE_NETWORK;ENABLE_PHYSICS;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_2D_PHYSICS;ENABLE_GAMECENTER;ENABLE_SHADOWS;ENABLE_AUDIO;ENABLE_NAVMESH_CARVING;ENABLE_DUCK_TYPING;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;ENABLE_PROFILER;UNITY_EDITOR;UNITY_EDITOR_OSX;UNITY_TEAM_LICENSE;UNITY_PRO_LICENSE 23 | prompt 24 | 4 25 | 0169 26 | 27 | 28 | pdbonly 29 | true 30 | Temp\bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 0169 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | /Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll 43 | 44 | 45 | /Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEditor.dll 46 | 47 | 48 | 49 | 50 | 51 | /Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEditor.Graphs.dll 52 | 53 | 54 | 55 | 56 | {5C5A758D-9CAE-C586-67A2-AFA743B37560} Assembly-CSharp-vs 57 | 58 | 59 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /NavMesh/Assembly-CSharp-Editor.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 10.0.20506 7 | 2.0 8 | {C87A5162-27DA-D4EA-7AC8-6CF152A7091A} 9 | Library 10 | Properties 11 | 12 | Assembly-CSharp-Editor 13 | v3.5 14 | 512 15 | Assets 16 | 17 | 18 | true 19 | full 20 | false 21 | Temp\bin\Debug\ 22 | DEBUG;TRACE;UNITY_4_5_0;UNITY_4_5;UNITY_STANDALONE_OSX;ENABLE_MICROPHONE;ENABLE_TEXTUREID_MAP;ENABLE_UNITYEVENTS;ENABLE_NEW_HIERARCHY ;ENABLE_AUDIO_FMOD;UNITY_STANDALONE;ENABLE_MONO;ENABLE_TERRAIN;ENABLE_SUBSTANCE;ENABLE_GENERICS;INCLUDE_WP8SUPPORT;ENABLE_MOVIES;ENABLE_WWW;ENABLE_IMAGEEFFECTS;ENABLE_WEBCAM;INCLUDE_METROSUPPORT;RENDER_SOFTWARE_CURSOR;ENABLE_NETWORK;ENABLE_PHYSICS;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_2D_PHYSICS;ENABLE_GAMECENTER;ENABLE_SHADOWS;ENABLE_AUDIO;ENABLE_NAVMESH_CARVING;ENABLE_DUCK_TYPING;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;ENABLE_PROFILER;UNITY_EDITOR;UNITY_EDITOR_OSX;UNITY_TEAM_LICENSE;UNITY_PRO_LICENSE 23 | prompt 24 | 4 25 | 0169 26 | 27 | 28 | pdbonly 29 | true 30 | Temp\bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 0169 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | /Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll 43 | 44 | 45 | /Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEditor.dll 46 | 47 | 48 | 49 | 50 | 51 | /Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEditor.Graphs.dll 52 | 53 | 54 | 55 | 56 | {5C5A758D-9CAE-C586-67A2-AFA743B37560} Assembly-CSharp 57 | 58 | 59 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /NavMesh/Assembly-CSharp-vs.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 10.0.20506 7 | 2.0 8 | {5C5A758D-9CAE-C586-67A2-AFA743B37560} 9 | Library 10 | Properties 11 | 12 | Assembly-CSharp 13 | v3.5 14 | 512 15 | Assets 16 | 17 | 18 | true 19 | full 20 | false 21 | Temp\bin\Debug\ 22 | DEBUG;TRACE;UNITY_4_5_0;UNITY_4_5;UNITY_STANDALONE_OSX;ENABLE_MICROPHONE;ENABLE_TEXTUREID_MAP;ENABLE_UNITYEVENTS;ENABLE_NEW_HIERARCHY ;ENABLE_AUDIO_FMOD;UNITY_STANDALONE;ENABLE_MONO;ENABLE_TERRAIN;ENABLE_SUBSTANCE;ENABLE_GENERICS;INCLUDE_WP8SUPPORT;ENABLE_MOVIES;ENABLE_WWW;ENABLE_IMAGEEFFECTS;ENABLE_WEBCAM;INCLUDE_METROSUPPORT;RENDER_SOFTWARE_CURSOR;ENABLE_NETWORK;ENABLE_PHYSICS;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_2D_PHYSICS;ENABLE_GAMECENTER;ENABLE_SHADOWS;ENABLE_AUDIO;ENABLE_NAVMESH_CARVING;ENABLE_DUCK_TYPING;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;ENABLE_PROFILER;UNITY_EDITOR;UNITY_EDITOR_OSX;UNITY_TEAM_LICENSE;UNITY_PRO_LICENSE 23 | prompt 24 | 4 25 | 0169 26 | 27 | 28 | pdbonly 29 | true 30 | Temp\bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 0169 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | /Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll 43 | 44 | 45 | /Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEditor.dll 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /NavMesh/Assembly-CSharp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 10.0.20506 7 | 2.0 8 | {5C5A758D-9CAE-C586-67A2-AFA743B37560} 9 | Library 10 | Properties 11 | 12 | Assembly-CSharp 13 | v3.5 14 | 512 15 | Assets 16 | 17 | 18 | true 19 | full 20 | false 21 | Temp\bin\Debug\ 22 | DEBUG;TRACE;UNITY_4_5_0;UNITY_4_5;UNITY_STANDALONE_OSX;ENABLE_MICROPHONE;ENABLE_TEXTUREID_MAP;ENABLE_UNITYEVENTS;ENABLE_NEW_HIERARCHY ;ENABLE_AUDIO_FMOD;UNITY_STANDALONE;ENABLE_MONO;ENABLE_TERRAIN;ENABLE_SUBSTANCE;ENABLE_GENERICS;INCLUDE_WP8SUPPORT;ENABLE_MOVIES;ENABLE_WWW;ENABLE_IMAGEEFFECTS;ENABLE_WEBCAM;INCLUDE_METROSUPPORT;RENDER_SOFTWARE_CURSOR;ENABLE_NETWORK;ENABLE_PHYSICS;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_2D_PHYSICS;ENABLE_GAMECENTER;ENABLE_SHADOWS;ENABLE_AUDIO;ENABLE_NAVMESH_CARVING;ENABLE_DUCK_TYPING;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;ENABLE_PROFILER;UNITY_EDITOR;UNITY_EDITOR_OSX;UNITY_TEAM_LICENSE;UNITY_PRO_LICENSE 23 | prompt 24 | 4 25 | 0169 26 | 27 | 28 | pdbonly 29 | true 30 | Temp\bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 0169 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | /Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll 43 | 44 | 45 | /Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEditor.dll 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /NavMesh/Assets/Gizmos.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 09a73ede791c04bb69f7d24c93b3412e 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /NavMesh/Assets/Gizmos/010.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Assets/Gizmos/010.tif -------------------------------------------------------------------------------- /NavMesh/Assets/Gizmos/010.tif.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a47f0c4eba7dd40af85b87445eeb1c94 3 | TextureImporter: 4 | serializedVersion: 2 5 | mipmaps: 6 | mipMapMode: 0 7 | enableMipMap: 1 8 | linearTexture: 0 9 | correctGamma: 0 10 | fadeOut: 0 11 | borderMipMap: 0 12 | mipMapFadeDistanceStart: 1 13 | mipMapFadeDistanceEnd: 3 14 | bumpmap: 15 | convertToNormalMap: 0 16 | externalNormalMap: 0 17 | heightScale: .25 18 | normalMapFilter: 0 19 | isReadable: 0 20 | grayScaleToAlpha: 0 21 | generateCubemap: 0 22 | seamlessCubemap: 0 23 | textureFormat: -1 24 | maxTextureSize: 1024 25 | textureSettings: 26 | filterMode: -1 27 | aniso: -1 28 | mipBias: -1 29 | wrapMode: -1 30 | nPOTScale: 1 31 | lightmap: 0 32 | compressionQuality: 50 33 | spriteMode: 0 34 | spriteExtrude: 1 35 | spriteMeshType: 1 36 | alignment: 0 37 | spritePivot: {x: .5, y: .5} 38 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 39 | spritePixelsToUnits: 100 40 | alphaIsTransparency: 0 41 | textureType: -1 42 | buildTargetSettings: [] 43 | spriteSheet: 44 | sprites: [] 45 | spritePackingTag: 46 | userData: 47 | -------------------------------------------------------------------------------- /NavMesh/Assets/New Terrain.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Assets/New Terrain.asset -------------------------------------------------------------------------------- /NavMesh/Assets/New Terrain.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: eee6f2420f021466e8922035a25fce06 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 15cb92e5905c64052a38c79aa0b18ee6 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bdbf485e36ad348dd9ebb2c7705adb29 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/Circle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | 6 | namespace Game.NavMesh 7 | { 8 | 9 | /// 10 | /// 圆 11 | /// 12 | public class Circle 13 | { 14 | //圆心 15 | public Vector2 center; 16 | 17 | //半径 18 | public float radius; 19 | 20 | public Circle(Vector2 cen, float r) 21 | { 22 | center = cen; 23 | radius = r; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/Circle.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4e55186f51e804e608f6e280e82fdfdf 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/DEBUG.cs: -------------------------------------------------------------------------------- 1 |  2 | using UnityEngine; 3 | using System; 4 | 5 | 6 | // DEBGU.cs 7 | // Author: Lu Zexi 8 | // 2013-10-04 9 | 10 | 11 | namespace Game.NavMesh 12 | { 13 | public class DEBUG 14 | { 15 | /// 16 | /// 记录打印 17 | /// 18 | /// 19 | public static void LOG(string str) 20 | { 21 | Debug.Log(str); 22 | } 23 | 24 | /// 25 | /// 错误记录打印 26 | /// 27 | /// 28 | public static void ERROR(string str) 29 | { 30 | Debug.LogError(str); 31 | } 32 | 33 | /// 34 | /// 异常记录打印 35 | /// 36 | /// 37 | public static void ERROR(Exception ex) 38 | { 39 | Debug.LogError(ex.StackTrace); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/DEBUG.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bc75ff7cf00364728a0b1369c0be6a2f 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 05737f79bb9524dc692895de2fc552ee 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/Editor/EditorNavMesh.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System; 4 | using System.Collections; 5 | using System.Collections.Generic; 6 | using Game.NavMesh; 7 | 8 | 9 | // EditorNavMesh.cs 10 | // Author: Lu Zexi 11 | // 2014-07-08 12 | 13 | 14 | namespace Game.NavMesh 15 | { 16 | [CustomEditor(typeof(NavMonoEditor))] 17 | public class EditorNavMesh : Editor 18 | { 19 | private const string UNWALK_EXTENSION = "unwalk"; 20 | private const string NAVMESH_EXTENSION = "navmesh"; 21 | private NavMonoEditor m_cNavMono = null; 22 | public static EditState m_eState = EditState.StateOther; 23 | public static GameObject m_cParent = null; 24 | 25 | private static int m_iLastSelGroup = -1; 26 | private static int m_iLastSelArea = -1; 27 | private static int m_iLastSelPoint = -1; 28 | 29 | public enum EditState 30 | { 31 | StateEditArea, 32 | StateFindArea, 33 | StateFinishArea, 34 | StateOther 35 | } 36 | 37 | // 焦点转移到编辑窗口 38 | private void FocusEditPanel() 39 | { 40 | if (SceneView.sceneViews.Count > 0) 41 | { 42 | SceneView myView = (SceneView)SceneView.sceneViews[0]; 43 | myView.Focus(); 44 | } 45 | } 46 | 47 | void OnEnable() 48 | { 49 | if (m_cNavMono == null) 50 | { 51 | if (target) 52 | { 53 | m_cNavMono = (NavMonoEditor)target; 54 | } 55 | else 56 | Debug.Log("需要一个脚本对象,必须挂载脚本上面"); 57 | } 58 | if( m_cParent == null ) 59 | { 60 | GameObject.DestroyImmediate(GameObject.Find("NavMeshParent")); 61 | m_cParent = new GameObject("NavMeshParent"); 62 | m_cParent.transform.parent = this.m_cNavMono.transform; 63 | } 64 | } 65 | 66 | void OnDisable() 67 | { 68 | if (m_eState == EditState.StateEditArea || m_eState == EditState.StateFindArea) 69 | { 70 | if (this.m_cNavMono.gameObject != null) 71 | { 72 | Selection.activeGameObject = this.m_cNavMono.gameObject; 73 | 74 | //Debug.Log("请先关闭编辑状态(点击FinishArea按钮),才能选择别的对象"); 75 | } 76 | } 77 | } 78 | 79 | void OnDestroy() 80 | { 81 | this.m_cNavMono = null; 82 | } 83 | 84 | private static Vector3 sPos; 85 | private static Vector3 ePos; 86 | private static int m_iIndex = 0; 87 | void OnSceneGUI() 88 | { 89 | if (Event.current == null) 90 | return; 91 | 92 | Event e = Event.current; 93 | 94 | if (this.m_cNavMono == null) 95 | return; 96 | 97 | // only in edit mode will auto add point with mouse click; 98 | if (m_eState == EditState.StateEditArea) 99 | { 100 | if (e.button == 0 && e.type == EventType.MouseDown) 101 | { 102 | NavEditAreaGroup group = NavEditAreaManager.sInstance.GetGroup(this.m_cNavMono.m_iSelGroup); 103 | if (group == null) 104 | return; 105 | NavEditArea area = group.GetArea(this.m_cNavMono.m_iSelArea); 106 | if(area == null) 107 | return; 108 | 109 | Ray ray = HandleUtility.GUIPointToWorldRay(e.mousePosition); 110 | //int layerMask = 1 << 9; 111 | RaycastHit hit; 112 | if (Physics.Raycast(ray.origin, ray.direction, out hit, Mathf.Infinity)) 113 | { 114 | Vector3 placePos = hit.point; 115 | //placePos.y = pointHeight; 116 | 117 | // generate obj 118 | GameObject point = GameObject.CreatePrimitive(PrimitiveType.Sphere); 119 | point.transform.position = placePos; 120 | point.transform.parent = m_cParent.transform; 121 | point.transform.localScale /= 5f; 122 | point.name = "point"; 123 | area.Insert(point , this.m_cNavMono.m_iSelPoint); 124 | this.m_cNavMono.m_iSelPoint++; 125 | if( this.m_cNavMono.m_iSelPoint >= area.m_lstPoints.Count ) 126 | this.m_cNavMono.m_iSelPoint = area.m_lstPoints.Count -1; 127 | } 128 | e.Use(); 129 | } 130 | } 131 | else if( m_eState == EditState.StateFindArea ) 132 | { 133 | if (e.button == 0 && e.type == EventType.MouseDown) 134 | { 135 | Ray ray = HandleUtility.GUIPointToWorldRay(e.mousePosition); 136 | //int layerMask = 1 << 9; 137 | RaycastHit hit; 138 | if (Physics.Raycast(ray.origin, ray.direction, out hit, Mathf.Infinity)) 139 | { 140 | if( m_iIndex == 0 ) 141 | { 142 | sPos = hit.point; 143 | m_iIndex++; 144 | } 145 | else 146 | { 147 | m_iIndex = 0; 148 | ePos = hit.point; 149 | this.m_cNavMono.Seek(sPos , ePos); 150 | } 151 | 152 | } 153 | } 154 | } 155 | } 156 | 157 | private Vector2 groupUIPos; 158 | private Vector2 areaUIPos; 159 | private Vector2 pointUIPos; 160 | override public void OnInspectorGUI() 161 | { 162 | EditorGUILayout.BeginVertical(); 163 | { 164 | NavEditAreaGroup group = NavEditAreaManager.sInstance.GetGroup(this.m_cNavMono.m_iSelGroup); 165 | NavEditArea area = null; 166 | if( group != null) 167 | { 168 | area = group.GetArea(this.m_cNavMono.m_iSelArea); 169 | } 170 | 171 | //========================= groups ============================= 172 | GUILayout.BeginVertical(); 173 | { 174 | GUILayout.Label("All Groups"); 175 | groupUIPos = GUILayout.BeginScrollView( groupUIPos ,GUILayout.Height(150)); 176 | { 177 | List lst = new List(); 178 | for(int i = 0 ; i lst = new List(); 227 | for(int i = 0 ; i< group.m_lstArea.Count ; i++) 228 | { 229 | lst.Add( "Area(" + i.ToString() + ")" ); 230 | } 231 | this.m_cNavMono.m_iSelArea = GUILayout.SelectionGrid( 232 | this.m_cNavMono.m_iSelArea, 233 | lst.ToArray(),1); 234 | if( m_iLastSelArea != this.m_cNavMono.m_iSelArea ) 235 | { 236 | m_iLastSelArea = this.m_cNavMono.m_iSelArea; 237 | this.m_cNavMono.m_iSelPoint = 0; 238 | } 239 | // FocusEditPanel(); 240 | } 241 | } 242 | GUILayout.EndScrollView(); 243 | 244 | GUILayout.BeginHorizontal(); 245 | { 246 | GUI.enabled = group != null; 247 | if( GUILayout.Button("Create Frame Area")) 248 | { 249 | Debug.Log("create frame area"); 250 | group.CreateFrameArea(); 251 | this.m_cNavMono.m_iSelArea = 0; 252 | this.m_cNavMono.m_iSelPoint = 0; 253 | } 254 | if( GUILayout.Button("Create Area")) 255 | { 256 | Debug.Log("create area"); 257 | group.CreateArea(); 258 | this.m_cNavMono.m_iSelArea = group.m_lstArea.Count-1; 259 | this.m_cNavMono.m_iSelPoint = 0; 260 | } 261 | if( GUILayout.Button("Delete Area")) 262 | { 263 | Debug.Log("delete area"); 264 | group.RemoveArea(this.m_cNavMono.m_iSelArea); 265 | this.m_cNavMono.m_iSelArea--; 266 | if(this.m_cNavMono.m_iSelArea < 0 ) 267 | this.m_cNavMono.m_iSelArea = 0; 268 | this.m_cNavMono.m_iSelPoint = 0; 269 | } 270 | } 271 | GUILayout.EndHorizontal(); 272 | } 273 | GUILayout.EndVertical(); 274 | 275 | //====================== points ============================== 276 | GUILayout.BeginVertical(); 277 | { 278 | GUILayout.Label("All Points"); 279 | pointUIPos = GUILayout.BeginScrollView( pointUIPos ,GUILayout.Height(150)); 280 | { 281 | if(group != null && area != null) 282 | { 283 | List lst = new List(); 284 | for(int i = 0 ; i< area.m_lstPoints.Count ; i++) 285 | { 286 | lst.Add( "Point(" + i + ")"); 287 | } 288 | this.m_cNavMono.m_iSelPoint = GUILayout.SelectionGrid( 289 | this.m_cNavMono.m_iSelPoint, 290 | lst.ToArray(),1); 291 | // FocusEditPanel(); 292 | } 293 | } 294 | GUILayout.EndScrollView(); 295 | GUI.enabled = m_eState != EditState.StateEditArea; 296 | if(GUILayout.Button("Editor Point",GUILayout.Height(30))) 297 | { 298 | m_eState = EditState.StateEditArea; 299 | } 300 | GUI.enabled = m_eState != EditState.StateFindArea; 301 | if(GUILayout.Button("Find Path",GUILayout.Height(30))) 302 | { 303 | m_eState = EditState.StateFindArea; 304 | } 305 | GUI.enabled = (m_eState == EditState.StateEditArea || m_eState == EditState.StateFindArea); 306 | if(GUILayout.Button("Finish Point",GUILayout.Height(30))) 307 | { 308 | m_eState = EditState.StateFinishArea; 309 | } 310 | if(GUILayout.Button("Delete Point",GUILayout.Height(30))) 311 | { 312 | Debug.Log("delete point"); 313 | if(area != null ) 314 | { 315 | area.RemoveAt(this.m_cNavMono.m_iSelPoint); 316 | this.m_cNavMono.m_iSelPoint--; 317 | if(this.m_cNavMono.m_iSelPoint < 0 ) 318 | this.m_cNavMono.m_iSelPoint = 0; 319 | } 320 | } 321 | GUI.enabled = true; 322 | } 323 | GUILayout.EndVertical(); 324 | 325 | //===================== ============================ 326 | } 327 | EditorGUILayout.EndVertical(); 328 | 329 | 330 | GUILayout.Label("NavMesh"); 331 | this.m_cNavMono.m_bShowMesh = GUILayout.Toggle(this.m_cNavMono.m_bShowMesh , "NavMesh Show"); 332 | this.m_cNavMono.m_bShowArea = GUILayout.Toggle(this.m_cNavMono.m_bShowArea , "Area Show"); 333 | if( GUILayout.Button("Create NavMesh",GUILayout.Height(30))) 334 | { 335 | this.m_cNavMono.CreateNavMesh(); 336 | } 337 | 338 | GUILayout.Label("Area Group Save/Load"); 339 | GUILayout.BeginHorizontal(); 340 | { 341 | if( GUILayout.Button("Save AreaGroup",GUILayout.Height(30))) 342 | { 343 | Debug.Log("save area group"); 344 | string pathfile = EditorUtility.SaveFilePanel("Save Area Group" , Application.dataPath , "map" , UNWALK_EXTENSION); 345 | NavEditAreaManager.sInstance.SaveAreaGroup(pathfile); 346 | } 347 | if( GUILayout.Button("Load AreaGroup",GUILayout.Height(30))) 348 | { 349 | Debug.Log("load area group"); 350 | string pathfile = EditorUtility.OpenFilePanel("Open Area Group" , Application.dataPath , UNWALK_EXTENSION); 351 | NavEditAreaManager.sInstance.LoadAreaGroup(pathfile , m_cParent); 352 | } 353 | } 354 | GUILayout.EndHorizontal(); 355 | 356 | GUILayout.Label("NavMesh Save/Load"); 357 | GUILayout.BeginHorizontal(); 358 | { 359 | if(GUILayout.Button("Save NavMesh",GUILayout.Height(30))) 360 | { 361 | Debug.Log("save navmesh"); 362 | string pathfile = EditorUtility.SaveFilePanel("Save NavMesh" , Application.dataPath , "map" , NAVMESH_EXTENSION); 363 | this.m_cNavMono.SaveNavMesh(pathfile); 364 | } 365 | if(GUILayout.Button("Load NavMesh",GUILayout.Height(30))) 366 | { 367 | Debug.Log("load navmesh"); 368 | string pathfile = EditorUtility.OpenFilePanel("Open NavMesh" , Application.dataPath , NAVMESH_EXTENSION); 369 | this.m_cNavMono.LoadNavMesh(pathfile); 370 | } 371 | } 372 | GUILayout.EndHorizontal(); 373 | 374 | } 375 | } 376 | 377 | } 378 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/Editor/EditorNavMesh.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 65182398383394d1d97ec3f4d816081d 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/Line2D.cs: -------------------------------------------------------------------------------- 1 |  2 | using UnityEngine; 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | 7 | // Line2D.cs 8 | // Author: Lu Zexi 9 | // 2013-10-04 10 | 11 | 12 | 13 | namespace Game.NavMesh 14 | { 15 | /// 16 | /// 点与线段所在位置 17 | /// 18 | public enum PointSide 19 | { 20 | ON_LINE = 0, //在线段上 21 | LEFT_SIDE = 1, //在线段左边 22 | RIGHT_SIDE = 2, //在线段右边 23 | }; 24 | 25 | /// 26 | /// 两线段交叉状态 27 | /// 28 | public enum LineCrossState 29 | { 30 | COLINE = 0, //外线口 31 | PARALLEL, //平行线 32 | CROSS, //相交 33 | NOT_CROSS //无相交 34 | } 35 | 36 | /// 37 | /// 2D线段类 38 | /// 39 | public class Line2D 40 | { 41 | private Vector2 m_cStartPoint; //起始点 42 | private Vector2 m_cEndPoint; //结束点 43 | 44 | public Line2D(Vector2 ps, Vector2 pe) 45 | { 46 | this.m_cStartPoint = ps; 47 | this.m_cEndPoint = pe; 48 | } 49 | 50 | /// 51 | /// 检测线段是否在给定线段列表里面 52 | /// 53 | /// 线段列表 54 | /// 检查线段 55 | /// 如果在,返回索引 56 | /// 57 | public static bool CheckLineIn(List allLines, Line2D chkLine, out int index) 58 | { 59 | index = -1; 60 | for (int i = 0; i < allLines.Count; i++) 61 | { 62 | Line2D line = allLines[i]; 63 | if (line.Equals(chkLine)) 64 | { 65 | index = i; 66 | return true; 67 | } 68 | } 69 | return false; 70 | } 71 | 72 | /// 73 | /// 判断点与直线的关系,假设你站在a点朝向b点, 74 | /// 则输入点与直线的关系分为:Left, Right or Centered on the line 75 | /// 76 | /// 判断点 77 | /// 判断结果 78 | public PointSide ClassifyPoint(Vector2 point) 79 | { 80 | if (point == this.m_cStartPoint || point == this.m_cEndPoint) 81 | return PointSide.ON_LINE; 82 | //向量a 83 | Vector2 vectorA = this.m_cEndPoint - this.m_cStartPoint; 84 | //向量b 85 | Vector2 vectorB = point - this.m_cStartPoint; 86 | 87 | float crossResult = NMath.CrossProduct(vectorA, vectorB); 88 | if (NMath.IsEqualZero(crossResult)) 89 | return PointSide.ON_LINE; 90 | else if (crossResult < 0) 91 | return PointSide.RIGHT_SIDE; 92 | else 93 | return PointSide.LEFT_SIDE; 94 | } 95 | 96 | /// 97 | /// 计算两条二维线段的交点 98 | /// 99 | /// Other line 100 | /// 输出的线段交点 101 | /// 返回值说明了两条线段的位置关系(COLINE,PARALLEL,CROSS,NOT_CROSS) 102 | public LineCrossState Intersection(Line2D other, out Vector2 intersectPoint) 103 | { 104 | intersectPoint.x = intersectPoint.y = float.NaN; 105 | if (!NMath.CheckCross(this.m_cStartPoint, this.m_cEndPoint, other.m_cStartPoint, other.m_cEndPoint)) 106 | return LineCrossState.NOT_CROSS; 107 | 108 | double A1, B1, C1, A2, B2, C2; 109 | 110 | A1 = this.m_cEndPoint.y - this.m_cStartPoint.y; 111 | B1 = this.m_cStartPoint.x - this.m_cEndPoint.x; 112 | C1 = this.m_cEndPoint.x * this.m_cStartPoint.y - this.m_cStartPoint.x * this.m_cEndPoint.y; 113 | 114 | A2 = other.m_cEndPoint.y - other.m_cStartPoint.y; 115 | B2 = other.m_cStartPoint.x - other.m_cEndPoint.x; 116 | C2 = other.m_cEndPoint.x * other.m_cStartPoint.y - other.m_cStartPoint.x * other.m_cEndPoint.y; 117 | 118 | if (NMath.IsEqualZero(A1 * B2 - B1 * A2)) 119 | { 120 | if (NMath.IsEqualZero((A1 + B1) * C2 - (A2 + B2) * C1)) 121 | { 122 | return LineCrossState.COLINE; 123 | } 124 | else 125 | { 126 | return LineCrossState.PARALLEL; 127 | } 128 | } 129 | else 130 | { 131 | intersectPoint.x = (float)((B2 * C1 - B1 * C2) / (A2 * B1 - A1 * B2)); 132 | intersectPoint.y = (float)((A1 * C2 - A2 * C1) / (A2 * B1 - A1 * B2)); 133 | return LineCrossState.CROSS; 134 | } 135 | } 136 | 137 | /// 138 | /// 获得直线方向 139 | /// 140 | /// 矢量 141 | public Vector2 GetDirection() 142 | { 143 | Vector2 dir = this.m_cEndPoint - this.m_cStartPoint; 144 | return dir; 145 | } 146 | 147 | /// 148 | /// 选段长度 149 | /// 150 | /// 151 | public float GetLength() 152 | { 153 | return (float)Math.Sqrt(Math.Pow(this.m_cStartPoint.x - this.m_cEndPoint.x, 2.0) + Math.Pow(this.m_cStartPoint.y - this.m_cEndPoint.y, 2.0)); 154 | } 155 | 156 | /// 157 | /// 两条线段是否相等 158 | /// 159 | /// 判断对象 160 | /// 是否相等 161 | public bool Equals(Line2D line) 162 | { 163 | //只是一个点 164 | if (NMath.IsEqualZero(line.m_cStartPoint - line.m_cEndPoint) || 165 | NMath.IsEqualZero(m_cStartPoint - m_cEndPoint)) 166 | return false; 167 | 168 | //whatever the direction 169 | bool bEquals = NMath.IsEqualZero(m_cStartPoint - line.m_cStartPoint) ? true : NMath.IsEqualZero(m_cStartPoint - line.m_cEndPoint); 170 | if (bEquals) 171 | { 172 | bEquals = NMath.IsEqualZero(m_cEndPoint - line.m_cStartPoint) ? true : NMath.IsEqualZero(m_cEndPoint - line.m_cEndPoint); 173 | } 174 | return bEquals; 175 | } 176 | 177 | /// 178 | /// 获取起始点 179 | /// 180 | /// 起始点 181 | public Vector2 GetStartPoint() 182 | { 183 | return this.m_cStartPoint; 184 | } 185 | 186 | /// 187 | /// 获取结束点 188 | /// 189 | /// 结束点 190 | public Vector2 GetEndPoint() 191 | { 192 | return this.m_cEndPoint; 193 | } 194 | 195 | } 196 | 197 | } 198 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/Line2D.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9450ef14c695a44b694409d92fc97bca 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/NMath.cs: -------------------------------------------------------------------------------- 1 |  2 | using UnityEngine; 3 | using System; 4 | 5 | 6 | // NMath.cs 7 | // Author: Lu Zexi 8 | // 2013-10-04 9 | 10 | 11 | 12 | namespace Game.NavMesh 13 | { 14 | 15 | /// 16 | /// NavMesh专用数学类 17 | /// 18 | public class NMath 19 | { 20 | private const float EPSILON = 1e-005f; //最小常量 21 | 22 | /// 23 | /// 返回顶角在o点,起始边为os,终止边为oe的夹角, 即∠soe (单位:弧度) 24 | /// 矢量os 在矢量 oe的顺时针方向,返回正值;否则返回负值 25 | /// 26 | /// 27 | /// 28 | /// 29 | /// 返回弧度 30 | public static double LineRadian(Vector2 s, Vector2 o, Vector2 e) 31 | { 32 | float dx12 = s.x - o.x; 33 | float dy12 = s.y - o.y; 34 | float dx32 = e.x - o.x; 35 | float dy32 = e.y - o.y; 36 | 37 | //角度计算公式s→ * e→ = |s|*|e|*cosθ 38 | 39 | double cosfi = dx12 * dx32 + dy12 * dy32; 40 | 41 | float norm = (dx12 * dx12 + dy12 * dy12) * (dx32 * dx32 + dy32 * dy32); 42 | 43 | cosfi /= Math.Sqrt(norm); 44 | 45 | if (cosfi >= 1.0) return 0; 46 | if (cosfi <= -1.0) return -Math.PI; 47 | 48 | double angleRadian = Math.Acos(cosfi); 49 | 50 | // 说明矢量os 在矢量 oe的顺时针方向 51 | if (dx12 * dy32 - dy12 * dx32 > 0) 52 | return angleRadian; 53 | 54 | return -angleRadian; 55 | 56 | } 57 | 58 | /// 59 | /// 获得外接圆的包围盒 60 | /// 61 | /// 62 | /// 63 | public static Rect GetCircleBoundBox(Circle circle) 64 | { 65 | Rect bBox = new Rect(); 66 | bBox.xMin = circle.center.x - circle.radius; 67 | bBox.xMax = circle.center.x + circle.radius; 68 | bBox.yMin = circle.center.y - circle.radius; 69 | bBox.yMax = circle.center.y + circle.radius; 70 | return bBox; 71 | } 72 | 73 | /// 74 | /// 返回三角形的外接圆 75 | /// 76 | /// 77 | /// 78 | /// 79 | /// 80 | public static Circle CreateCircle(Vector2 p1, Vector2 p2, Vector2 p3) 81 | { 82 | if (!NMath.IsEqualZero(p1.y - p2.y) || 83 | !NMath.IsEqualZero(p2.y - p3.y)) 84 | { 85 | double yc, xc; 86 | float m1 = -(p2.x - p1.x) / (p2.y - p1.y); 87 | float m2 = -(p3.x - p2.x) / (p3.y - p2.y); 88 | double mx1 = (p1.x + p2.x) / 2.0; 89 | double mx2 = (p2.x + p3.x) / 2.0; 90 | double my1 = (p1.y + p2.y) / 2.0; 91 | double my2 = (p2.y + p3.y) / 2.0; 92 | 93 | if (NMath.IsEqualZero(p1.y - p2.y)) 94 | { 95 | xc = (p2.x + p1.x) / 2.0; 96 | yc = m2 * (xc - mx2) + my2; 97 | } 98 | else if (NMath.IsEqualZero(p3.y - p2.y)) 99 | { 100 | xc = (p3.x + p2.x) / 2.0; 101 | yc = m1 * (xc - mx1) + my1; 102 | } 103 | else 104 | { 105 | xc = (m1 * mx1 - m2 * mx2 + my2 - my1) / (m1 - m2); 106 | yc = m1 * (xc - mx1) + my1; 107 | } 108 | 109 | double dx = p2.x - xc; 110 | double dy = p2.y - yc; 111 | double rsqr = dx * dx + dy * dy; 112 | double r = Math.Sqrt(rsqr); 113 | 114 | return new Circle(new Vector2((float)xc, (float)yc), (float)r); 115 | } 116 | return new Circle(new Vector2(0, 0), 0); 117 | } 118 | 119 | /// 120 | /// Calculate the circle tangency. 121 | /// 122 | /// The circle tangency. 123 | /// C. 124 | /// St. 125 | public static Vector2[] CalCircleTangency( Circle c , Vector2 st ) 126 | { 127 | Vector2 dir; 128 | float dis = (c.center - st).magnitude; 129 | float temp= Mathf.Sqrt(dis*dis-c.radius*c.radius); 130 | float sina=temp/dis; 131 | float cosa=c.radius/dis; 132 | dir.x=(st.x-c.center.x)/dis*c.radius; 133 | dir.y=(st.y-c.center.y)/dis*c.radius; 134 | 135 | Vector2[] res = new Vector2[2]; 136 | 137 | res[0].x = c.center.x+(dir.x*cosa-dir.y*sina); 138 | res[0].y = c.center.y+(dir.x*sina+dir.y*cosa); 139 | 140 | res[1].x = c.center.x+(dir.x*cosa+dir.y*sina); 141 | res[1].y = c.center.y+(-dir.x*sina+dir.y*cosa); 142 | 143 | return res; 144 | } 145 | 146 | /// 147 | /// 将线段终点延长 148 | /// 149 | /// 起始点 150 | /// 终点 151 | /// 延长长度 152 | /// 153 | public static Vector2 ExtendPos(Vector2 startPos, Vector2 tarPos, int length) 154 | { 155 | Vector2 newPos = tarPos; 156 | float slopeRate = Math.Abs((tarPos.y - startPos.y) / (tarPos.x - startPos.x)); 157 | float xLength, yLength; 158 | if (slopeRate < 1) 159 | { 160 | yLength = length; 161 | xLength = length / slopeRate; 162 | } 163 | else 164 | { 165 | xLength = length; 166 | yLength = length * slopeRate; 167 | } 168 | 169 | if (tarPos.x > startPos.x) 170 | newPos.x += xLength; 171 | else 172 | newPos.x -= xLength; 173 | 174 | if (tarPos.y > startPos.y) 175 | newPos.y += yLength; 176 | else 177 | newPos.y -= yLength; 178 | 179 | return newPos; 180 | } 181 | 182 | /// 183 | /// 判断矩形是否相交 184 | /// 185 | /// 矩形1 186 | /// 矩形2 187 | /// 是否相交 188 | public static bool CheckCross(Rect rec1, Rect rec2) 189 | { 190 | Rect ret = new Rect(); 191 | ret.xMin = Mathf.Max(rec1.xMin, rec2.xMin); 192 | ret.xMax = Mathf.Min(rec1.xMax, rec2.xMax); 193 | ret.yMin = Mathf.Max(rec1.yMin, rec2.yMin); 194 | ret.yMax = Mathf.Min(rec1.yMax, rec2.yMax); 195 | 196 | if (ret.xMin > ret.xMax || ret.yMin > ret.yMax) 197 | { 198 | // no intersection, return empty 199 | return false; 200 | } 201 | return true; 202 | } 203 | 204 | /// 205 | /// 根据线段生成矩形 206 | /// 207 | /// 线段 208 | /// 矩形 209 | public static Rect LineRect(Line2D linePath) 210 | { 211 | Rect lineRect = new Rect(); 212 | 213 | if (linePath.GetStartPoint().x < linePath.GetEndPoint().x) 214 | lineRect.xMin = linePath.GetStartPoint().x; 215 | else 216 | lineRect.xMin = linePath.GetEndPoint().x; 217 | 218 | if (linePath.GetStartPoint().y < linePath.GetEndPoint().y) 219 | lineRect.yMin = linePath.GetStartPoint().y; 220 | else 221 | lineRect.yMin = linePath.GetEndPoint().y; 222 | 223 | lineRect.width = Math.Abs(linePath.GetEndPoint().x - linePath.GetStartPoint().x); 224 | lineRect.height = Math.Abs(linePath.GetEndPoint().y - linePath.GetStartPoint().y); 225 | 226 | return lineRect; 227 | } 228 | 229 | /// 230 | /// 检查线段是否相交 231 | /// 232 | /// line1 start point 233 | /// line1 end point 234 | /// line2 start point 235 | /// line2 end point 236 | /// is cross 237 | public static bool CheckCross(Vector2 sp1, Vector2 ep1, Vector2 sp2, Vector2 ep2) 238 | { 239 | if (Math.Max(sp1.x, ep1.x) < Math.Min(sp2.x, ep2.x)) 240 | { 241 | return false; 242 | } 243 | if (Math.Min(sp1.x, ep1.x) > Math.Max(sp2.x, ep2.x)) 244 | { 245 | return false; 246 | } 247 | if (Math.Max(sp1.y, ep1.y) < Math.Min(sp2.y, ep2.y)) 248 | { 249 | return false; 250 | } 251 | if (Math.Min(sp1.y, ep1.y) > Math.Max(sp2.y, ep2.y)) 252 | { 253 | return false; 254 | } 255 | 256 | float temp1 = CrossProduct((sp1 - sp2), (ep2 - sp2)) * CrossProduct((ep2 - sp2), (ep1 - sp2)); 257 | float temp2 = CrossProduct((sp2 - sp1), (ep1 - sp1)) * CrossProduct((ep1 - sp1), (ep2 - sp1)); 258 | 259 | if ((temp1 >= 0) && (temp2 >= 0)) 260 | { 261 | return true; 262 | } 263 | 264 | return false; 265 | } 266 | 267 | /// 268 | /// Checks the cross. 269 | /// 270 | /// true, if cross was checked, false otherwise. 271 | /// Line. 272 | /// Tri. 273 | public static bool CheckCross( Line2D line , Triangle tri ) 274 | { 275 | for(int i = 0 ; i < 3 ; i++ ) 276 | { 277 | Line2D lineTri = tri.GetSide(i); 278 | if( CheckCross(line.GetStartPoint() , line.GetEndPoint() , 279 | lineTri.GetStartPoint() , lineTri.GetEndPoint()) 280 | ) 281 | { 282 | return true; 283 | } 284 | } 285 | return false; 286 | } 287 | 288 | /// 289 | /// Checks the cross. 290 | /// 291 | /// true, if cross was checked, false otherwise. 292 | /// Line. 293 | /// Cir. 294 | public static bool CheckCross( Line2D line , Circle cir ) 295 | { 296 | return CheckCross(line , cir.center , cir.radius); 297 | } 298 | 299 | /// 300 | /// Checks the cross. 301 | /// 302 | /// true, if cross was checked, false otherwise. 303 | /// Line. 304 | /// Position. 305 | /// Radius. 306 | public static bool CheckCross( Line2D line , Vector2 pos , float radius ) 307 | { 308 | float fDis = line.GetLength(); 309 | 310 | Vector2 d; 311 | d.x = (line.GetEndPoint().x - line.GetStartPoint().x) / fDis; 312 | d.y = (line.GetEndPoint().y - line.GetStartPoint().y) / fDis; 313 | 314 | Vector2 E; 315 | E.x = pos.x - line.GetStartPoint().x; 316 | E.y = pos.y - line.GetStartPoint().y; 317 | 318 | float a = E.x * d.x + E.y * d.y; 319 | float a2 = a * a; 320 | 321 | float e2 = E.x * E.x + E.y * E.y; 322 | 323 | float r2 = radius * radius; 324 | 325 | if ((r2 - e2 + a2) < 0) 326 | { 327 | return false; 328 | } 329 | return true; 330 | } 331 | 332 | /// 333 | /// r=multiply(sp,ep,op),得到(sp-op)*(ep-op)的叉积 334 | /// r>0:ep在矢量opsp的逆时针方向; 335 | /// r=0:opspep三点共线; 336 | /// r<0:ep在矢量opsp的顺时针方向 337 | /// 338 | /// opsp 339 | /// opep 340 | /// 341 | public static float CrossProduct(Vector2 p1, Vector2 p2) 342 | { 343 | return (p1.x * p2.y - p1.y * p2.x); 344 | } 345 | 346 | /// 347 | /// 两个矢量是否相同 348 | /// 349 | /// 350 | /// 351 | /// 352 | public static bool IsEqual(Vector2 v1, Vector2 v2) 353 | { 354 | return IsEqualZero(v1 - v2); 355 | } 356 | 357 | /// 358 | /// 点是否等于0 359 | /// 360 | /// 361 | /// 362 | public static bool IsEqualZero(Vector2 data) 363 | { 364 | if (IsEqualZero(data.x) && IsEqualZero(data.y)) 365 | return true; 366 | else 367 | return false; 368 | } 369 | 370 | /// 371 | /// 检查浮点数误差 372 | /// 373 | /// 374 | /// 375 | public static bool IsEqualZero(double data) 376 | { 377 | if (Math.Abs(data) <= EPSILON) 378 | return true; 379 | else 380 | return false; 381 | } 382 | } 383 | } 384 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/NMath.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dad57801c7fd74dc284b1261ddf59300 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/NavEditArea.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | // NavEditArea.cs 6 | // Author: Lu Zexi 7 | // 2014-07-08 8 | 9 | 10 | namespace Game.NavMesh 11 | { 12 | /// 13 | /// Nav edit area. 14 | /// 15 | public class NavEditArea 16 | { 17 | //public int m_iAreaID; //area id 18 | public List m_lstPoints = new List(); //the points 19 | 20 | /// 21 | /// Adds the point. 22 | /// 23 | /// Object. 24 | public void Add( GameObject obj ) 25 | { 26 | Debug.Log(obj.name); 27 | this.m_lstPoints.Add(obj); 28 | Debug.Log(obj.name); 29 | } 30 | 31 | /// 32 | /// Inserts the point. 33 | /// 34 | /// Object. 35 | /// Index. 36 | public void Insert( GameObject obj , int index ) 37 | { 38 | if( index >= this.m_lstPoints.Count - 1 ) 39 | { 40 | this.m_lstPoints.Add(obj); 41 | } 42 | else if( index >= 0 && index < this.m_lstPoints.Count) 43 | { 44 | this.m_lstPoints.Insert(index+1 ,obj); 45 | } 46 | } 47 | 48 | /// 49 | /// Removes at index. 50 | /// 51 | /// Index. 52 | public bool RemoveAt(int index) 53 | { 54 | if( index >= 0 && index < this.m_lstPoints.Count ) 55 | { 56 | GameObject.DestroyImmediate(this.m_lstPoints[index]); 57 | this.m_lstPoints.RemoveAt(index); 58 | return true; 59 | } 60 | return false; 61 | } 62 | 63 | /// 64 | /// Checks the line cross. 65 | /// 66 | /// true, if line cross was checked, false otherwise. 67 | public bool CheckLineCross() 68 | { 69 | Vector2 p1s, p1e, p2s, p2e; 70 | 71 | int iPointCount = this.m_lstPoints.Count; 72 | 73 | // 如果点的列表中只有两个点, 可以添加新点. 74 | if (iPointCount <= 2) 75 | { 76 | return true; 77 | } 78 | 79 | for (int i = 0; i < iPointCount - 2; i++) 80 | { 81 | p1s.x = this.m_lstPoints[i].transform.position.x; 82 | p1s.y = this.m_lstPoints[i].transform.position.z; 83 | p1e.x = this.m_lstPoints[i + 1].transform.position.x; 84 | p1e.y = this.m_lstPoints[i + 1].transform.position.z; 85 | 86 | for (int j = i + 2; j < iPointCount; j++) 87 | { 88 | if (j != iPointCount - 1) 89 | { 90 | p2s.x = this.m_lstPoints[j].transform.position.x; 91 | p2s.y = this.m_lstPoints[j].transform.position.z; 92 | p2e.x = this.m_lstPoints[j + 1].transform.position.x; 93 | p2e.y = this.m_lstPoints[j + 1].transform.position.z; 94 | } 95 | else 96 | { 97 | p2s.x = this.m_lstPoints[j].transform.position.x; 98 | p2s.y = this.m_lstPoints[j].transform.position.z; 99 | p2e.x = this.m_lstPoints[0].transform.position.x; 100 | p2e.y = this.m_lstPoints[0].transform.position.z; 101 | 102 | if (0 == i) 103 | { 104 | continue; 105 | } 106 | } 107 | 108 | if (NMath.CheckCross(p1s, p1e, p2s, p2e)) 109 | { 110 | return false; 111 | } 112 | 113 | } 114 | } 115 | return true; 116 | } 117 | 118 | /// 119 | /// Destroy this instance. 120 | /// 121 | public void Destroy() 122 | { 123 | foreach( GameObject item in this.m_lstPoints ) 124 | { 125 | GameObject.DestroyImmediate(item); 126 | } 127 | this.m_lstPoints.Clear(); 128 | } 129 | } 130 | 131 | } -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/NavEditArea.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2353ad324112f41e7aacc436578d4230 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/NavEditAreaGroup.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | 6 | 7 | // NavEditAreaGroup.cs 8 | // Author: Lu Zexi 9 | // 2014-07-08 10 | 11 | 12 | 13 | namespace Game.NavMesh 14 | { 15 | /// 16 | /// Nav edit area group. 17 | /// 18 | public class NavEditAreaGroup 19 | { 20 | //public int m_iID; 21 | public NavEditArea m_cFrameArea; 22 | public List m_lstArea = new List(); 23 | //public int m_iLastAreaID = 1; 24 | 25 | /// 26 | /// Gets the area. 27 | /// 28 | /// The area. 29 | /// Areaid. 30 | public NavEditArea GetArea( int areaIndex ) 31 | { 32 | if(areaIndex >=0 && areaIndex < this.m_lstArea.Count ) 33 | return this.m_lstArea[areaIndex]; 34 | return null; 35 | } 36 | 37 | /// 38 | /// Adds the new area. 39 | /// 40 | public NavEditArea CreateArea() 41 | { 42 | NavEditArea area = new NavEditArea(); 43 | this.m_lstArea.Add(area); 44 | return area; 45 | } 46 | 47 | /// 48 | /// Adds the frame area. 49 | /// 50 | /// The frame area. 51 | public NavEditArea CreateFrameArea() 52 | { 53 | if(this.m_cFrameArea != null ) 54 | { 55 | this.m_lstArea.Remove(this.m_cFrameArea); 56 | this.m_cFrameArea.Destroy(); 57 | this.m_cFrameArea = null; 58 | } 59 | NavEditArea area = new NavEditArea(); 60 | this.m_cFrameArea = area; 61 | this.m_lstArea.Insert(0,this.m_cFrameArea); 62 | return this.m_cFrameArea; 63 | } 64 | 65 | /// 66 | /// Removes the frame area. 67 | /// 68 | public void RemoveFrameArea() 69 | { 70 | this.m_lstArea.Remove(this.m_cFrameArea); 71 | this.m_cFrameArea.Destroy(); 72 | this.m_cFrameArea = null; 73 | } 74 | 75 | /// 76 | /// Removes the area. 77 | /// 78 | /// Index. 79 | public void RemoveArea( int areaIndex ) 80 | { 81 | this.m_lstArea[areaIndex].Destroy(); 82 | this.m_lstArea.RemoveAt(areaIndex); 83 | } 84 | 85 | /// 86 | /// Destroy this instance. 87 | /// 88 | public void Destroy() 89 | { 90 | foreach( NavEditArea item in this.m_lstArea ) 91 | { 92 | item.Destroy(); 93 | } 94 | this.m_lstArea.Clear(); 95 | this.m_cFrameArea = null; 96 | } 97 | 98 | } 99 | 100 | } -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/NavEditAreaGroup.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7a250d6273fbe46268300c56cd6d7a99 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/NavEditAreaManager.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | using System.Text; 4 | using System.IO; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | 8 | 9 | // NavEditAreaManager.cs 10 | // Author: Lu Zexi 11 | // 2014-07-08 12 | 13 | 14 | namespace Game.NavMesh 15 | { 16 | /// 17 | /// Nav edit area manager. 18 | /// 19 | public class NavEditAreaManager 20 | { 21 | public const string EDITVERSION = "NAV_AREA_GROUP_001"; 22 | public int m_iLastGroupID = 0; 23 | public List m_lstAreaGroup = new List(); 24 | 25 | private static NavEditAreaManager s_cInstance; 26 | public static NavEditAreaManager sInstance 27 | { 28 | get 29 | { 30 | if( s_cInstance == null ) 31 | s_cInstance = new NavEditAreaManager(); 32 | return s_cInstance; 33 | } 34 | } 35 | 36 | public NavEditAreaManager() 37 | { 38 | // 39 | } 40 | 41 | /// 42 | /// Gets the group. 43 | /// 44 | /// The group. 45 | /// Group index. 46 | public NavEditAreaGroup GetGroup( int groupIndex ) 47 | { 48 | if( groupIndex >= 0 && groupIndex < this.m_lstAreaGroup.Count ) 49 | return this.m_lstAreaGroup[groupIndex]; 50 | return null; 51 | } 52 | 53 | /// 54 | /// Adds the group. 55 | /// 56 | public void AddGroup() 57 | { 58 | NavEditAreaGroup group = new NavEditAreaGroup(); 59 | //group.m_iID = this.m_iLastGroupID++; 60 | this.m_lstAreaGroup.Add(group); 61 | } 62 | 63 | /// 64 | /// Removes the group. 65 | /// 66 | /// Groupid. 67 | public void RemoveGroup( int groupindex ) 68 | { 69 | this.m_lstAreaGroup[groupindex].Destroy(); 70 | this.m_lstAreaGroup.RemoveAt(groupindex); 71 | } 72 | 73 | /// 74 | /// Removes all group. 75 | /// 76 | public void RemoveAllGroup() 77 | { 78 | foreach( NavEditAreaGroup item in this.m_lstAreaGroup) 79 | { 80 | item.Destroy(); 81 | } 82 | this.m_lstAreaGroup.Clear(); 83 | } 84 | 85 | /// 86 | /// Gets the area. 87 | /// 88 | /// The area. 89 | /// Identifier. 90 | public NavEditArea GetArea( int groupIndex , int areaIndex ) 91 | { 92 | if( groupIndex >=0 && groupIndex < this.m_lstAreaGroup.Count) 93 | { 94 | NavEditAreaGroup group = this.m_lstAreaGroup[groupIndex]; 95 | return group.GetArea(areaIndex); 96 | } 97 | return null; 98 | } 99 | 100 | /// 101 | /// Adds the frame area. 102 | /// 103 | /// The frame area. 104 | /// Group index. 105 | public NavEditArea AddFrameArea( int groupIndex ) 106 | { 107 | return this.m_lstAreaGroup[groupIndex].CreateFrameArea(); 108 | } 109 | 110 | /// 111 | /// Adds the new area. 112 | /// 113 | public NavEditArea AddNewArea( int groupIndex ) 114 | { 115 | return this.m_lstAreaGroup[groupIndex].CreateArea(); 116 | } 117 | 118 | /// 119 | /// Removes the area. 120 | /// 121 | /// Areaid. 122 | public void RemoveArea( int groupIndex , int areaIndex ) 123 | { 124 | this.m_lstAreaGroup[groupIndex].RemoveArea(areaIndex); 125 | } 126 | 127 | /// 128 | /// Adds the new point. 129 | /// 130 | /// Areaid. 131 | /// Object. 132 | public void AddNewPoint( int groupIndex , int areaIndex , GameObject obj ) 133 | { 134 | this.m_lstAreaGroup[groupIndex].m_lstArea[areaIndex].Add(obj); 135 | } 136 | 137 | /// 138 | /// Inserts the point. 139 | /// 140 | /// Areaid. 141 | /// Point index. 142 | /// Object. 143 | public void InsertPoint( int groupIndex , int areaIndex , int pointIndex , GameObject obj ) 144 | { 145 | this.m_lstAreaGroup[groupIndex].m_lstArea[areaIndex].Insert(obj ,pointIndex); 146 | } 147 | 148 | /// 149 | /// Removes the point. 150 | /// 151 | /// Areaid. 152 | /// Point index. 153 | public void RemovePoint( int groupIndex, int areaIndex , int pointIndex ) 154 | { 155 | this.m_lstAreaGroup[groupIndex].m_lstArea[areaIndex].RemoveAt(pointIndex); 156 | } 157 | 158 | /// 159 | /// Checks all points. 160 | /// 161 | public void CheckAllPoints() 162 | { 163 | foreach( NavEditAreaGroup group in this.m_lstAreaGroup ) 164 | { 165 | foreach (NavEditArea item in group.m_lstArea ) 166 | { 167 | int pointNum = item.m_lstPoints.Count; 168 | for (int i = 0; i < pointNum; i++) 169 | { 170 | if (item.m_lstPoints[i] == null) 171 | { 172 | item.RemoveAt(i); 173 | i--; 174 | pointNum--; 175 | } 176 | } 177 | } 178 | } 179 | } 180 | 181 | /// 182 | /// Raies the height. 183 | /// 184 | /// The height. 185 | /// The x coordinate. 186 | /// The z coordinate. 187 | public float RayHeight( float x , float z ) 188 | { 189 | float SceneHeight = -100000.0f; 190 | Ray ray = new Ray();//构造射线 191 | ray.direction = -Vector3.up; 192 | ray.origin = new Vector3(x, 100000.0f, z); 193 | RaycastHit hitInfo; 194 | if (Physics.Raycast(ray, out hitInfo, Mathf.Infinity))//排除actor 195 | { 196 | SceneHeight = hitInfo.point.y; 197 | } 198 | return SceneHeight; 199 | } 200 | 201 | /// 202 | /// Saves the area. 203 | /// 204 | /// Path. 205 | public void SaveAreaGroup( string filePath ) 206 | { 207 | UTF8Encoding utf8 = new UTF8Encoding(); 208 | 209 | if (!Directory.Exists(Path.GetDirectoryName(filePath))) 210 | Directory.CreateDirectory(Path.GetDirectoryName(filePath)); 211 | 212 | FileStream fs = File.Create(filePath); 213 | BinaryWriter binWriter = new BinaryWriter(fs); 214 | 215 | // write version 216 | binWriter.Write(utf8.GetBytes(EDITVERSION)); 217 | binWriter.Write(this.m_lstAreaGroup.Count); 218 | foreach( NavEditAreaGroup item in this.m_lstAreaGroup ) 219 | { 220 | binWriter.Write(item.m_lstArea.Count); 221 | foreach (NavEditArea area in item.m_lstArea) 222 | { 223 | //save id 224 | //binWriter.Write(area.areaId); 225 | //为了和以前的格式保存一直,这里需要存入一个区域等级的标记 226 | //binWriter.Write(UnWalkFlag); 227 | //save point count 228 | binWriter.Write( area.m_lstPoints.Count ); 229 | 230 | foreach (GameObject point in area.m_lstPoints) 231 | { 232 | Vector3 pos = point.transform.position; 233 | //save x z info 234 | binWriter.Write(pos.x); 235 | binWriter.Write(pos.z); 236 | //为了和以前的格式保存一直,这里需要存入y 237 | binWriter.Write(pos.y); 238 | } 239 | } 240 | } 241 | 242 | binWriter.Close(); 243 | fs.Close(); 244 | 245 | Debug.Log("保存数据成功!"); 246 | } 247 | 248 | /// 249 | /// Loads the area. 250 | /// 251 | /// Path. 252 | /// Parent. 253 | public void LoadAreaGroup( string filePath , GameObject parentPoint ) 254 | { 255 | if (parentPoint == null) 256 | { 257 | Debug.LogError("the parent is null."); 258 | return; 259 | } 260 | float pointHeight = parentPoint.transform.position.y; 261 | // check file exist 262 | if (!File.Exists(filePath)) 263 | return; 264 | 265 | RemoveAllGroup(); 266 | 267 | // open file 268 | FileStream fs = File.Open(filePath, FileMode.Open); 269 | BinaryReader binReader = new BinaryReader(fs); 270 | 271 | try 272 | { 273 | // read version 274 | string currVersion = new string(binReader.ReadChars(EDITVERSION.Length)); 275 | if (currVersion == EDITVERSION) 276 | { 277 | int areaGroupCount = binReader.ReadInt32(); 278 | for( int k = 0 ; k < areaGroupCount ; k++ ) 279 | { 280 | NavEditAreaGroup group = new NavEditAreaGroup(); 281 | // read areas count 282 | int areaCount = binReader.ReadInt32(); 283 | 284 | for (int i = 0; i < areaCount; i++) 285 | { 286 | NavEditArea area = new NavEditArea(); 287 | 288 | //read point count 289 | int pointCount = binReader.ReadInt32(); 290 | 291 | for (int j = 0; j < pointCount; j++) 292 | { 293 | // read pos 294 | float x = binReader.ReadSingle(); 295 | //float z = binReader.ReadSingle(); 296 | float z = binReader.ReadSingle(); 297 | //为了和以前的格式保存一直,这里需要y 298 | float y = binReader.ReadSingle(); 299 | 300 | // auto generate point gameobject 301 | GameObject point = GameObject.CreatePrimitive(PrimitiveType.Sphere); 302 | float height = RayHeight(x, z); 303 | point.transform.position = new UnityEngine.Vector3(x, height, z); 304 | point.transform.parent = parentPoint.transform; 305 | point.transform.localScale /= 5; 306 | 307 | area.m_lstPoints.Add(point); 308 | } 309 | 310 | //the frame area. 311 | if( i == 0 ) 312 | group.m_cFrameArea = area; 313 | group.m_lstArea.Add(area); 314 | } 315 | this.m_lstAreaGroup.Add(group); 316 | } 317 | } 318 | else 319 | { 320 | Debug.LogError("version not match"); 321 | } 322 | } 323 | catch (EndOfStreamException e) 324 | { 325 | Debug.LogError(e.Message); 326 | } 327 | finally 328 | { 329 | binReader.Close(); 330 | fs.Close(); 331 | } 332 | 333 | Debug.Log("加载数据成功!"); 334 | } 335 | } 336 | } 337 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/NavEditAreaManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 008984c8f730746c482b6d815d59e612 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/NavMeshGen.cs: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | created: 2011/12/19 3 | created: 19:12:2011 13:31 4 | filename: SGWeb\DependProjects\NavMesh\NavMeshGen.cs 5 | file path: SGWeb\DependProjects\NavMesh 6 | file base: NavMeshGen 7 | file ext: cs 8 | author: Ivan 9 | 10 | purpose: 这个类用来生成导航网格(保存,加载),必须传入不可行走区域。 11 | 请加载NavMeshTestProject项目来运行单元测试,保证方法的正确 12 | *********************************************************************/ 13 | using System; 14 | using System.Collections.Generic; 15 | using UnityEngine; 16 | using System.Text; 17 | using System.IO; 18 | 19 | namespace Game.NavMesh 20 | { 21 | /// 22 | /// 生成结果 23 | /// 24 | public enum NavResCode 25 | { 26 | Success = 0, 27 | Failed = -1, 28 | NotFindDt = -2, 29 | FileNotExist = -3, 30 | VersionNotMatch = -4, 31 | } 32 | 33 | public sealed class NavMeshGen 34 | { 35 | // 使用者必须实现自己的加载数据函数,否则使用默认的C#的文件加载 [1/10/2012 Ivan] 36 | public delegate UnityEngine.Object GetResources(string fileName); 37 | // 更改为单例模式 38 | static readonly NavMeshGen s_cInstance = new NavMeshGen(); 39 | 40 | static NavMeshGen() { } 41 | 42 | public static NavMeshGen sInstance 43 | { 44 | get 45 | { 46 | return s_cInstance; 47 | } 48 | } 49 | 50 | // version info 51 | private const string NAVMESH_VERSION = "SGNAVMESH_01"; 52 | 53 | public List allEdges { get; set; } //所有阻挡区域的边 54 | public List allPoints { get; set; }//所有顶点列表 55 | public Line2D startEdge {get;set;} //start edge. 56 | 57 | public NavMeshGen() 58 | { 59 | allEdges = new List(); 60 | allPoints = new List(); 61 | } 62 | 63 | /// 64 | /// 保存导航网格信息到文件里面 65 | /// 66 | /// 文件全路径 67 | /// 68 | public NavResCode SaveNavMeshToFile(string filePath, List navTriangles) 69 | { 70 | if (navTriangles == null || navTriangles.Count == 0) 71 | return NavResCode.Failed; 72 | 73 | UTF8Encoding utf8 = new UTF8Encoding(); 74 | 75 | if (!Directory.Exists(Path.GetDirectoryName(filePath))) 76 | Directory.CreateDirectory(Path.GetDirectoryName(filePath)); 77 | 78 | FileStream fs = File.Create(filePath); 79 | BinaryWriter binWriter = new BinaryWriter(fs); 80 | 81 | // save version 82 | binWriter.Write(utf8.GetBytes(NAVMESH_VERSION)); 83 | // save triangle count 84 | binWriter.Write(navTriangles.Count); 85 | 86 | // 遍历导航网格并保存 87 | foreach (Triangle navTri in navTriangles) 88 | { 89 | if (navTri != null) 90 | { 91 | //保存网格ID 92 | binWriter.Write(navTri.GetID()); 93 | //保存网格的三角形顶点 94 | for (int i = 0; i < 3; i++) 95 | { 96 | binWriter.Write(navTri.GetPoint(i).x); 97 | binWriter.Write(navTri.GetPoint(i).y); 98 | } 99 | 100 | // 保存所有邻居边 101 | for (int i = 0; i < 3; i++) 102 | { 103 | binWriter.Write(navTri.GetNeighbor(i)); 104 | } 105 | 106 | // 保存每条边中点距离 107 | for (int i = 0; i < 3; i++) 108 | { 109 | binWriter.Write(navTri.GetWallDis(i)); 110 | } 111 | 112 | // 保存中心点位置 113 | binWriter.Write(navTri.GetCenter().x); 114 | binWriter.Write(navTri.GetCenter().y); 115 | 116 | //保存区域id 117 | binWriter.Write(navTri.GetGroupID()); 118 | } 119 | } 120 | 121 | // close file 122 | binWriter.Close(); 123 | fs.Close(); 124 | 125 | return NavResCode.Success; 126 | } 127 | 128 | /// 129 | /// 从文件中读取导航网格信息 130 | /// 131 | /// 文件全路径 132 | /// 读取的导航网格 133 | /// 134 | public NavResCode LoadNavMeshFromResource(string filePath, out List navTriangles, GetResources GetRes) 135 | { 136 | navTriangles = new List(); 137 | BinaryReader binReader = null; 138 | MemoryStream stream = null; 139 | 140 | if (GetRes == null) 141 | { 142 | if (!File.Exists(filePath)) 143 | return NavResCode.FileNotExist; 144 | 145 | // open file 146 | FileStream fs = File.Open(filePath, FileMode.Open); 147 | binReader = new BinaryReader(fs); 148 | } 149 | else 150 | { 151 | 152 | UnityEngine.Object FileObject = GetRes(filePath); 153 | if (FileObject == null) 154 | { 155 | return NavResCode.FileNotExist; 156 | } 157 | 158 | TextAsset asset = (TextAsset)FileObject; 159 | 160 | stream = new MemoryStream(asset.bytes); 161 | binReader = new BinaryReader(stream); 162 | } 163 | 164 | 165 | NavResCode res = NavResCode.Failed; 166 | try 167 | { 168 | res = LoadNavMeshFromFile(ref navTriangles, binReader); 169 | } 170 | catch 171 | { 172 | } 173 | finally 174 | { 175 | binReader.Close(); 176 | if( GetRes != null ) 177 | stream.Close(); 178 | } 179 | 180 | 181 | return res; 182 | } 183 | 184 | /// 185 | /// 从文件中读取导航网格信息(这个函数使用C#的文件加载) 186 | /// 187 | /// 188 | /// 189 | /// 190 | public NavResCode LoadNavMeshFromFile(string filePath, out List navTriangles) 191 | { 192 | //navTriangles = new List(); 193 | //// check file exist 194 | //if (!File.Exists(filePath)) 195 | // return NavResCode.FileNotExist; 196 | 197 | //// open file 198 | //FileStream fs = File.Open(filePath, FileMode.Open); 199 | //BinaryReader binReader = new BinaryReader(fs); 200 | 201 | //NavResCode res = NavResCode.Failed; 202 | //try 203 | //{ 204 | // res = LoadNavMeshFromFile(ref navTriangles, binReader); 205 | //} 206 | //catch 207 | //{ 208 | //} 209 | //finally 210 | //{ 211 | // binReader.Close(); 212 | // fs.Close(); 213 | //} 214 | 215 | 216 | //return res; 217 | return LoadNavMeshFromResource(filePath, out navTriangles, null); 218 | } 219 | 220 | /// 221 | /// 根据传进来BinaryReader读取数据 222 | /// 223 | /// 224 | /// 225 | /// 226 | public NavResCode LoadNavMeshFromFile(ref List navTriangles, BinaryReader binReader) 227 | { 228 | try 229 | { 230 | // 读取版本号 231 | string fileVersion = new string(binReader.ReadChars(NAVMESH_VERSION.Length)); 232 | if (fileVersion != NAVMESH_VERSION) 233 | return NavResCode.VersionNotMatch; 234 | // 读取导航三角形数量 235 | int navCount = binReader.ReadInt32(); 236 | Triangle currTri; 237 | for (int i = 0; i < navCount; i++) 238 | { 239 | currTri = new Triangle(); 240 | currTri.Read(binReader); 241 | navTriangles.Add(currTri); 242 | } 243 | } 244 | catch 245 | { 246 | //Debug.LogError(e.Message); 247 | return NavResCode.Failed; 248 | } 249 | finally 250 | { 251 | } 252 | 253 | return NavResCode.Success; 254 | } 255 | 256 | /// 257 | /// 创建导航网格 258 | /// 259 | /// 所有阻挡区域 260 | /// 输出的导航网格 261 | /// 262 | public NavResCode CreateNavMesh(List polyAll , ref int id , int groupid , ref List triAll) 263 | { 264 | triAll.Clear(); 265 | List allLines = new List(); //线段堆栈 266 | 267 | //Step1 保存顶点和边 268 | NavResCode initRes = InitData(polyAll); 269 | if (initRes != NavResCode.Success) 270 | return initRes; 271 | 272 | int lastNeighborId = -1; 273 | Triangle lastTri = null; 274 | 275 | //Step2.遍历边界边作为起点 276 | { 277 | Line2D sEdge = startEdge; 278 | allLines.Add(sEdge); 279 | Line2D edge = null; 280 | 281 | do 282 | { 283 | //Step3.选出计算出边的DT点,构成约束Delaunay三角形 284 | edge = allLines[allLines.Count - 1]; 285 | allLines.Remove(edge); 286 | 287 | Vector2 dtPoint; 288 | bool isFindDt = FindDT(edge, out dtPoint); 289 | if (!isFindDt) 290 | continue; 291 | Line2D lAD = new Line2D(edge.GetStartPoint(), dtPoint); 292 | Line2D lDB = new Line2D(dtPoint, edge.GetEndPoint()); 293 | 294 | //创建三角形 295 | Triangle delaunayTri = new Triangle(edge.GetStartPoint(), edge.GetEndPoint(), dtPoint, id++ , groupid); 296 | // 保存邻居节点 297 | // if (lastNeighborId != -1) 298 | // { 299 | // delaunayTri.SetNeighbor(lastNeighborId); 300 | // if(lastTri != null) 301 | // lastTri.SetNeighbor(delaunayTri.ID); 302 | // } 303 | //save result triangle 304 | triAll.Add(delaunayTri); 305 | 306 | // 保存上一次的id和三角形 307 | lastNeighborId = delaunayTri.GetID(); 308 | lastTri = delaunayTri; 309 | 310 | int lineIndex; 311 | //Step4.检测刚创建的的线段ad,db;如果如果它们不是约束边 312 | //并且在线段堆栈中,则将其删除,如果不在其中,那么将其放入 313 | if (!Line2D.CheckLineIn(allEdges, lAD, out lineIndex)) 314 | { 315 | if (!Line2D.CheckLineIn(allLines, lAD, out lineIndex)) 316 | allLines.Add(lAD); 317 | else 318 | allLines.RemoveAt(lineIndex); 319 | } 320 | 321 | if (!Line2D.CheckLineIn(allEdges, lDB, out lineIndex)) 322 | { 323 | if (!Line2D.CheckLineIn(allLines, lDB, out lineIndex)) 324 | allLines.Add(lDB); 325 | else 326 | allLines.RemoveAt(lineIndex); 327 | } 328 | 329 | //Step5.如果堆栈不为空,则转到第Step3.否则结束循环 330 | } while (allLines.Count > 0); 331 | } 332 | 333 | // 计算邻接边和每边中点距离 334 | for (int i = 0; i < triAll.Count; i++) 335 | { 336 | Triangle tri = triAll[i]; 337 | //// 计算每个三角形每边中点距离 338 | //tri.calcWallDistance(); 339 | 340 | // 计算邻居边 341 | for (int j = 0; j < triAll.Count; j++) 342 | { 343 | Triangle triNext = triAll[j]; 344 | if (tri.GetID() == triNext.GetID()) 345 | continue; 346 | 347 | int result = tri.isNeighbor(triNext); 348 | if (result != -1) 349 | { 350 | tri.SetNeighbor(result , triNext.GetID() ); 351 | } 352 | } 353 | } 354 | 355 | return NavResCode.Success; 356 | } 357 | 358 | bool needSplitBig = false; 359 | // 判断是否需要拆分大三角形 360 | public bool NeedSplitBig 361 | { 362 | get { return needSplitBig; } 363 | set { needSplitBig = value; } 364 | } 365 | int needSplitSize = 50; 366 | // 拆分的尺寸 367 | public int NeedSplitSize 368 | { 369 | get { return needSplitSize; } 370 | set { needSplitSize = value; } 371 | } 372 | // void SplitBigTriangle(ref List triangles) 373 | // { 374 | // // 将面积过大的三角形拆分成三个小三角形 375 | // for (int i = 0; i < triangles.Count; i++) 376 | // { 377 | // if (triangles[i].Area() > NeedSplitSize) 378 | // { 379 | // } 380 | // } 381 | // } 382 | 383 | /// 384 | /// 判断点是否是线段的可见点,组成的三角形没有和其他边相交 385 | /// 386 | /// 387 | /// 388 | /// 389 | private bool IsPointVisibleOfLine(Line2D line, Vector2 point) 390 | { 391 | if (line == null) 392 | return false; 393 | 394 | Vector2 sPnt = line.GetStartPoint(); 395 | Vector2 ePnt = line.GetEndPoint(); 396 | 397 | // 是否是线段端点 398 | if (point == sPnt || point == ePnt) 399 | return false; 400 | //点不在线段的右侧(多边形顶点顺序为顺时针) 401 | if (line.ClassifyPoint(point) != PointSide.RIGHT_SIDE) 402 | return false; 403 | 404 | if (!IsVisibleIn2Point(sPnt, point)) 405 | return false; 406 | 407 | if (!IsVisibleIn2Point(ePnt, point)) 408 | return false; 409 | 410 | return true; 411 | } 412 | 413 | /// 414 | /// 判断这条线段是否没有和其他的边相交 415 | /// 416 | /// 417 | /// 418 | /// 419 | private bool IsVisibleIn2Point(Vector2 sPnt, Vector2 ePnt) 420 | { 421 | Line2D line = new Line2D(sPnt, ePnt); 422 | Vector2 interPos; 423 | 424 | foreach (Line2D edge in allEdges) 425 | { 426 | if (edge.Intersection(line, out interPos) == LineCrossState.CROSS) 427 | { 428 | if (!NMath.IsEqualZero(sPnt - interPos) 429 | && !NMath.IsEqualZero(ePnt - interPos)) 430 | return false; 431 | } 432 | } 433 | return true; 434 | } 435 | 436 | /// 437 | /// 找到指定边的约束边DT 438 | /// 439 | /// 440 | /// 441 | private bool FindDT(Line2D line, out Vector2 dtPoint) 442 | { 443 | dtPoint = new Vector2(); 444 | if (line == null) 445 | return false; 446 | 447 | Vector2 ptA = line.GetStartPoint(); 448 | Vector2 ptB = line.GetEndPoint(); 449 | 450 | List visiblePnts = new List(); 451 | foreach (Vector2 point in allPoints) 452 | { 453 | if (IsPointVisibleOfLine(line, point)) 454 | visiblePnts.Add(point); 455 | } 456 | 457 | if (visiblePnts.Count == 0) 458 | return false; 459 | 460 | bool bContinue = false; 461 | dtPoint = visiblePnts[0]; 462 | 463 | do 464 | { 465 | bContinue = false; 466 | //Step1.构造三角形的外接圆,以及外接圆的包围盒 467 | Circle circle = NMath.CreateCircle(ptA, ptB, dtPoint); 468 | Rect boundBox = NMath.GetCircleBoundBox(circle); 469 | 470 | //Step2. 依次访问网格包围盒内的每个网格单元: 471 | //若某个网格单元中存在可见点 p, 并且 ∠p1pp2 > ∠p1p3p2,则令 p3=p,转Step1; 472 | //否则,转Step3. 473 | float angOld = (float)Math.Abs(NMath.LineRadian(ptA, dtPoint, ptB)); 474 | foreach (Vector2 pnt in visiblePnts) 475 | { 476 | if (pnt == ptA || pnt == ptB || pnt == dtPoint) 477 | continue; 478 | if (!boundBox.Contains(pnt)) 479 | continue; 480 | 481 | float angNew = (float)Math.Abs(NMath.LineRadian(ptA, pnt, ptB)); 482 | if (angNew > angOld) 483 | { 484 | dtPoint = pnt; 485 | bContinue = true; 486 | break; 487 | } 488 | } 489 | 490 | //false 转Step3 491 | } while (bContinue); 492 | 493 | //Step3. 若当前网格包围盒内所有网格单元都已被处理完, 494 | // 也即C(p1,p2,p3)内无可见点,则 p3 为的 p1p2 的 DT 点 495 | return true; 496 | } 497 | 498 | /// 499 | /// 初始化创建导航网格需要的数据 500 | /// 501 | /// 所有阻挡区域 502 | /// 503 | private NavResCode InitData(List polyAll) 504 | { 505 | allEdges = new List(); 506 | allPoints = new List(); 507 | 508 | PolyResCode resCode = NavUtil.UnionAllPolygon(ref polyAll); 509 | if (resCode != PolyResCode.Success) 510 | return NavResCode.Failed; 511 | // 保存所有点和边 512 | foreach (Polygon poly in polyAll) 513 | { 514 | if (poly.GetPoints().Count < 3) 515 | continue; 516 | AddPoint(poly.GetPoints()); 517 | AddEdge(poly.GetPoints()); 518 | } 519 | 520 | if(polyAll != null && polyAll.Count > 0 ) 521 | startEdge = new Line2D(polyAll[0].GetPoints()[0], polyAll[0].GetPoints()[1]); 522 | return NavResCode.Success; 523 | } 524 | 525 | /// 526 | /// 保存用到的顶点 527 | /// 528 | /// 529 | /// 530 | private NavResCode AddPoint(List points) 531 | { 532 | foreach (Vector2 point in points) 533 | { 534 | allPoints.Add(point); 535 | } 536 | 537 | return NavResCode.Success; 538 | } 539 | 540 | /// 541 | /// 保存所有边 542 | /// 543 | /// 544 | /// 545 | private NavResCode AddEdge(List points) 546 | { 547 | Vector2 pBegin = points[0]; 548 | for (int i = 1; i < points.Count; i++) 549 | { 550 | Vector2 pEnd = points[i]; 551 | Line2D line = new Line2D(pBegin, pEnd); 552 | allEdges.Add(line); 553 | pBegin = pEnd; 554 | } 555 | Line2D lineEnd = new Line2D(pBegin, points[0]); 556 | allEdges.Add(lineEnd); 557 | 558 | return NavResCode.Success; 559 | } 560 | 561 | } 562 | } 563 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/NavMeshGen.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d6eb707f8ae0c493d88969fcee802895 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/NavMonoEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | //using Game.NavMesh; 5 | 6 | // NavMonoEditor.cs 7 | // Author: Lu Zexi 8 | // 2014-07-08 9 | 10 | 11 | 12 | namespace Game.NavMesh 13 | { 14 | /// 15 | /// Nav mono editor. 16 | /// 17 | public class NavMonoEditor : MonoBehaviour 18 | { 19 | public static NavTriangle StopTri; 20 | public static List m_lstTriPath = new List(); 21 | private List m_lstTriangle = new List(); //navmesh triangle 22 | private List m_lstFindPath = new List(); //findPath; 23 | 24 | public bool m_bShowMesh = true; //is show mesh 25 | public bool m_bShowArea = true; 26 | public int m_iSelGroup; //the selected group 27 | public int m_iSelArea; //the selected area 28 | public int m_iSelPoint; //the selected point 29 | 30 | // Use this for initialization 31 | void Start () 32 | { 33 | // 34 | } 35 | 36 | // Update is called once per frame 37 | void Update () 38 | { 39 | // 40 | } 41 | 42 | void OnDrawGizmos() 43 | { 44 | DrawAllAreas(); 45 | DrawSelectPoint(); 46 | DrawNavMesh(); 47 | DrawFindPath(); 48 | DrawPathTriangle(); 49 | } 50 | 51 | //========================== draw area ======================================== 52 | 53 | /// 54 | /// Draws all areas. 55 | /// 56 | private void DrawAllAreas() 57 | { 58 | if(this.m_bShowArea) 59 | { 60 | for( int i = 0 ; i 77 | /// Draws the area. 78 | /// 79 | /// Areaid. 80 | private void DrawArea( NavEditArea area , bool selectarea ) 81 | { 82 | if(area == null ) 83 | return; 84 | 85 | List allPoints = area.m_lstPoints; 86 | if (allPoints.Count <= 0) 87 | return; 88 | 89 | if ( selectarea ) 90 | Gizmos.color = Color.red; 91 | else 92 | Gizmos.color = Color.green; 93 | 94 | for (int i = 0; i < allPoints.Count; i++) 95 | { 96 | if (allPoints[i] == null) 97 | { 98 | NavEditAreaManager.sInstance.CheckAllPoints(); 99 | Debug.LogError("there a null in the point gameobj lst." +i); 100 | return; 101 | } 102 | else 103 | { 104 | if (i != allPoints.Count - 1) 105 | { 106 | if (allPoints[i + 1] == null) 107 | { 108 | NavEditAreaManager.sInstance.CheckAllPoints(); 109 | Debug.LogError("there a null in the point gameobj lst."); 110 | return; 111 | } 112 | Gizmos.DrawLine(allPoints[i].transform.position, allPoints[i + 1].transform.position); 113 | } 114 | else 115 | { 116 | Gizmos.DrawLine(allPoints[i].transform.position, allPoints[0].transform.position); 117 | } 118 | } 119 | } 120 | } 121 | 122 | //========================= draw select point ======================== 123 | /// 124 | /// Draws the select point. 125 | /// 126 | private void DrawSelectPoint() 127 | { 128 | NavEditArea area = NavEditAreaManager.sInstance.GetArea( this.m_iSelGroup , this.m_iSelArea); 129 | if( area == null ) 130 | return; 131 | 132 | if( this.m_iSelPoint < 0 || this.m_iSelPoint >= area.m_lstPoints.Count ) 133 | return; 134 | 135 | Vector3 pos = area.m_lstPoints[this.m_iSelPoint].transform.position; 136 | pos.y += 1; 137 | Gizmos.DrawIcon( pos , "010.tif" ); 138 | } 139 | 140 | //======================= draw editor find triangle ====================================== 141 | /// 142 | /// Draws the path triangle. 143 | /// 144 | private void DrawPathTriangle() 145 | { 146 | if(m_lstTriPath != null && m_lstTriPath.Count > 0 ) 147 | { 148 | foreach (NavTriangle tri in m_lstTriPath) 149 | { 150 | Gizmos.color = Color.blue; 151 | 152 | Vector3 p1 = new Vector3(tri.GetPoint(0).x, 5, tri.GetPoint(0).y); 153 | Vector3 p2 = new Vector3(tri.GetPoint(1).x, 5, tri.GetPoint(1).y); 154 | Vector3 p3 = new Vector3(tri.GetPoint(2).x, 5, tri.GetPoint(2).y); 155 | Gizmos.DrawLine(p1, p2); 156 | Gizmos.DrawLine(p2, p3); 157 | Gizmos.DrawLine(p3, p1); 158 | } 159 | } 160 | if(StopTri != null) 161 | { 162 | Gizmos.color = Color.red; 163 | 164 | Vector3 p1 = new Vector3(StopTri.GetPoint(0).x, 7, StopTri.GetPoint(0).y); 165 | Vector3 p2 = new Vector3(StopTri.GetPoint(1).x, 7, StopTri.GetPoint(1).y); 166 | Vector3 p3 = new Vector3(StopTri.GetPoint(2).x, 7, StopTri.GetPoint(2).y); 167 | Gizmos.DrawLine(p1, p2); 168 | Gizmos.DrawLine(p2, p3); 169 | Gizmos.DrawLine(p3, p1); 170 | } 171 | } 172 | 173 | //======================= draw NavMesh ====================================== 174 | 175 | /// 176 | /// Draws the nav mesh. 177 | /// 178 | private void DrawNavMesh() 179 | { 180 | if (this.m_bShowMesh) 181 | { 182 | if (this.m_lstTriangle.Count != 0) 183 | { 184 | foreach (Triangle tri in m_lstTriangle) 185 | { 186 | Gizmos.color = Color.black; 187 | 188 | Vector3 p1 = new Vector3(tri.GetPoint(0).x, 0, tri.GetPoint(0).y); 189 | Vector3 p2 = new Vector3(tri.GetPoint(1).x, 0, tri.GetPoint(1).y); 190 | Vector3 p3 = new Vector3(tri.GetPoint(2).x, 0, tri.GetPoint(2).y); 191 | Gizmos.DrawLine(p1, p2); 192 | Gizmos.DrawLine(p2, p3); 193 | Gizmos.DrawLine(p3, p1); 194 | } 195 | } 196 | } 197 | } 198 | 199 | //======================== create navmesh ========================== 200 | 201 | /// 202 | /// Gets the un walk areas. 203 | /// 204 | /// The un walk areas. 205 | private List GetUnWalkAreas( List lst ) 206 | { 207 | List areas = new List(); 208 | for (int i = 0; i < lst.Count; i++) 209 | { 210 | List allPoints = lst[i].m_lstPoints; 211 | List allVecPnts = new List(); 212 | for (int j = 0; j < allPoints.Count; j++) 213 | { 214 | Vector2 pos = new Vector2(allPoints[j].transform.position.x, allPoints[j].transform.position.z); 215 | allVecPnts.Add(pos); 216 | } 217 | areas.Add(new Polygon(allVecPnts)); 218 | } 219 | 220 | return areas; 221 | } 222 | 223 | /// 224 | /// 创建导航网格 225 | /// 226 | public void CreateNavMesh() 227 | { 228 | Debug.Log("start..."); 229 | 230 | List lstTri = new List(); 231 | this.m_lstTriangle.Clear(); 232 | int startTriID = 0; 233 | for( int i = 0 ; i areas = GetUnWalkAreas(group.m_lstArea); 238 | Debug.Log(areas.Count + " polygon count"); 239 | NavResCode genResult = NavMeshGen.sInstance.CreateNavMesh(areas , ref startTriID , i , ref lstTri ); 240 | foreach( Triangle item in lstTri ) 241 | { 242 | this.m_lstTriangle.Add(item); 243 | } 244 | if (genResult != NavResCode.Success) 245 | Debug.LogError("faile"); 246 | } 247 | 248 | Debug.Log("triangle count "+ this.m_lstTriangle.Count); 249 | Debug.Log("end!"); 250 | } 251 | 252 | //========================= save or load navmesh ========================= 253 | 254 | /// 255 | /// Saves the nav mesh. 256 | /// 257 | /// Path. 258 | public void SaveNavMesh( string path ) 259 | { 260 | NavResCode code = NavMeshGen.sInstance.SaveNavMeshToFile(path , this.m_lstTriangle); 261 | if( code != NavResCode.Success ) 262 | { 263 | Debug.LogError( "save navmesh error: " + code.ToString()); 264 | } 265 | } 266 | 267 | /// 268 | /// Loads the nav mesh. 269 | /// 270 | /// Path. 271 | public void LoadNavMesh( string path ) 272 | { 273 | List lst; 274 | NavResCode code = NavMeshGen.sInstance.LoadNavMeshFromFile(path , out lst); 275 | this.m_lstTriangle = lst; 276 | 277 | if(code != NavResCode.Success) 278 | { 279 | Debug.LogError("load navmesh error: " + code.ToString()); 280 | } 281 | } 282 | 283 | //=============================== seeker test ================================= 284 | /// 285 | /// Draws the find path. 286 | /// 287 | public void DrawFindPath() 288 | { 289 | for( int i = 1 ; i < this.m_lstFindPath.Count ; i++) 290 | { 291 | Gizmos.color = Color.blue; 292 | Vector3 spos = new Vector3(this.m_lstFindPath[i].x , 0 , this.m_lstFindPath[i].y); 293 | Vector3 epos = new Vector3(this.m_lstFindPath[i-1].x , 0 , this.m_lstFindPath[i-1].y); 294 | Gizmos.DrawLine(spos , epos); 295 | } 296 | } 297 | 298 | /// 299 | /// Seek the specified sPos and ePos. 300 | /// 301 | /// S position. 302 | /// E position. 303 | public void Seek( Vector3 sPos , Vector3 ePos ) 304 | { 305 | // 306 | List lst = new List(); 307 | foreach( Triangle item in this.m_lstTriangle ) 308 | { 309 | NavTriangle navTri = item.CloneNavTriangle(); 310 | lst.Add(navTri); 311 | //Debug.Log( "src " + item.GetGroupID() + " :" + item.GetNeighbor(0)+"--" + item.GetNeighbor(1) + "--" + item.GetNeighbor(2) ); 312 | //Debug.Log( "tar " + navTri.GetGroupID() + " :" + navTri.GetNeighbor(0)+"--" + navTri.GetNeighbor(1) + "--" + navTri.GetNeighbor(2) ); 313 | } 314 | Seeker.GetInstance().NavMeshData = lst; 315 | List lstpath; 316 | Vector2 ssPos = new Vector2(sPos.x , sPos.z); 317 | Vector2 eePos = new Vector2(ePos.x , ePos.z); 318 | Seeker.GetInstance().Seek(ssPos ,eePos ,out lstpath , 40); 319 | //Debug.Log(lstpath.Count + " lstpath"); 320 | this.m_lstFindPath = lstpath; 321 | } 322 | } 323 | 324 | } -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/NavMonoEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3cd0266cbe221422db4d7e095c033513 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/NavNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | 6 | 7 | 8 | namespace Game.NavMesh 9 | { 10 | public class NavNode 11 | { 12 | public Vector2 vertex; //顶点 13 | public bool passed; //是否被访问过 14 | public bool isMain; //是否主多边形顶点 15 | public bool o; //是否输出点 16 | public bool isIns; //是否交点 17 | public NavNode other; //交点用,另个多边形上的节点 18 | public NavNode next; //后面一个点 19 | 20 | public NavNode(Vector2 point, bool isin, bool bMain) 21 | { 22 | vertex = point; 23 | isIns = isin; 24 | isMain = bMain; 25 | passed = false; 26 | o = false; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/NavNode.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2ad203620231e4b1eb2af329d95c9f39 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/NavTriangle.cs: -------------------------------------------------------------------------------- 1 |  2 | 3 | using UnityEngine; 4 | using System; 5 | 6 | // NavTriangle.cs 7 | // Author: Lu Zexi 8 | // 2013-10-04 9 | 10 | 11 | namespace Game.NavMesh 12 | { 13 | 14 | /// 15 | /// Nav三角形类 16 | /// 17 | public class NavTriangle : Triangle 18 | { 19 | // 寻路相关参数 20 | private int m_iSessionID; // 21 | private int m_iParentID; //父节点ID 22 | private bool m_bIsOpen; //是否打开 23 | 24 | 25 | //评估相关 26 | private double m_dHValue; //H评估值 27 | private double m_dGValue; //G评估值 28 | private int m_iInWallIndex; //穿入边索引 29 | private int m_iOutWallIndex; //穿出边索引 30 | 31 | public NavTriangle() 32 | :base() 33 | { 34 | Reset(); 35 | } 36 | 37 | /// 38 | /// 重置 39 | /// 40 | public void Reset() 41 | { 42 | this.m_iSessionID = -1; 43 | this.m_iParentID = -1; 44 | this.m_bIsOpen = false; 45 | this.m_iOutWallIndex = -1; 46 | this.m_dHValue = 0; 47 | this.m_dGValue = 0; 48 | this.m_iInWallIndex = -1; 49 | } 50 | 51 | /// 52 | /// 设置当前三角形的穿入边 53 | /// 54 | /// 55 | public void SetArrivalWall(int neighborID) 56 | { 57 | if (neighborID == -1) 58 | return; 59 | 60 | this.m_iInWallIndex = GetWallIndex(neighborID); 61 | } 62 | 63 | /// 64 | /// 获得通过当前三角形的花费 65 | /// 66 | /// 67 | /// 68 | public double GetCost(int neighborID) 69 | { 70 | int outWallIndex = GetWallIndex(neighborID); 71 | if (this.m_iInWallIndex == -1) 72 | return 0; 73 | else if (this.m_iInWallIndex != 0) 74 | return this.m_vecWallDistance[1]; 75 | else if (outWallIndex == 1) 76 | return this.m_vecWallDistance[0]; 77 | else 78 | return this.m_vecWallDistance[2]; 79 | } 80 | 81 | /// 82 | /// 计算三角形估价函数(h值) 83 | /// 使用该三角形的中心点(3个顶点的平均值)到路径终点的x和y方向的距离。 84 | /// 85 | /// 终点 86 | public void CalcHeuristic(Vector2 endPos) 87 | { 88 | double xDelta = Math.Abs(this.m_cCenter.x - endPos.x); 89 | double yDelta = Math.Abs(this.m_cCenter.y - endPos.y); 90 | this.m_dHValue = Math.Sqrt(xDelta * xDelta + yDelta * yDelta); 91 | } 92 | 93 | /// 94 | /// 获取SESSIONID 95 | /// 96 | /// 97 | public int GetSessionID() 98 | { 99 | return this.m_iSessionID; 100 | } 101 | 102 | /// 103 | /// 设置SESSIONID 104 | /// 105 | /// 106 | public void SetSessionID(int id) 107 | { 108 | this.m_iSessionID = id; 109 | } 110 | 111 | /// 112 | /// 获取父节点ID 113 | /// 114 | /// 115 | public int GetParentID() 116 | { 117 | return this.m_iParentID; 118 | } 119 | 120 | /// 121 | /// 设置父节点 122 | /// 123 | /// 124 | public void SetParentID( int id ) 125 | { 126 | this.m_iParentID = id; 127 | } 128 | 129 | /// 130 | /// 获取是否打开 131 | /// 132 | /// 133 | public bool GetOpen() 134 | { 135 | return this.m_bIsOpen; 136 | } 137 | 138 | /// 139 | /// 设置打开状态 140 | /// 141 | /// 142 | public void SetOpen(bool val) 143 | { 144 | this.m_bIsOpen = val; 145 | } 146 | 147 | /// 148 | /// 获取H评估值 149 | /// 150 | /// 151 | public double GetHValue() 152 | { 153 | return this.m_dHValue; 154 | } 155 | 156 | /// 157 | /// 获取G评估值 158 | /// 159 | /// 160 | public double GetGValue() 161 | { 162 | return this.m_dGValue; 163 | } 164 | 165 | /// 166 | /// 设置G评估值 167 | /// 168 | /// 169 | public void SetGValue(double val) 170 | { 171 | this.m_dGValue = val; 172 | } 173 | 174 | /// 175 | /// 获取穿入边索引 176 | /// 177 | /// 178 | public int InWallIndex() 179 | { 180 | return this.m_iInWallIndex; 181 | } 182 | 183 | /// 184 | /// 获取穿出边索引 185 | /// 186 | /// 187 | public int GetOutWallIndex() 188 | { 189 | return this.m_iOutWallIndex; 190 | } 191 | 192 | /// 193 | /// 设置穿出边索引 194 | /// 195 | /// 196 | public void SetOutWallIndex(int index) 197 | { 198 | this.m_iOutWallIndex = index; 199 | } 200 | } 201 | 202 | } 203 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/NavTriangle.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ab6722932481e4b63a7ac125771e53e7 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/NavUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | 6 | namespace Game.NavMesh 7 | { 8 | public class NavUtil 9 | { 10 | /// 11 | /// 用于合并传进来的多边形数组,返回合并后的多边形数组, 12 | /// 如果生成了孤岛,则孤岛的tag标志递增 13 | /// 14 | /// 15 | /// 16 | public static PolyResCode UnionAllPolygon(ref List polys) 17 | { 18 | int tag = 1; 19 | 20 | for (int i = 0; i < polys.Count; i++) 21 | polys[i].CW(); 22 | 23 | for (int i = 1; i < polys.Count; i++) 24 | { 25 | Polygon p1 = polys[i]; 26 | for (int j = 1; j < polys.Count; j++) 27 | { 28 | Polygon p2 = polys[j]; 29 | if ( i!=j && !p1.Equals(p2)) 30 | { 31 | List polyResult = new List(); 32 | PolyResCode result = p1.Union(p2, ref polyResult); 33 | 34 | if (result == PolyResCode.Success && polyResult.Count > 0) 35 | { 36 | polys.Remove(p1); 37 | polys.Remove(p2); 38 | 39 | for (int k = 0; k < polyResult.Count; k++) 40 | { 41 | Polygon poly = polyResult[k]; 42 | if (/*polyResult.Count > 1 &&*/ !poly.IsCW()) 43 | poly.SetTag(tag++);//如果逆时针说明这个多边形是孤岛 44 | 45 | polys.Add(poly); 46 | } 47 | i = -1; 48 | break; 49 | } 50 | } 51 | } 52 | } 53 | return PolyResCode.Success; 54 | } 55 | 56 | /// 57 | /// 合并两个节点列表,生成交点,并按顺时针序插入到顶点表中 58 | /// 59 | /// 主多边形顶点表,并返回插入交点后的顶点表 60 | /// 合并多边形顶点表,并返回插入交点后的顶点表 61 | /// 交点个数 62 | /// 63 | public static PolyResCode NavNodeIntersectPoint(List c0, List c1, out int nInsCnt) 64 | { 65 | nInsCnt = 0; 66 | 67 | NavNode startNode0 = c0[0]; 68 | NavNode startNode1 = null; 69 | Line2D line0, line1; 70 | Vector2 insPoint; 71 | bool hasIns = false; 72 | 73 | while (startNode0 != null) 74 | { 75 | // 判断是否到末点了 76 | if (startNode0.next == null) 77 | line0 = new Line2D(startNode0.vertex, c0[0].vertex); 78 | else 79 | line0 = new Line2D(startNode0.vertex, startNode0.next.vertex); 80 | 81 | startNode1 = c1[0]; 82 | hasIns = false; 83 | 84 | while (startNode1 != null) 85 | { 86 | if (startNode1.next == null) 87 | line1 = new Line2D(startNode1.vertex, c1[0].vertex); 88 | else 89 | line1 = new Line2D(startNode1.vertex, startNode1.next.vertex); 90 | 91 | if (line0.Intersection(line1, out insPoint) == LineCrossState.CROSS) 92 | { 93 | int insPotIndex = -1; 94 | //如果交点不在多边形的节点上 95 | if (NavUtil.NavNodeGetNodeIndex(c0, insPoint, out insPotIndex) == PolyResCode.ErrNotInside) 96 | { 97 | nInsCnt++; 98 | NavNode node0 = new NavNode(insPoint, true, true); 99 | NavNode node1 = new NavNode(insPoint, true, false); 100 | 101 | c0.Add(node0); 102 | c1.Add(node1); 103 | 104 | node0.other = node1; 105 | node1.other = node0; 106 | 107 | //插入顶点列表 108 | node0.next = startNode0.next; 109 | startNode0.next = node0; 110 | node1.next = startNode1.next; 111 | startNode1.next = node1; 112 | 113 | if (line0.ClassifyPoint(line1.GetEndPoint()) == PointSide.RIGHT_SIDE) 114 | { 115 | node0.o = true; 116 | node1.o = true; 117 | } 118 | 119 | hasIns = true; 120 | break; 121 | } 122 | } 123 | startNode1 = startNode1.next; 124 | 125 | } 126 | if (!hasIns) 127 | startNode0 = startNode0.next; 128 | 129 | } 130 | 131 | return PolyResCode.Success; 132 | } 133 | 134 | /// 135 | /// 查找point是否在节点列表里面 136 | /// 137 | /// 节点列表 138 | /// 用于查找的节点 139 | /// 返回节点索引 140 | /// if inside,return sucess,else return not inside 141 | public static PolyResCode NavNodeGetNodeIndex(List nodeList, Vector2 point, out int pIndex) 142 | { 143 | pIndex = -1; 144 | for (int i = 0; i < nodeList.Count; i++) 145 | { 146 | NavNode node = nodeList[i]; 147 | if (NMath.Equals(node.vertex, point)) 148 | { 149 | pIndex = i; 150 | return PolyResCode.Success; 151 | } 152 | } 153 | return PolyResCode.ErrNotInside; 154 | } 155 | 156 | /// 157 | /// 合并两个节点列表为一个多边形,结果为顺时针序( 生成的内部孔洞多边形为逆时针序) 158 | /// 159 | /// 160 | /// 161 | /// 162 | /// 163 | public static PolyResCode LinkToPolygon(List mainNode, List subNode, ref List polyRes) 164 | { 165 | polyRes.Clear(); 166 | for (int i = 0; i < mainNode.Count; i++) 167 | { 168 | NavNode currNode = mainNode[i]; 169 | 170 | // 选择一个没有访问过的交点做起始点 171 | if (currNode.isIns && !currNode.passed) 172 | { 173 | List points = new List(); 174 | while (currNode != null) 175 | { 176 | currNode.passed = true; 177 | 178 | //交点转换 179 | if (currNode.isIns) 180 | { 181 | currNode.other.passed = true; 182 | 183 | if (!currNode.o)//该交点为进点(跟踪裁剪多边形边界) 184 | { 185 | if (currNode.isMain)//当前点在主多边形中 186 | currNode = currNode.other;//切换到裁剪多边形中 187 | } 188 | else 189 | { 190 | //该交点为出点(跟踪主多边形边界) 191 | if (!currNode.isMain)//当前点在裁剪多边形中 192 | currNode = currNode.other;//切换到主多边形中 193 | } 194 | } 195 | 196 | points.Add(currNode.vertex); 197 | 198 | if (currNode.next == null) 199 | { 200 | if (currNode.isMain) 201 | currNode = mainNode[0]; 202 | else 203 | currNode = subNode[0]; 204 | } 205 | else 206 | currNode = currNode.next; 207 | 208 | if (currNode.vertex == points[0]) 209 | break; 210 | } 211 | 212 | // 删除重复顶点 213 | Polygon poly = new Polygon(points); 214 | poly.DelRepeatPoint(); 215 | polyRes.Add(poly); 216 | } 217 | } 218 | return PolyResCode.Success; 219 | } 220 | } 221 | } 222 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/NavUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 91d827081ccfb4b4fbe579a80f79ee4d 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/Polygon.cs: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | using UnityEngine; 5 | using System.Collections.Generic; 6 | 7 | 8 | // Polygon.cs 9 | // Author: Lu Zexi 10 | // 2013-10-04 11 | 12 | 13 | 14 | 15 | namespace Game.NavMesh 16 | { 17 | public enum PolyResCode 18 | { 19 | Success = 0, 20 | ErrEmpty = -1, //空多边形 21 | ErrNotCross = -2, //没有相交 22 | ErrCrossNum = -3, // 多边形交点数量错误 23 | ErrNotInside = -4 //不在多边形上 24 | } 25 | 26 | /// 27 | /// 多边形类 28 | /// 29 | public class Polygon 30 | { 31 | private int m_iTag; //标志 32 | private List m_lstPoints; //列表点 33 | 34 | public Polygon() 35 | { 36 | this.m_lstPoints = new List(); 37 | this.m_iTag = 0; 38 | } 39 | 40 | public Polygon(List points) 41 | { 42 | this.m_lstPoints = points; 43 | this.m_iTag = 0; 44 | } 45 | 46 | /// 47 | /// 删除重复顶点 48 | /// 49 | /// 50 | public void DelRepeatPoint() 51 | { 52 | for (int i = 0; i < this.m_lstPoints.Count; i++) 53 | { 54 | for (int j = i + 1; j < this.m_lstPoints.Count; j++) 55 | { 56 | if (NMath.IsEqualZero(this.m_lstPoints[i] - this.m_lstPoints[j])) 57 | { 58 | this.m_lstPoints.Remove(this.m_lstPoints[j]); 59 | j = i; 60 | } 61 | } 62 | } 63 | } 64 | 65 | 66 | /// 67 | /// 顺时针排序 68 | /// 69 | /// 70 | public void CW() 71 | { 72 | if (!IsCW()) 73 | { 74 | this.m_lstPoints.Reverse(); 75 | } 76 | } 77 | 78 | 79 | /// 80 | /// 判断是否是顺时针 81 | /// 82 | /// 83 | public bool IsCW() 84 | { 85 | if (this.m_lstPoints.Count <= 2) 86 | return false; 87 | 88 | //最上(y最小)最左(x最小)点, 肯定是一个凸点 89 | //寻找最上点 90 | Vector2 topPoint = this.m_lstPoints[0]; 91 | int topIndex = 0; 92 | for (int i = 1; i < this.m_lstPoints.Count; i++) 93 | { 94 | Vector2 currPoint = this.m_lstPoints[i]; 95 | if ((topPoint.y > currPoint.y) 96 | || ((topPoint.y == currPoint.y) && (topPoint.x > currPoint.x))) 97 | { 98 | topPoint = currPoint; 99 | topIndex = i; 100 | } 101 | } 102 | 103 | //寻找左右邻居 104 | int preIndex = (topIndex - 1) >= 0 ? (topIndex - 1) : (this.m_lstPoints.Count - 1); 105 | int nextIndex = (topIndex + 1) < this.m_lstPoints.Count ? (topIndex + 1) : 0; 106 | 107 | Vector2 prePoint = this.m_lstPoints[preIndex]; 108 | Vector2 nextPoint = this.m_lstPoints[nextIndex]; 109 | 110 | //三点共线情况不存在,若三点共线则说明必有一点的y(斜线)或x(水平线)小于topPt 111 | float r = NMath.CrossProduct((prePoint - topPoint), (nextPoint - topPoint)); 112 | if (r > 0) 113 | return true; 114 | 115 | return false; 116 | } 117 | 118 | // ========================================== 合并 ============================================= // 119 | 120 | /// 121 | /// 合并两个交叉的多边形(多边形必须先转换为顺时针方向,调用CW()函数!) 122 | /// 123 | /// 124 | /// 125 | /// 126 | public PolyResCode Union(Polygon other, ref List polyRes) 127 | { 128 | if (this.m_lstPoints.Count == 0 || other.m_lstPoints.Count == 0) 129 | return PolyResCode.ErrEmpty; 130 | else if (!NMath.CheckCross(GetCoverRect(), other.GetCoverRect())) 131 | return PolyResCode.ErrNotCross; 132 | 133 | // 转换为顺时针方向 134 | //this.CW(); 135 | //other.CW(); 136 | 137 | List mainNode = new List(); //主多边形顶点 138 | List subNode = new List(); //需要合并的多边形顶点 139 | 140 | // init main nodes 141 | for (int i = 0; i < this.m_lstPoints.Count; i++) 142 | { 143 | NavNode currNode = new NavNode(this.m_lstPoints[i], false, true); 144 | if (i > 0) 145 | { 146 | NavNode preNode = mainNode[i - 1]; 147 | preNode.next = currNode; 148 | } 149 | mainNode.Add(currNode); 150 | } 151 | 152 | // init sub nodes 153 | for (int j = 0; j < other.m_lstPoints.Count; j++) 154 | { 155 | NavNode currNode = new NavNode(other.m_lstPoints[j], false, false); 156 | if (j > 0) 157 | { 158 | NavNode preNode = subNode[j - 1]; 159 | preNode.next = currNode; 160 | } 161 | subNode.Add(currNode); 162 | } 163 | 164 | int insCnt = 0; 165 | PolyResCode result = NavUtil.NavNodeIntersectPoint(mainNode, subNode, out insCnt); 166 | if (result == PolyResCode.Success && insCnt > 0) 167 | { 168 | if (insCnt % 2 != 0) 169 | { 170 | return PolyResCode.ErrCrossNum; 171 | } 172 | else 173 | { 174 | PolyResCode linkRes = NavUtil.LinkToPolygon(mainNode, subNode, ref polyRes); 175 | return linkRes; 176 | } 177 | } 178 | 179 | return PolyResCode.ErrCrossNum; 180 | } 181 | 182 | // ======================================== 合并结束 ============================================ // 183 | 184 | 185 | 186 | 187 | /// 188 | /// 返回多边形包围盒 189 | /// 190 | /// 191 | public Rect GetCoverRect() 192 | { 193 | Rect rect = new Rect(0, 0, 0, 0); 194 | 195 | for (int i = 0; i < this.m_lstPoints.Count; i++) 196 | { 197 | if (rect.xMin > this.m_lstPoints[i].x) 198 | rect.xMin = this.m_lstPoints[i].x; 199 | if (rect.xMax < this.m_lstPoints[i].x) 200 | rect.xMax = this.m_lstPoints[i].x; 201 | if (rect.yMin > this.m_lstPoints[i].y) 202 | rect.yMin = this.m_lstPoints[i].y; 203 | if (rect.yMax < this.m_lstPoints[i].y) 204 | rect.yMax = this.m_lstPoints[i].y; 205 | } 206 | return rect; 207 | } 208 | 209 | 210 | /// 211 | /// 获取标识 212 | /// 213 | /// 214 | public int GetTag() 215 | { 216 | return this.m_iTag; 217 | } 218 | 219 | /// 220 | /// 设置标签 221 | /// 222 | /// 223 | public void SetTag( int tag ) 224 | { 225 | this.m_iTag = tag; 226 | } 227 | 228 | /// 229 | /// 获取点集 230 | /// 231 | /// 232 | public List GetPoints() 233 | { 234 | return new List(this.m_lstPoints); 235 | } 236 | 237 | /// 238 | /// 增加点位置 239 | /// 240 | /// 241 | public void AddPoints(Vector2 pos) 242 | { 243 | this.m_lstPoints.Add(pos); 244 | } 245 | 246 | } 247 | 248 | } 249 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/Polygon.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1684dad0daf904e53b22c786e405379d 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/Seeker.cs: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | using UnityEngine; 5 | using System; 6 | using System.Collections.Generic; 7 | 8 | // Seeker.cs 9 | // Author: Lu Zexi 10 | // 2013-10-05 11 | 12 | 13 | 14 | namespace Game.NavMesh 15 | { 16 | 17 | public enum PathResCode 18 | { 19 | Success = 0, //寻路成功 20 | Failed = -1, //寻路失败 21 | NoMeshData = -2, //没有数据 22 | NoStartTriOrEndTri = -3, //没有起始点或终点 23 | NavIDNotMatch = -4, //导航网格的索引和id不匹配 24 | NotFoundPath = -5, //找不到路径 25 | CanNotGetNextWayPoint = -6,//找不到下一个拐点信息 26 | GroupNotMatch, //起点和中点在不同的孤岛之间,无法到达 27 | NoCrossPoint, 28 | FixPointFailed, //修复点失败 29 | } 30 | 31 | /// 32 | /// 寻路者 33 | /// 34 | public class Seeker 35 | { 36 | private const int START_POS_EXTEND_LENGTH = 10; //起始位置容错长度 37 | private const int END_POS_EXTEND_LENGTH = 2; //终点位置容错长度 38 | 39 | private List m_lstTriangle; //地图数据 40 | public List NavMeshData 41 | { 42 | set{ this.m_lstTriangle = value;} 43 | } 44 | 45 | private static Seeker s_cInstance; //静态实例 46 | 47 | public Seeker() 48 | { 49 | this.m_lstTriangle = new List(); 50 | } 51 | 52 | /// 53 | /// 获取静态实例 54 | /// 55 | /// 56 | public static Seeker GetInstance() 57 | { 58 | if (s_cInstance == null) 59 | s_cInstance = new Seeker(); 60 | return s_cInstance; 61 | } 62 | 63 | /// 64 | /// 寻路 65 | /// 66 | /// 起始位置 67 | /// 终点位置 68 | /// 输出路径点 69 | /// 移动物体大小 70 | /// 寻路结果 71 | public PathResCode Seek(Vector2 startPos, Vector2 endPos, out List path, int offset) 72 | { 73 | path = new List(); 74 | 75 | if (this.m_lstTriangle == null || this.m_lstTriangle.Count <= 0) 76 | return PathResCode.NoMeshData; 77 | 78 | ResetData(); 79 | 80 | 81 | List pathTri; 82 | PathResCode res = SeekTrianglePath(ref startPos, ref endPos, out pathTri, offset); 83 | if (res != PathResCode.Success) 84 | return res; 85 | 86 | //NavMonoEditor.m_lstTriPath = pathTri; 87 | res = CreateWayPoints(startPos, endPos, pathTri, out path, offset); 88 | if (res != PathResCode.Success) 89 | return res; 90 | 91 | return res; 92 | } 93 | 94 | /// 95 | /// 寻路路径三角形 96 | /// 97 | /// 起始点 98 | /// 终点 99 | /// 输出三角形 100 | /// 移动物品大小 101 | /// 结果 102 | private PathResCode SeekTrianglePath(ref Vector2 startPos, ref Vector2 endPos, out List pathList, int offset) 103 | { 104 | pathList = new List(); 105 | NavTriangle startTri = null, endTri = null; 106 | 107 | //获得起始与终点三角形 108 | foreach (NavTriangle navTri in this.m_lstTriangle) 109 | { 110 | if (startTri == null) 111 | if (navTri.IsPointIn(startPos)) 112 | startTri = navTri; 113 | 114 | if (endTri == null) 115 | if (navTri.IsPointIn(endPos)) 116 | endTri = navTri; 117 | 118 | if (startTri != null && endTri != null) 119 | break; 120 | } 121 | 122 | //检查和修复位置 123 | PathResCode posErr = CheckAndFixPos(ref startTri, ref startPos, ref endTri, ref endPos); 124 | if (posErr != PathResCode.Success) 125 | return posErr; 126 | 127 | //////////////////////////////////// A*算法 /////////////////////////////////////// 128 | 129 | int pathSessionId = 1; 130 | bool foundPath = false; 131 | List openList = new List(); //开放列表 132 | List closeList = new List(); 133 | 134 | startTri.SetSessionID(pathSessionId); 135 | 136 | openList.Add(startTri); 137 | while (openList.Count > 0) 138 | { 139 | // 1. 把当前节点从开放列表删除, 加入到封闭列表 140 | NavTriangle currNode; 141 | currNode = openList[openList.Count - 1]; 142 | openList.Remove(currNode); 143 | closeList.Add(currNode); 144 | 145 | //已经找到目的地 146 | if (currNode.GetID() == endTri.GetID()) 147 | { 148 | foundPath = true; 149 | break; 150 | } 151 | 152 | // 2. 对当前节点相邻的每一个节点依次执行以下步骤: 153 | // 遍历所有邻接三角型 154 | for (int i = 0; i < 3; i++) 155 | { 156 | int neighborID = currNode.GetNeighbor(i); 157 | NavTriangle neighborTri; 158 | 159 | // 3. 如果该相邻节点不可通行,则什么操作也不执行,继续检验下一个节点; 160 | if (neighborID < 0) 161 | { 162 | //没有该邻居节点 163 | continue; 164 | } 165 | else 166 | { 167 | neighborTri = this.m_lstTriangle[neighborID]; 168 | 169 | if (neighborTri == null || neighborTri.GetID() != neighborID) 170 | return PathResCode.NavIDNotMatch; 171 | } 172 | if (neighborTri.GetGroupID() == startTri.GetGroupID() ) 173 | { 174 | if (neighborTri.GetSessionID() != pathSessionId) 175 | { 176 | //judge the side is wide enough to to pass in offset 177 | int sideIndex = neighborTri.GetNeighborWall(currNode); 178 | if( sideIndex != -1 && neighborTri.GetSide(sideIndex).GetLength() >= offset ) 179 | { 180 | // 4. 如果该相邻节点不在开放列表中,则将该节点添加到开放列表中, 181 | // 并将该相邻节点的父节点设为当前节点,同时保存该相邻节点的G和F值; 182 | neighborTri.SetSessionID(pathSessionId); 183 | neighborTri.SetParentID(currNode.GetID()); 184 | neighborTri.SetOpen(true); 185 | 186 | // 计算启发值h 187 | neighborTri.CalcHeuristic(endPos); 188 | // 计算三角形花费g 189 | neighborTri.SetGValue(currNode.GetGValue() + currNode.GetCost(neighborTri.GetID()) ); 190 | 191 | //放入开放列表并排序 192 | openList.Add(neighborTri); 193 | openList.Sort(CompareTriWithGValue); 194 | 195 | //保存穿入边 196 | neighborTri.SetArrivalWall(currNode.GetID()); 197 | } 198 | } 199 | else 200 | { 201 | // 5. 如果该相邻节点在开放列表中, 202 | // 则判断若经由当前节点到达该相邻节点的G值是否小于原来保存的G值, 203 | // 若小于,则将该相邻节点的父节点设为当前节点,并重新设置该相邻节点的G和F值 204 | if (neighborTri.GetOpen()) 205 | { 206 | if (neighborTri.GetGValue() + neighborTri.GetCost(currNode.GetID()) < currNode.GetGValue()) 207 | { 208 | currNode.SetGValue(neighborTri.GetGValue() + neighborTri.GetCost(currNode.GetID())); 209 | currNode.SetParentID(neighborTri.GetID()); 210 | currNode.SetArrivalWall(neighborTri.GetID()); 211 | } 212 | } 213 | else 214 | { 215 | neighborTri = null; 216 | continue; 217 | } 218 | 219 | } 220 | } 221 | } 222 | } 223 | 224 | if (closeList.Count != 0) 225 | { 226 | NavTriangle path = closeList[closeList.Count - 1]; 227 | pathList.Add(path); 228 | while (path.GetParentID() != -1) 229 | { 230 | pathList.Add(this.m_lstTriangle[path.GetParentID()]); 231 | path = this.m_lstTriangle[path.GetParentID()]; 232 | } 233 | } 234 | 235 | if (!foundPath) 236 | return PathResCode.NotFoundPath; 237 | else 238 | return PathResCode.Success; 239 | } 240 | 241 | /// 242 | /// 根据f和h实现排序,A*算法 243 | /// 244 | /// 245 | /// 246 | /// 247 | private int CompareTriWithGValue(NavTriangle x, NavTriangle y) 248 | { 249 | double xFvalue = x.GetHValue() /*+ x.GValue*/; 250 | double yFvalue = y.GetHValue() /*+ y.GValue*/; 251 | 252 | if (xFvalue == yFvalue) 253 | return 0; 254 | else if (xFvalue < yFvalue) 255 | return 1; 256 | else 257 | return -1; 258 | } 259 | 260 | /// 261 | /// 检查和修复所有错误路径点 262 | /// 263 | /// 264 | /// 265 | /// 266 | /// 267 | /// 268 | private PathResCode CheckAndFixPos(ref NavTriangle startTri, ref Vector2 startPos, ref NavTriangle endTri, ref Vector2 endPos) 269 | { 270 | if ( startTri != null && endTri != null && startTri.GetGroupID() != endTri.GetGroupID()) 271 | return PathResCode.GroupNotMatch; 272 | 273 | if (endTri == null) 274 | { 275 | if (FixPos(ref endTri, ref endPos, startTri, startPos, END_POS_EXTEND_LENGTH) != PathResCode.Success) 276 | { 277 | return PathResCode.Failed; 278 | } 279 | } 280 | 281 | if (startTri == null) 282 | { 283 | PathResCode fixRet = FixPos(ref startTri, ref startPos, endTri, endPos, START_POS_EXTEND_LENGTH); 284 | } 285 | 286 | if (startTri == null || endTri == null) 287 | return PathResCode.Failed; 288 | 289 | if (startTri.GetGroupID() != endTri.GetGroupID()) 290 | return PathResCode.GroupNotMatch; 291 | 292 | return PathResCode.Success; 293 | } 294 | 295 | /// 296 | /// 根据原始点计算出正确的落在导航区内的位置,修复无效点和三角形 297 | /// 298 | /// 起源三角形 299 | /// 起源点 300 | /// 参考方向三角形 301 | /// 参考方向点 302 | /// 结果 303 | private PathResCode FixPos(ref NavTriangle orgTarTri, ref Vector2 orgTarPos, NavTriangle otherTri, Vector2 otherPos, int extendLength) 304 | { 305 | Vector2 tarPos = orgTarPos; 306 | ////////////////////////////////////////////////////////////////////////// 307 | //为了精确判断,需要逆向延长线段一定长度 308 | if (extendLength > 0) 309 | { 310 | Vector2 newTarPos = NMath.ExtendPos(otherPos, tarPos, extendLength); 311 | tarPos = newTarPos; 312 | } 313 | ////////////////////////////////////////////////////////////////////////// 314 | 315 | Line2D linePath = new Line2D(tarPos, otherPos); //参考线段 316 | Rect lineRect = NMath.LineRect(linePath); //获取线段矩形包围盒 317 | 318 | //1)找到所有与参考线段矩形相交的三角形,并判断是否groupID相等 319 | List crossNavTris = new List(); 320 | foreach (NavTriangle tri in this.m_lstTriangle) 321 | { 322 | if (NMath.CheckCross(lineRect, tri.GetBoxCollider())) 323 | { 324 | if (otherTri != null && otherTri.GetGroupID() != tri.GetGroupID()) 325 | continue; 326 | crossNavTris.Add(tri); 327 | } 328 | } 329 | 330 | //2)找出所有与参考线段相交的三角形,并记录相交点 331 | List crossPoints = new List(); //相交点列表 332 | List triIndex = new List(); //相交三角形索引列表 333 | for (int index = 0; index < crossNavTris.Count; index++) 334 | { 335 | NavTriangle crossTri = crossNavTris[index]; 336 | Line2D triLine; 337 | for (int i = 0; i < 3; i++) 338 | { 339 | Vector2 insPoint; 340 | triLine = new Line2D(crossTri.GetPoint(i), crossTri.GetPoint((i + 1)%3)); 341 | if (linePath.Intersection(triLine, out insPoint) == LineCrossState.CROSS) 342 | { 343 | crossPoints.Add(insPoint); 344 | triIndex.Add(index); 345 | } 346 | } 347 | } 348 | 349 | if (crossPoints.Count == 0) 350 | return PathResCode.NoCrossPoint; 351 | 352 | 353 | //3)找到最接近起源点的点 354 | Vector2 lastPos = crossPoints[0]; 355 | int lastTriIndex = triIndex[0]; 356 | double lastLength = Math.Pow(lastPos.x - orgTarPos.x, 2.0) + Math.Pow(lastPos.y - orgTarPos.y, 2.0); 357 | for (int i = 1; i < crossPoints.Count; i++) 358 | { 359 | double newLength = Math.Pow(crossPoints[i].x - orgTarPos.x, 2.0) + Math.Pow(crossPoints[i].y - orgTarPos.y, 2.0); 360 | if (newLength < lastLength) 361 | { 362 | lastPos = crossPoints[i]; 363 | lastTriIndex = triIndex[i]; 364 | lastLength = newLength; 365 | } 366 | } 367 | 368 | //4)保存目标 369 | orgTarPos = lastPos; 370 | orgTarTri = crossNavTris[lastTriIndex]; 371 | 372 | return PathResCode.Success; 373 | } 374 | 375 | 376 | /// 377 | /// 生成最终的路径点 378 | /// 379 | /// 起始点 380 | /// 终点 381 | /// 三角形路径列表 382 | /// 路径点 383 | /// 移动物体宽度 384 | /// 385 | private PathResCode CreateWayPoints(Vector2 startPos, Vector2 endPos 386 | , List triPathList, out List wayPoints, int offSet) 387 | { 388 | wayPoints = new List(); 389 | if (triPathList.Count == 0 || startPos == null || endPos == null) 390 | return PathResCode.Failed; 391 | 392 | // 保证从起点到终点的顺序 393 | triPathList.Reverse(); 394 | 395 | // 保存出边编号 396 | for (int i = 0; i < triPathList.Count; i++) 397 | { 398 | NavTriangle tri = triPathList[i]; 399 | if (i != triPathList.Count - 1) 400 | { 401 | NavTriangle nextTri = triPathList[i + 1]; 402 | tri.SetOutWallIndex(tri.GetWallIndex(nextTri.GetID())); 403 | } 404 | } 405 | 406 | wayPoints.Add(startPos); 407 | 408 | //起点与终点在同一三角形中 409 | if (triPathList.Count == 1) 410 | { 411 | wayPoints.Add(endPos); 412 | return PathResCode.Success; 413 | } 414 | 415 | WayPoint way = new WayPoint(startPos, triPathList[0]); 416 | while (!NMath.IsEqualZero(way.GetPoint() - endPos)) 417 | { 418 | way = GetFurthestWayPoint(way, triPathList, endPos, offSet); 419 | if (way == null) 420 | return PathResCode.CanNotGetNextWayPoint; 421 | wayPoints.Add(way.GetPoint()); 422 | } 423 | 424 | return PathResCode.Success; 425 | } 426 | 427 | /// 428 | /// 根据拐点计算法获得导航网格的下一个拐点 429 | /// 430 | /// 431 | /// 432 | /// 433 | /// 434 | /// 435 | private WayPoint GetFurthestWayPoint(WayPoint way, List triPathList, Vector2 endPos, int offSet) 436 | { 437 | WayPoint nextWay = null; 438 | Vector2 currPnt = way.GetPoint(); 439 | NavTriangle currTri = way.GetTriangle(); 440 | NavTriangle lastTriA = currTri; 441 | NavTriangle lastTriB = currTri; 442 | int startIndex = triPathList.IndexOf(currTri);//开始路点所在的网格索引 443 | Line2D outSide = currTri.GetSide(currTri.GetOutWallIndex());//路径线在网格中的穿出边? 444 | Vector2 lastPntA = outSide.GetStartPoint(); 445 | Vector2 lastPntB = outSide.GetEndPoint(); 446 | Line2D lastLineA = new Line2D(currPnt, lastPntA); 447 | Line2D lastLineB = new Line2D(currPnt, lastPntB); 448 | Vector2 testPntA, testPntB; 449 | 450 | for (int i = startIndex + 1; i < triPathList.Count; i++) 451 | { 452 | currTri = triPathList[i]; 453 | outSide = currTri.GetSide(currTri.GetOutWallIndex()); 454 | if (i == triPathList.Count - 1) 455 | { 456 | testPntA = endPos; 457 | testPntB = endPos; 458 | } 459 | else 460 | { 461 | testPntA = outSide.GetStartPoint(); 462 | testPntB = outSide.GetEndPoint(); 463 | } 464 | 465 | if (lastPntA != testPntA) 466 | { 467 | if (lastLineB.ClassifyPoint(testPntA) == PointSide.RIGHT_SIDE) 468 | { 469 | nextWay = new WayPoint(lastPntB, lastTriB); 470 | return nextWay; 471 | } 472 | else if (lastLineA.ClassifyPoint(testPntA) != PointSide.LEFT_SIDE) 473 | { 474 | lastPntA = testPntA; 475 | lastTriA = currTri; 476 | //重设直线 477 | lastLineA = new Line2D(lastLineA.GetStartPoint(), lastPntA); 478 | } 479 | } 480 | 481 | if (lastPntB != testPntB) 482 | { 483 | if (lastLineA.ClassifyPoint(testPntB) == PointSide.LEFT_SIDE) 484 | { 485 | nextWay = new WayPoint(lastPntA, lastTriA); 486 | return nextWay; 487 | } 488 | else if (lastLineB.ClassifyPoint(testPntB) != PointSide.RIGHT_SIDE) 489 | { 490 | lastPntB = testPntB; 491 | lastTriB = currTri; 492 | //重设直线 493 | lastLineB = new Line2D(lastLineB.GetStartPoint(), lastPntB); 494 | } 495 | } 496 | } 497 | 498 | //到达终点 499 | nextWay = new WayPoint(endPos, triPathList[triPathList.Count - 1]); 500 | 501 | return nextWay; 502 | } 503 | 504 | /// 505 | /// 重置寻路数据 506 | /// 507 | private void ResetData() 508 | { 509 | foreach (NavTriangle item in this.m_lstTriangle) 510 | { 511 | item.Reset(); 512 | } 513 | } 514 | 515 | 516 | } 517 | 518 | } 519 | 520 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/Seeker.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2b409f535139e43b3b4983d323336cf3 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/Triangle.cs: -------------------------------------------------------------------------------- 1 |  2 | 3 | using UnityEngine; 4 | using System; 5 | using System.IO; 6 | 7 | 8 | // Triangle.cs 9 | // Author: Lu Zexi 10 | // 2013-10-04 11 | 12 | 13 | namespace Game.NavMesh 14 | { 15 | 16 | /// 17 | /// 三角形类 18 | /// 19 | public class Triangle 20 | { 21 | //基础数据 22 | protected Vector2[] m_vecPoints; //三角形定点列表 23 | protected int m_iID; //三角形ID 24 | protected int m_iGroupID; //三角形组ID 25 | protected int[] m_vecNeighbors; //三角形邻居节点ID 26 | 27 | //计算数据 28 | protected Vector2 m_cCenter; //三角形中心点 29 | protected Rect m_cBoxCollider; //三角形包围盒 30 | protected double[] m_vecWallDistance; //三角形相邻两边的中点距离 31 | 32 | public Triangle() 33 | { 34 | this.m_vecPoints = new Vector2[3]; 35 | this.m_vecWallDistance = new double[3]; 36 | this.m_vecNeighbors = new int[] { -1, -1, -1 }; 37 | this.m_cCenter = Vector2.zero; 38 | } 39 | 40 | public Triangle( Vector2 pos1 , Vector2 pos2 , Vector2 pos3 , int id , int groupid ) 41 | { 42 | this.m_vecPoints = new Vector2[3]; 43 | this.m_vecWallDistance = new double[3]; 44 | this.m_vecNeighbors = new int[]{-1,-1,-1}; 45 | 46 | this.m_iID = id; 47 | this.m_iGroupID = groupid; 48 | 49 | this.m_vecPoints[0] = pos1; 50 | this.m_vecPoints[1] = pos2; 51 | this.m_vecPoints[2] = pos3; 52 | 53 | 54 | //计算中心点 55 | Vector2 temp = new Vector2(); 56 | temp.x = (this.m_vecPoints[0].x + this.m_vecPoints[1].x + this.m_vecPoints[2].x) / 3; 57 | temp.y = (this.m_vecPoints[0].y + this.m_vecPoints[1].y + this.m_vecPoints[2].y) / 3; 58 | this.m_cCenter = temp; 59 | 60 | //计算三角形相邻两边的中点距离 61 | Vector2[] wallMidPoint = new Vector2[3]; 62 | wallMidPoint[0] = new Vector2((this.m_vecPoints[0].x + this.m_vecPoints[1].x) / 2, (this.m_vecPoints[0].y + this.m_vecPoints[1].y) / 2); 63 | wallMidPoint[1] = new Vector2((this.m_vecPoints[1].x + this.m_vecPoints[2].x) / 2, (this.m_vecPoints[1].y + this.m_vecPoints[2].y) / 2); 64 | wallMidPoint[2] = new Vector2((this.m_vecPoints[2].x + this.m_vecPoints[0].x) / 2, (this.m_vecPoints[2].y + this.m_vecPoints[0].y) / 2); 65 | 66 | this.m_vecWallDistance[0] = Math.Sqrt((wallMidPoint[0].x - wallMidPoint[1].x) * (wallMidPoint[0].x - wallMidPoint[1].x) 67 | + (wallMidPoint[0].y - wallMidPoint[1].y) * (wallMidPoint[0].y - wallMidPoint[1].y)); 68 | this.m_vecWallDistance[1] = Math.Sqrt((wallMidPoint[1].x - wallMidPoint[2].x) * (wallMidPoint[1].x - wallMidPoint[2].x) 69 | + (wallMidPoint[1].y - wallMidPoint[2].y) * (wallMidPoint[1].y - wallMidPoint[2].y)); 70 | this.m_vecWallDistance[2] = Math.Sqrt((wallMidPoint[2].x - wallMidPoint[0].x) * (wallMidPoint[2].x - wallMidPoint[0].x) 71 | + (wallMidPoint[2].y - wallMidPoint[0].y) * (wallMidPoint[2].y - wallMidPoint[0].y)); 72 | 73 | 74 | //计算包围盒 75 | CalcCollider(); 76 | } 77 | 78 | public NavTriangle CloneNavTriangle() 79 | { 80 | NavTriangle tri = new NavTriangle(); 81 | //基础数据 82 | Array.Copy(this.m_vecPoints,tri.m_vecPoints,this.m_vecPoints.Length); //三角形定点列表 83 | tri.m_iID = this.m_iID; //三角形ID 84 | tri.m_iGroupID = this.m_iGroupID; //三角形组ID 85 | Array.Copy( this.m_vecNeighbors , tri.m_vecNeighbors , this.m_vecNeighbors.Length); //三角形邻居节点ID 86 | 87 | //计算数据 88 | tri.m_cCenter = this.m_cCenter; //三角形中心点 89 | tri.m_cBoxCollider = this.m_cBoxCollider; //三角形包围盒 90 | //tri.m_vecWallDistance = this.m_vecWallDistance; //三角形相邻两边的中点距离 91 | Array.Copy(this.m_vecWallDistance , tri.m_vecWallDistance , this.m_vecWallDistance.Length); 92 | return tri; 93 | } 94 | 95 | /// 96 | /// 计算包围盒 97 | /// 98 | private void CalcCollider() 99 | { 100 | //计算包围盒 101 | if (this.m_vecPoints[0] == this.m_vecPoints[1] || this.m_vecPoints[1] == this.m_vecPoints[2] || this.m_vecPoints[0] == this.m_vecPoints[2]) 102 | { 103 | DEBUG.ERROR("Triangle:This is not a triangle."); 104 | return; 105 | } 106 | 107 | Rect collider = new Rect(); 108 | collider.xMin = collider.xMax = this.m_vecPoints[0].x; 109 | collider.yMin = collider.yMax = this.m_vecPoints[0].y; 110 | for (int i = 1; i < 3; i++) 111 | { 112 | if (this.m_vecPoints[i].x < collider.xMin) 113 | { 114 | collider.xMin = this.m_vecPoints[i].x; 115 | } 116 | else if (this.m_vecPoints[i].x > collider.xMax) 117 | { 118 | collider.xMax = this.m_vecPoints[i].x; 119 | } 120 | 121 | if (this.m_vecPoints[i].y < collider.yMin) 122 | { 123 | collider.yMin = this.m_vecPoints[i].y; 124 | } 125 | else if (this.m_vecPoints[i].y > collider.yMax) 126 | { 127 | collider.yMax = this.m_vecPoints[i].y; 128 | } 129 | } 130 | 131 | this.m_cBoxCollider = collider; 132 | } 133 | 134 | /// 135 | /// 计算邻居节点 136 | /// 137 | /// 138 | /// 139 | public int isNeighbor(Triangle triNext) 140 | { 141 | for (int i = 0; i < 3; i++) 142 | { 143 | for (int j = 0; j < 3; j++) 144 | { 145 | if (GetSide(i).Equals(triNext.GetSide(j))) 146 | return i; 147 | } 148 | } 149 | return -1; 150 | } 151 | 152 | /// 153 | /// 测试给定点是否在三角形中 154 | /// 点在三角形边上也算 155 | /// 156 | /// 指定点 157 | /// 是否在三角形中 158 | public bool IsPointIn(Vector2 pt) 159 | { 160 | if (this.m_cBoxCollider.xMin != this.m_cBoxCollider.xMax && !this.m_cBoxCollider.Contains(pt)) 161 | return false; 162 | 163 | PointSide resultA = GetSide(0).ClassifyPoint(pt); 164 | PointSide resultB = GetSide(1).ClassifyPoint(pt); 165 | PointSide resultC = GetSide(2).ClassifyPoint(pt); 166 | 167 | if (resultA == PointSide.ON_LINE || resultB == PointSide.ON_LINE || resultC == PointSide.ON_LINE) 168 | { 169 | return true; 170 | } 171 | else if (resultA == PointSide.RIGHT_SIDE && resultB == PointSide.RIGHT_SIDE && resultC == PointSide.RIGHT_SIDE) 172 | { 173 | return true; 174 | } 175 | return false; 176 | } 177 | 178 | /// 179 | /// 根据索引获得相应的边 180 | /// 181 | /// 182 | /// 183 | public Line2D GetSide(int sideIndex) 184 | { 185 | Line2D newSide; 186 | 187 | switch (sideIndex) 188 | { 189 | case 0: 190 | newSide = new Line2D(this.m_vecPoints[0], this.m_vecPoints[1]); 191 | break; 192 | case 1: 193 | newSide = new Line2D(this.m_vecPoints[1], this.m_vecPoints[2]); 194 | break; 195 | case 2: 196 | newSide = new Line2D(this.m_vecPoints[2], this.m_vecPoints[0]); 197 | break; 198 | default: 199 | newSide = new Line2D(this.m_vecPoints[0], this.m_vecPoints[1]); 200 | //DEBUG.ERROR("Triangle:GetSide 获取索引[" + sideIndex + "]错误"); 201 | break; 202 | } 203 | 204 | return newSide; 205 | } 206 | 207 | /// 208 | /// 获得邻居ID边的索引 209 | /// 210 | /// 邻居三角形ID 211 | /// 212 | public int GetWallIndex(int neighborID) 213 | { 214 | for (int i = 0; i < 3; i++) 215 | { 216 | if (this.m_vecNeighbors[i] != -1 && this.m_vecNeighbors[i] == neighborID) 217 | return i; 218 | } 219 | return -1; 220 | } 221 | 222 | /// 223 | /// 比较并获取三角形邻居边索引 224 | /// 225 | /// 三角形 226 | /// 邻边索引 227 | public int GetNeighborWall(Triangle triNext) 228 | { 229 | for (int i = 0; i < 3; i++) 230 | { 231 | for (int j = 0; j < 3; j++) 232 | { 233 | if (GetSide(i).Equals(triNext.GetSide(j))) 234 | return i; 235 | } 236 | } 237 | return -1; 238 | } 239 | 240 | /// 241 | /// 获取三角形ID 242 | /// 243 | /// 244 | public int GetID() 245 | { 246 | return this.m_iID; 247 | } 248 | 249 | /// 250 | /// 获取组ID 251 | /// 252 | /// 253 | public int GetGroupID() 254 | { 255 | return this.m_iGroupID; 256 | } 257 | 258 | /// 259 | /// 获取中心点 260 | /// 261 | /// 262 | public Vector2 GetCenter() 263 | { 264 | return this.m_cCenter; 265 | } 266 | 267 | /// 268 | /// 获取包围盒 269 | /// 270 | /// 271 | public Rect GetBoxCollider() 272 | { 273 | return this.m_cBoxCollider; 274 | } 275 | 276 | /// 277 | /// 获取指定点 278 | /// 279 | /// 280 | /// 281 | public Vector2 GetPoint(int index) 282 | { 283 | if (index >= 3) 284 | { 285 | DEBUG.ERROR("GetPoint:The index is large than 3."); 286 | return Vector2.zero; 287 | } 288 | 289 | return this.m_vecPoints[index]; 290 | } 291 | 292 | /// 293 | /// 获取邻居节点ID 294 | /// 295 | /// 296 | /// 297 | public int GetNeighbor(int index) 298 | { 299 | if (index >= 3) 300 | { 301 | DEBUG.ERROR("GetNeighbor:The index is large than 3."); 302 | return -1; 303 | } 304 | 305 | return this.m_vecNeighbors[index]; 306 | } 307 | 308 | /// 309 | /// 设置邻居三角形ID 310 | /// 311 | /// 312 | /// 313 | public void SetNeighbor(int index, int id) 314 | { 315 | if (index >= 3) 316 | { 317 | DEBUG.ERROR("SetNeighbor:The index is large than 3."); 318 | return; 319 | } 320 | 321 | this.m_vecNeighbors[index] = id; 322 | } 323 | 324 | /// 325 | /// 获取三边中点距离 326 | /// 327 | /// 328 | /// 329 | public double GetWallDis(int index) 330 | { 331 | if (index >= 3) 332 | { 333 | DEBUG.ERROR("GetWallDis:The index is large than 3."); 334 | return -1; 335 | } 336 | 337 | return this.m_vecWallDistance[index]; 338 | } 339 | 340 | /// 341 | /// 读取数据 342 | /// 343 | public virtual void Read( BinaryReader binReader) 344 | { 345 | // 读取id 346 | this.m_iID = binReader.ReadInt32(); 347 | // 读取多边形的顶点 348 | for (int pNum = 0; pNum < 3; pNum++) 349 | { 350 | this.m_vecPoints[pNum].x = binReader.ReadSingle(); 351 | this.m_vecPoints[pNum].y = binReader.ReadSingle(); 352 | } 353 | 354 | // 计算包围盒 355 | CalcCollider(); 356 | 357 | // 读取邻居节点 358 | for (int neighborId = 0; neighborId < 3; neighborId++) 359 | { 360 | this.m_vecNeighbors[neighborId] = binReader.ReadInt32(); 361 | } 362 | // 读取每条边中点距离 363 | for (int wall = 0; wall < 3; wall++) 364 | { 365 | this.m_vecWallDistance[wall] = binReader.ReadDouble(); 366 | } 367 | 368 | // 读取中心点 369 | Vector2 tempCenter = this.m_cCenter; 370 | tempCenter.x = binReader.ReadSingle(); 371 | tempCenter.y = binReader.ReadSingle(); 372 | this.m_cCenter = tempCenter; 373 | 374 | // 读取区域id 375 | this.m_iGroupID = binReader.ReadInt32(); 376 | } 377 | 378 | } 379 | 380 | } 381 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/Triangle.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cacdda3f09d3f4c9fba33a9d32c9ea55 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/WayPoint.cs: -------------------------------------------------------------------------------- 1 |  2 | 3 | using UnityEngine; 4 | 5 | 6 | 7 | namespace Game.NavMesh 8 | { 9 | 10 | /// 11 | /// 路径点 12 | /// 13 | public class WayPoint 14 | { 15 | private Vector2 m_cPoint; //位置点 16 | private NavTriangle m_cTriangle; //所在三角形 17 | 18 | public WayPoint(Vector2 pos, NavTriangle tri) 19 | { 20 | this.m_cPoint = pos; 21 | this.m_cTriangle = tri; 22 | } 23 | 24 | /// 25 | /// 获取路径点 26 | /// 27 | /// 28 | public Vector2 GetPoint() 29 | { 30 | return this.m_cPoint; 31 | } 32 | 33 | /// 34 | /// 获取路径三角形 35 | /// 36 | /// 37 | public NavTriangle GetTriangle() 38 | { 39 | return this.m_cTriangle; 40 | } 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /NavMesh/Assets/Scripts/NavMesh/WayPoint.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 30d14ebf6e7474757879475d3243fbc3 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /NavMesh/Assets/Terrain.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Assets/Terrain.prefab -------------------------------------------------------------------------------- /NavMesh/Assets/Terrain.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cae94ac1d62804a11a3f7881db9e8cb4 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NavMesh/Assets/Test.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Assets/Test.unity -------------------------------------------------------------------------------- /NavMesh/Assets/Test.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 663438ac623fa4b43b3e1c9d7631738e 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NavMesh/Assets/data.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ab9480d4abf85435696be004e46e6884 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /NavMesh/Assets/data/map.navmesh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Assets/data/map.navmesh -------------------------------------------------------------------------------- /NavMesh/Assets/data/map.navmesh.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8a750640b06be4fd48be182eed970b9b 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NavMesh/Assets/data/map.unwalk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Assets/data/map.unwalk -------------------------------------------------------------------------------- /NavMesh/Assets/data/map.unwalk.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5893d4aa496c846ce8f337085ed506e4 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NavMesh/Assets/data/map1.navmesh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Assets/data/map1.navmesh -------------------------------------------------------------------------------- /NavMesh/Assets/data/map1.navmesh.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 512fd4ccbdd4f417dbd23011bda72173 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NavMesh/Assets/data/map1.unwalk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Assets/data/map1.unwalk -------------------------------------------------------------------------------- /NavMesh/Assets/data/map1.unwalk.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ac097c6f3a6434803844dc1a641c4d7b 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NavMesh/Assets/data/map2.navmesh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Assets/data/map2.navmesh -------------------------------------------------------------------------------- /NavMesh/Assets/data/map2.navmesh.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 655accde9495346568817b86f2289ed9 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NavMesh/Assets/data/map2.unwalk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Assets/data/map2.unwalk -------------------------------------------------------------------------------- /NavMesh/Assets/data/map2.unwalk.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 52cc90dfdfc5a46ebb6097ce8ce0f995 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NavMesh/Assets/data/map3.navmesh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Assets/data/map3.navmesh -------------------------------------------------------------------------------- /NavMesh/Assets/data/map3.navmesh.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 27a306fbcdc134268a83acefb2471e7d 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NavMesh/Assets/data/map3.unwalk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Assets/data/map3.unwalk -------------------------------------------------------------------------------- /NavMesh/Assets/data/map3.unwalk.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7c82556b8752449eca5e7560b9403753 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NavMesh/Library/AnnotationManager: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/AnnotationManager -------------------------------------------------------------------------------- /NavMesh/Library/AssetImportState: -------------------------------------------------------------------------------- 1 | 4;0;-1 -------------------------------------------------------------------------------- /NavMesh/Library/AssetServerCacheV3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/AssetServerCacheV3 -------------------------------------------------------------------------------- /NavMesh/Library/AssetVersioning.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/AssetVersioning.db -------------------------------------------------------------------------------- /NavMesh/Library/BuildPlayer.prefs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/BuildPlayer.prefs -------------------------------------------------------------------------------- /NavMesh/Library/BuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/BuildSettings.asset -------------------------------------------------------------------------------- /NavMesh/Library/CurrentLayout.dwlt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/CurrentLayout.dwlt -------------------------------------------------------------------------------- /NavMesh/Library/EditorUserBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/EditorUserBuildSettings.asset -------------------------------------------------------------------------------- /NavMesh/Library/EditorUserSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/EditorUserSettings.asset -------------------------------------------------------------------------------- /NavMesh/Library/FailedAssetImports.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/FailedAssetImports.txt -------------------------------------------------------------------------------- /NavMesh/Library/InspectorExpandedItems.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/InspectorExpandedItems.asset -------------------------------------------------------------------------------- /NavMesh/Library/MonoManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/MonoManager.asset -------------------------------------------------------------------------------- /NavMesh/Library/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/ProjectSettings.asset -------------------------------------------------------------------------------- /NavMesh/Library/ScriptAssemblies/Assembly-CSharp-Editor.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/ScriptAssemblies/Assembly-CSharp-Editor.dll -------------------------------------------------------------------------------- /NavMesh/Library/ScriptAssemblies/Assembly-CSharp-Editor.dll.mdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/ScriptAssemblies/Assembly-CSharp-Editor.dll.mdb -------------------------------------------------------------------------------- /NavMesh/Library/ScriptAssemblies/Assembly-CSharp.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/ScriptAssemblies/Assembly-CSharp.dll -------------------------------------------------------------------------------- /NavMesh/Library/ScriptAssemblies/Assembly-CSharp.dll.mdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/ScriptAssemblies/Assembly-CSharp.dll.mdb -------------------------------------------------------------------------------- /NavMesh/Library/ScriptAssemblies/CompilationCompleted.txt: -------------------------------------------------------------------------------- 1 | Completed 2 | -------------------------------------------------------------------------------- /NavMesh/Library/ScriptMapper: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/ScriptMapper -------------------------------------------------------------------------------- /NavMesh/Library/ShaderCache.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/ShaderCache.db -------------------------------------------------------------------------------- /NavMesh/Library/ShaderCache/4/48682794dd6853836c7e7474aaa659f2.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/ShaderCache/4/48682794dd6853836c7e7474aaa659f2.bin -------------------------------------------------------------------------------- /NavMesh/Library/ShaderCache/4/4f3692287816d020b19ddc922e965711.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/ShaderCache/4/4f3692287816d020b19ddc922e965711.bin -------------------------------------------------------------------------------- /NavMesh/Library/ShaderCache/8/852147239167e337d561a23df0952531.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/ShaderCache/8/852147239167e337d561a23df0952531.bin -------------------------------------------------------------------------------- /NavMesh/Library/ShaderCache/9/9004e6c5f266fb4d0b148f1b9580e527.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/ShaderCache/9/9004e6c5f266fb4d0b148f1b9580e527.bin -------------------------------------------------------------------------------- /NavMesh/Library/assetDatabase3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/assetDatabase3 -------------------------------------------------------------------------------- /NavMesh/Library/expandedItems: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/expandedItems -------------------------------------------------------------------------------- /NavMesh/Library/guidmapper: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/guidmapper -------------------------------------------------------------------------------- /NavMesh/Library/metadata/00/00000000000000001000000000000000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/00/00000000000000001000000000000000 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/00/00000000000000002000000000000000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/00/00000000000000002000000000000000 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/00/00000000000000003000000000000000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/00/00000000000000003000000000000000 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/00/00000000000000004000000000000000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/00/00000000000000004000000000000000 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/00/00000000000000004100000000000000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/00/00000000000000004100000000000000 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/00/00000000000000005000000000000000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/00/00000000000000005000000000000000 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/00/00000000000000005100000000000000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/00/00000000000000005100000000000000 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/00/00000000000000006000000000000000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/00/00000000000000006000000000000000 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/00/00000000000000006100000000000000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/00/00000000000000006100000000000000 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/00/00000000000000007000000000000000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/00/00000000000000007000000000000000 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/00/00000000000000008000000000000000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/00/00000000000000008000000000000000 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/00/00000000000000009000000000000000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/00/00000000000000009000000000000000 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/00/0000000000000000a000000000000000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/00/0000000000000000a000000000000000 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/00/0000000000000000b000000000000000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/00/0000000000000000b000000000000000 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/00/0000000000000000c000000000000000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/00/0000000000000000c000000000000000 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/00/008984c8f730746c482b6d815d59e612: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/00/008984c8f730746c482b6d815d59e612 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/05/05737f79bb9524dc692895de2fc552ee: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/05/05737f79bb9524dc692895de2fc552ee -------------------------------------------------------------------------------- /NavMesh/Library/metadata/09/09a73ede791c04bb69f7d24c93b3412e: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/09/09a73ede791c04bb69f7d24c93b3412e -------------------------------------------------------------------------------- /NavMesh/Library/metadata/15/15cb92e5905c64052a38c79aa0b18ee6: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/15/15cb92e5905c64052a38c79aa0b18ee6 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/16/1684dad0daf904e53b22c786e405379d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/16/1684dad0daf904e53b22c786e405379d -------------------------------------------------------------------------------- /NavMesh/Library/metadata/23/2353ad324112f41e7aacc436578d4230: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/23/2353ad324112f41e7aacc436578d4230 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/27/27a306fbcdc134268a83acefb2471e7d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/27/27a306fbcdc134268a83acefb2471e7d -------------------------------------------------------------------------------- /NavMesh/Library/metadata/2a/2ad203620231e4b1eb2af329d95c9f39: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/2a/2ad203620231e4b1eb2af329d95c9f39 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/2b/2b409f535139e43b3b4983d323336cf3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/2b/2b409f535139e43b3b4983d323336cf3 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/30/30d14ebf6e7474757879475d3243fbc3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/30/30d14ebf6e7474757879475d3243fbc3 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/3c/3cd0266cbe221422db4d7e095c033513: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/3c/3cd0266cbe221422db4d7e095c033513 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/4e/4e55186f51e804e608f6e280e82fdfdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/4e/4e55186f51e804e608f6e280e82fdfdf -------------------------------------------------------------------------------- /NavMesh/Library/metadata/51/512fd4ccbdd4f417dbd23011bda72173: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/51/512fd4ccbdd4f417dbd23011bda72173 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/52/52cc90dfdfc5a46ebb6097ce8ce0f995: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/52/52cc90dfdfc5a46ebb6097ce8ce0f995 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/58/5893d4aa496c846ce8f337085ed506e4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/58/5893d4aa496c846ce8f337085ed506e4 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/65/65182398383394d1d97ec3f4d816081d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/65/65182398383394d1d97ec3f4d816081d -------------------------------------------------------------------------------- /NavMesh/Library/metadata/65/655accde9495346568817b86f2289ed9: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/65/655accde9495346568817b86f2289ed9 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/66/663438ac623fa4b43b3e1c9d7631738e: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/66/663438ac623fa4b43b3e1c9d7631738e -------------------------------------------------------------------------------- /NavMesh/Library/metadata/7a/7a250d6273fbe46268300c56cd6d7a99: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/7a/7a250d6273fbe46268300c56cd6d7a99 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/7c/7c82556b8752449eca5e7560b9403753: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/7c/7c82556b8752449eca5e7560b9403753 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/8a/8a750640b06be4fd48be182eed970b9b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/8a/8a750640b06be4fd48be182eed970b9b -------------------------------------------------------------------------------- /NavMesh/Library/metadata/91/91d827081ccfb4b4fbe579a80f79ee4d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/91/91d827081ccfb4b4fbe579a80f79ee4d -------------------------------------------------------------------------------- /NavMesh/Library/metadata/94/9450ef14c695a44b694409d92fc97bca: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/94/9450ef14c695a44b694409d92fc97bca -------------------------------------------------------------------------------- /NavMesh/Library/metadata/a4/a47f0c4eba7dd40af85b87445eeb1c94: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/a4/a47f0c4eba7dd40af85b87445eeb1c94 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/ab/ab6722932481e4b63a7ac125771e53e7: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/ab/ab6722932481e4b63a7ac125771e53e7 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/ab/ab9480d4abf85435696be004e46e6884: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/ab/ab9480d4abf85435696be004e46e6884 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/ac/ac097c6f3a6434803844dc1a641c4d7b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/ac/ac097c6f3a6434803844dc1a641c4d7b -------------------------------------------------------------------------------- /NavMesh/Library/metadata/bc/bc75ff7cf00364728a0b1369c0be6a2f: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/bc/bc75ff7cf00364728a0b1369c0be6a2f -------------------------------------------------------------------------------- /NavMesh/Library/metadata/bd/bdbf485e36ad348dd9ebb2c7705adb29: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/bd/bdbf485e36ad348dd9ebb2c7705adb29 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/ca/cacdda3f09d3f4c9fba33a9d32c9ea55: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/ca/cacdda3f09d3f4c9fba33a9d32c9ea55 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/ca/cae94ac1d62804a11a3f7881db9e8cb4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/ca/cae94ac1d62804a11a3f7881db9e8cb4 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/d6/d6eb707f8ae0c493d88969fcee802895: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/d6/d6eb707f8ae0c493d88969fcee802895 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/da/dad57801c7fd74dc284b1261ddf59300: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/da/dad57801c7fd74dc284b1261ddf59300 -------------------------------------------------------------------------------- /NavMesh/Library/metadata/ee/eee6f2420f021466e8922035a25fce06: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Library/metadata/ee/eee6f2420f021466e8922035a25fce06 -------------------------------------------------------------------------------- /NavMesh/Library/shadercompiler-1.log: -------------------------------------------------------------------------------- 1 | Base path: /Applications/Unity/Unity.app/Contents 2 | Pipe name: \\.\pipe\UnityShaderCompiler-1--1596288600 3 | Cmd: getPlatforms 4 | Cmd: preprocess 5 | insize=683 outsize=683 ok=1 6 | Cmd: preprocess 7 | insize=838 outsize=838 ok=1 8 | Cmd: preprocess 9 | insize=2390 outsize=838 ok=1 10 | Cmd: compileSnippet 11 | api=0 type=0 insize=1131 outsize=498 kw= ok=1 12 | Cmd: compileSnippet 13 | api=0 type=1 insize=1131 outsize=143 kw= ok=1 14 | Cmd: compileSnippet 15 | api=0 type=0 insize=1028 outsize=490 kw= ok=1 16 | Cmd: compileSnippet 17 | api=0 type=1 insize=1028 outsize=143 kw= ok=1 18 | Cmd: preprocess 19 | insize=763 outsize=763 ok=1 20 | Cmd: preprocess 21 | insize=2445 outsize=2445 ok=1 22 | -------------------------------------------------------------------------------- /NavMesh/NavMesh-csharp.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 11.00 2 | # Visual Studio 2008 3 | 4 | Project("{A77459F6-0FC9-06F0-BB8C-45C3D4A2CF6A}") = "NavMesh", "Assembly-CSharp-vs.csproj", "{5C5A758D-9CAE-C586-67A2-AFA743B37560}" 5 | EndProject 6 | Project("{A77459F6-0FC9-06F0-BB8C-45C3D4A2CF6A}") = "NavMesh", "Assembly-CSharp-Editor-vs.csproj", "{C87A5162-27DA-D4EA-7AC8-6CF152A7091A}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {5C5A758D-9CAE-C586-67A2-AFA743B37560}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {5C5A758D-9CAE-C586-67A2-AFA743B37560}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {5C5A758D-9CAE-C586-67A2-AFA743B37560}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {5C5A758D-9CAE-C586-67A2-AFA743B37560}.Release|Any CPU.Build.0 = Release|Any CPU 18 | {C87A5162-27DA-D4EA-7AC8-6CF152A7091A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {C87A5162-27DA-D4EA-7AC8-6CF152A7091A}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {C87A5162-27DA-D4EA-7AC8-6CF152A7091A}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {C87A5162-27DA-D4EA-7AC8-6CF152A7091A}.Release|Any CPU.Build.0 = Release|Any CPU 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | GlobalSection(MonoDevelopProperties) = preSolution 27 | StartupItem = Assembly-CSharp.csproj 28 | Policies = $0 29 | $0.TextStylePolicy = $1 30 | $1.inheritsSet = null 31 | $1.scope = text/x-csharp 32 | $0.CSharpFormattingPolicy = $2 33 | $2.inheritsSet = Mono 34 | $2.inheritsScope = text/x-csharp 35 | $2.scope = text/x-csharp 36 | $0.TextStylePolicy = $3 37 | $3.FileWidth = 120 38 | $3.TabWidth = 4 39 | $3.EolMarker = Unix 40 | $3.inheritsSet = Mono 41 | $3.inheritsScope = text/plain 42 | $3.scope = text/plain 43 | EndGlobalSection 44 | 45 | EndGlobal 46 | -------------------------------------------------------------------------------- /NavMesh/NavMesh.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 11.00 2 | # Visual Studio 2008 3 | 4 | Project("{A77459F6-0FC9-06F0-BB8C-45C3D4A2CF6A}") = "NavMesh", "Assembly-CSharp.csproj", "{5C5A758D-9CAE-C586-67A2-AFA743B37560}" 5 | EndProject 6 | Project("{A77459F6-0FC9-06F0-BB8C-45C3D4A2CF6A}") = "NavMesh", "Assembly-CSharp-Editor.csproj", "{C87A5162-27DA-D4EA-7AC8-6CF152A7091A}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {5C5A758D-9CAE-C586-67A2-AFA743B37560}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {5C5A758D-9CAE-C586-67A2-AFA743B37560}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {5C5A758D-9CAE-C586-67A2-AFA743B37560}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {5C5A758D-9CAE-C586-67A2-AFA743B37560}.Release|Any CPU.Build.0 = Release|Any CPU 18 | {C87A5162-27DA-D4EA-7AC8-6CF152A7091A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {C87A5162-27DA-D4EA-7AC8-6CF152A7091A}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {C87A5162-27DA-D4EA-7AC8-6CF152A7091A}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {C87A5162-27DA-D4EA-7AC8-6CF152A7091A}.Release|Any CPU.Build.0 = Release|Any CPU 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | GlobalSection(MonoDevelopProperties) = preSolution 27 | StartupItem = Assembly-CSharp.csproj 28 | Policies = $0 29 | $0.TextStylePolicy = $1 30 | $1.inheritsSet = null 31 | $1.scope = text/x-csharp 32 | $0.CSharpFormattingPolicy = $2 33 | $2.inheritsSet = Mono 34 | $2.inheritsScope = text/x-csharp 35 | $2.scope = text/x-csharp 36 | $0.TextStylePolicy = $3 37 | $3.FileWidth = 120 38 | $3.TabWidth = 4 39 | $3.EolMarker = Unix 40 | $3.inheritsSet = Mono 41 | $3.inheritsScope = text/plain 42 | $3.scope = text/plain 43 | EndGlobalSection 44 | 45 | EndGlobal 46 | -------------------------------------------------------------------------------- /NavMesh/NavMesh.userprefs: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | bytes[0] 42 | bytes[1] 43 | m 44 | n 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /NavMesh/ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /NavMesh/ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /NavMesh/ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /NavMesh/ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /NavMesh/ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /NavMesh/ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /NavMesh/ProjectSettings/NavMeshLayers.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/ProjectSettings/NavMeshLayers.asset -------------------------------------------------------------------------------- /NavMesh/ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /NavMesh/ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /NavMesh/ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /NavMesh/ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /NavMesh/ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /NavMesh/ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /NavMesh/Temp/UnityLockfile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luzexi/Unity3DNavMesh/97470c1e517e4e8dab54422af3d64a650b703965/NavMesh/Temp/UnityLockfile -------------------------------------------------------------------------------- /NavMesh/Temp/UnityTempFile-26208dfc0b3d54075b7672f761fa93ca: -------------------------------------------------------------------------------- 1 | -debug 2 | -target:library 3 | -nowarn:0169 4 | -out:'Temp/Assembly-CSharp.dll' 5 | -r:'/Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll' 6 | -r:'/Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEditor.dll' 7 | -define:UNITY_4_5_0 8 | -define:UNITY_4_5 9 | -define:UNITY_STANDALONE_OSX 10 | -define:ENABLE_MICROPHONE 11 | -define:ENABLE_TEXTUREID_MAP 12 | -define:ENABLE_UNITYEVENTS 13 | -define:ENABLE_NEW_HIERARCHY 14 | -define:ENABLE_AUDIO_FMOD 15 | -define:UNITY_STANDALONE 16 | -define:ENABLE_MONO 17 | -define:ENABLE_TERRAIN 18 | -define:ENABLE_SUBSTANCE 19 | -define:ENABLE_GENERICS 20 | -define:INCLUDE_WP8SUPPORT 21 | -define:ENABLE_MOVIES 22 | -define:ENABLE_WWW 23 | -define:ENABLE_IMAGEEFFECTS 24 | -define:ENABLE_WEBCAM 25 | -define:INCLUDE_METROSUPPORT 26 | -define:RENDER_SOFTWARE_CURSOR 27 | -define:ENABLE_NETWORK 28 | -define:ENABLE_PHYSICS 29 | -define:ENABLE_CACHING 30 | -define:ENABLE_CLOTH 31 | -define:ENABLE_2D_PHYSICS 32 | -define:ENABLE_GAMECENTER 33 | -define:ENABLE_SHADOWS 34 | -define:ENABLE_AUDIO 35 | -define:ENABLE_NAVMESH_CARVING 36 | -define:ENABLE_DUCK_TYPING 37 | -define:ENABLE_SINGLE_INSTANCE_BUILD_SETTING 38 | -define:ENABLE_PROFILER 39 | -define:UNITY_EDITOR 40 | -define:UNITY_EDITOR_OSX 41 | -define:UNITY_TEAM_LICENSE 42 | -define:UNITY_PRO_LICENSE 43 | 'Assets/Scripts/NavMesh/Circle.cs' 44 | 'Assets/Scripts/NavMesh/DEBUG.cs' 45 | 'Assets/Scripts/NavMesh/Line2D.cs' 46 | 'Assets/Scripts/NavMesh/NMath.cs' 47 | 'Assets/Scripts/NavMesh/NavEditArea.cs' 48 | 'Assets/Scripts/NavMesh/NavEditAreaGroup.cs' 49 | 'Assets/Scripts/NavMesh/NavEditAreaManager.cs' 50 | 'Assets/Scripts/NavMesh/NavMeshGen.cs' 51 | 'Assets/Scripts/NavMesh/NavMonoEditor.cs' 52 | 'Assets/Scripts/NavMesh/NavNode.cs' 53 | 'Assets/Scripts/NavMesh/NavTriangle.cs' 54 | 'Assets/Scripts/NavMesh/NavUtil.cs' 55 | 'Assets/Scripts/NavMesh/Polygon.cs' 56 | 'Assets/Scripts/NavMesh/Seeker.cs' 57 | 'Assets/Scripts/NavMesh/Triangle.cs' 58 | 'Assets/Scripts/NavMesh/WayPoint.cs' 59 | -r:'/Applications/Unity/Unity.app/Contents/Frameworks/Mono/lib/mono/unity/System.Runtime.Serialization.dll' 60 | -r:'/Applications/Unity/Unity.app/Contents/Frameworks/Mono/lib/mono/unity/System.Xml.Linq.dll' 61 | -------------------------------------------------------------------------------- /NavMesh/Temp/UnityTempFile-d2c3f16fcb2504e9a9feb83b84c044d3: -------------------------------------------------------------------------------- 1 | -debug 2 | -target:library 3 | -nowarn:0169 4 | -out:'Temp/Assembly-CSharp-Editor.dll' 5 | -r:'/Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll' 6 | -r:'/Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEditor.dll' 7 | -r:'Library/ScriptAssemblies/Assembly-CSharp.dll' 8 | -r:'/Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEditor.Graphs.dll' 9 | -define:UNITY_4_5_0 10 | -define:UNITY_4_5 11 | -define:UNITY_STANDALONE_OSX 12 | -define:ENABLE_MICROPHONE 13 | -define:ENABLE_TEXTUREID_MAP 14 | -define:ENABLE_UNITYEVENTS 15 | -define:ENABLE_NEW_HIERARCHY 16 | -define:ENABLE_AUDIO_FMOD 17 | -define:UNITY_STANDALONE 18 | -define:ENABLE_MONO 19 | -define:ENABLE_TERRAIN 20 | -define:ENABLE_SUBSTANCE 21 | -define:ENABLE_GENERICS 22 | -define:INCLUDE_WP8SUPPORT 23 | -define:ENABLE_MOVIES 24 | -define:ENABLE_WWW 25 | -define:ENABLE_IMAGEEFFECTS 26 | -define:ENABLE_WEBCAM 27 | -define:INCLUDE_METROSUPPORT 28 | -define:RENDER_SOFTWARE_CURSOR 29 | -define:ENABLE_NETWORK 30 | -define:ENABLE_PHYSICS 31 | -define:ENABLE_CACHING 32 | -define:ENABLE_CLOTH 33 | -define:ENABLE_2D_PHYSICS 34 | -define:ENABLE_GAMECENTER 35 | -define:ENABLE_SHADOWS 36 | -define:ENABLE_AUDIO 37 | -define:ENABLE_NAVMESH_CARVING 38 | -define:ENABLE_DUCK_TYPING 39 | -define:ENABLE_SINGLE_INSTANCE_BUILD_SETTING 40 | -define:ENABLE_PROFILER 41 | -define:UNITY_EDITOR 42 | -define:UNITY_EDITOR_OSX 43 | -define:UNITY_TEAM_LICENSE 44 | -define:UNITY_PRO_LICENSE 45 | 'Assets/Scripts/NavMesh/Editor/EditorNavMesh.cs' 46 | -r:'/Applications/Unity/Unity.app/Contents/Frameworks/Mono/lib/mono/2.0/System.Runtime.Serialization.dll' 47 | -r:'/Applications/Unity/Unity.app/Contents/Frameworks/Mono/lib/mono/2.0/System.Xml.Linq.dll' 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Unity3DNavMesh 2 | ============== 3 | 4 | 为Unity3d打造的NavMesh
5 | 如下地址为,此项目的博文地址。
6 | http://www.luzexi.com/unity3d%E6%9E%B6%E6%9E%84%E8%AE%BE%E8%AE%A1navmesh%E5%AF%BB%E8%B7%AF/
7 | 本项目专门为Unity3d网络游戏打造使用,现在只有单一平面轴上的网格生成和寻路功能,今后会继续扩展成更强大的功能。
8 | 所有的寻路网格都以文件生成保存,便于在切换场景时读取不同网格数据。
9 | NavMonoEditor是网格编辑器,可以用来对场景地图的网格编辑。
10 | 本API目标是打造更为方便,快捷,操作简单,且使用快速的宗旨。
11 | --------------------------------------------------------------------------------