浏览代码
Pathway component with Idea (#373)
Pathway component with Idea (#373)
* Pathway component with Idea * Pathway component deletion of error messages * Pathway component cleaning Pathway component * pathway interactive * Update PathwayGizmos.cs * cleaning * Pathway component update * Pathway component correction * Phatway update * Update PathWayNavMeshUI.cs * Update PathWayNavMeshUI.cs * Update PathWayNavMeshUI.cs * Rename variables add a tooltip * Rename variables Add hide pathway option * Update PathWayNavMeshUI.cs * rename add HasNavMeshAt * Correction DisplayHandles() incorrect use of EditorGUI.BeginChangeCheck (); * Update PathwayHandles.cs * correction HasNavMeshAt, I forgot the delete case Gismos just a rewrite * less calculus more data * cleaning * Update PathWayNavMeshUI.cs Correction * correction * update update in the path only the points moved by the handles * correction * small fixes/devlogs-4-addressable-assets
GitHub
4 年前
当前提交
47599961
共有 10 个文件被更改,包括 400 次插入 和 43 次删除
-
63UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayEditor.cs
-
2UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayEditor.cs.meta
-
75UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayGizmos.cs
-
2UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayGizmos.cs.meta
-
17UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayHandles.cs
-
40UOP1_Project/Assets/Scripts/Pathway/Pathway.cs
-
105UOP1_Project/Assets/Scripts/Editor/Pathway/PathWayNavMeshUI.cs
-
11UOP1_Project/Assets/Scripts/Editor/Pathway/PathWayNavMeshUI.cs.meta
-
117UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayNavMesh.cs
-
11UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayNavMesh.cs.meta
|
|||
using UnityEngine; |
|||
using UnityEditorInternal; |
|||
|
|||
|
|||
public class PathWayNavMeshUI |
|||
{ |
|||
private Pathway _pathway; |
|||
private PathwayNavMesh _pathwayNavMesh; |
|||
|
|||
public PathWayNavMeshUI(Pathway pathway) |
|||
{ |
|||
_pathway = pathway; |
|||
_pathwayNavMesh = new PathwayNavMesh(pathway); |
|||
RestorePath(); |
|||
} |
|||
|
|||
public void OnInspectorGUI() |
|||
{ |
|||
if (!_pathway.ToggledNavMeshDisplay) |
|||
{ |
|||
if (GUILayout.Button("NavMesh Path")) |
|||
{ |
|||
_pathway.ToggledNavMeshDisplay = true; |
|||
GeneratePath(); |
|||
InternalEditorUtility.RepaintAllViews(); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
if (GUILayout.Button("Handles Path")) |
|||
{ |
|||
_pathway.ToggledNavMeshDisplay = false; |
|||
InternalEditorUtility.RepaintAllViews(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public void UpdatePath() { |
|||
|
|||
if (!_pathway.DisplayProbes) |
|||
{ |
|||
_pathwayNavMesh.UpdatePath(); |
|||
} |
|||
} |
|||
|
|||
public void UpdatePathAt(int index) |
|||
{ |
|||
if (index >= 0) |
|||
{ |
|||
_pathway.DisplayProbes = !_pathwayNavMesh.HasNavMeshAt(index); |
|||
|
|||
if (!_pathway.DisplayProbes && _pathway.ToggledNavMeshDisplay) |
|||
{ |
|||
_pathway.DisplayProbes = !_pathwayNavMesh.UpdateCornersAt(index); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public void RealTime(int index) |
|||
{ |
|||
if (_pathway.RealTimeEnabled) |
|||
{ |
|||
UpdatePathAt(index); |
|||
|
|||
if (_pathway.ToggledNavMeshDisplay) |
|||
{ |
|||
UpdatePath(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private void RestorePath() |
|||
{ |
|||
bool existsPath = true; |
|||
|
|||
_pathway.Hits.Clear(); |
|||
_pathway.DisplayProbes = false; |
|||
|
|||
if (_pathway.Waypoints.Count > 1) |
|||
{ |
|||
for (int i = 0; i < _pathway.Waypoints.Count; i++) |
|||
{ |
|||
existsPath &= _pathwayNavMesh.HasNavMeshAt(i); |
|||
existsPath &= _pathwayNavMesh.UpdateCornersAt(i); |
|||
} |
|||
|
|||
if (existsPath) |
|||
{ |
|||
_pathwayNavMesh.UpdatePath(); |
|||
} |
|||
} |
|||
|
|||
_pathway.DisplayProbes = !existsPath; |
|||
} |
|||
|
|||
public void GeneratePath() |
|||
{ |
|||
if (_pathway.ToggledNavMeshDisplay) |
|||
{ |
|||
RestorePath(); |
|||
_pathway.ToggledNavMeshDisplay = !_pathway.DisplayProbes; |
|||
} |
|||
} |
|||
|
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 1114de2a61dc66e489f951c4ed04991f |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using UnityEngine.AI; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
|
|||
public class PathwayNavMesh |
|||
{ |
|||
private Pathway _pathway; |
|||
|
|||
public PathwayNavMesh(Pathway pathway) |
|||
{ |
|||
_pathway = pathway; |
|||
_pathway.Hits = new List<bool>(); |
|||
} |
|||
|
|||
public bool HasNavMeshAt(int index) |
|||
{ |
|||
NavMeshHit hit; |
|||
bool hasHit = true; |
|||
|
|||
if (_pathway.Waypoints.Count >= _pathway.Hits.Count) |
|||
{ |
|||
hasHit = NavMesh.SamplePosition(_pathway.Waypoints[index].waypoint, out hit, _pathway.ProbeRadius, NavMesh.AllAreas); |
|||
|
|||
if (index > _pathway.Hits.Count - 1) |
|||
{ |
|||
index = _pathway.Hits.Count; |
|||
_pathway.Hits.Add(hasHit); |
|||
} |
|||
else |
|||
{ |
|||
_pathway.Hits[index] = hasHit; |
|||
|
|||
} |
|||
|
|||
if (hasHit) |
|||
{ |
|||
_pathway.Waypoints[index].waypoint = hit.position; |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
_pathway.Hits.RemoveAt(index); |
|||
} |
|||
|
|||
return hasHit; |
|||
} |
|||
|
|||
private List<Vector3> GetPathCorners(int startIndex, int endIndex) |
|||
{ |
|||
NavMeshPath navMeshPath = new NavMeshPath(); |
|||
|
|||
if (NavMesh.CalculatePath(_pathway.Waypoints[startIndex].waypoint, _pathway.Waypoints[endIndex].waypoint, NavMesh.AllAreas, navMeshPath)) |
|||
{ |
|||
return navMeshPath.corners.ToList(); |
|||
} |
|||
|
|||
else |
|||
return null; |
|||
} |
|||
|
|||
private bool CopyCorners(int startIndex, int endIndex) |
|||
{ |
|||
List<Vector3> result; |
|||
|
|||
if ((result = GetPathCorners(startIndex, endIndex)) != null) |
|||
{ |
|||
_pathway.Waypoints[startIndex].corners = result; |
|||
} |
|||
|
|||
return result != null; |
|||
} |
|||
|
|||
public bool UpdateCornersAt(int index) |
|||
{ |
|||
bool canUpdate = true; |
|||
|
|||
if (_pathway.Waypoints.Count > 1 && index <_pathway.Waypoints.Count) |
|||
{ |
|||
if (index == 0) |
|||
{ |
|||
canUpdate = CopyCorners(index, index + 1); |
|||
canUpdate &= CopyCorners(_pathway.Waypoints.Count - 1, index); |
|||
} |
|||
else if (index == _pathway.Waypoints.Count - 1) |
|||
{ |
|||
|
|||
canUpdate = CopyCorners(index - 1, index); |
|||
canUpdate &= CopyCorners(index, 0); |
|||
} |
|||
else |
|||
{ |
|||
canUpdate = CopyCorners(index - 1, index); |
|||
canUpdate &= CopyCorners(index, index + 1); |
|||
} |
|||
} |
|||
|
|||
return canUpdate; |
|||
} |
|||
|
|||
public void UpdatePath() |
|||
{ |
|||
if (_pathway.Waypoints.Count > 1) |
|||
{ |
|||
_pathway.Path = _pathway.Waypoints.Aggregate(new List<Vector3>(), (acc, wpd) => |
|||
{ |
|||
wpd.corners.ForEach(c => acc.Add(c)); |
|||
return acc; |
|||
}); |
|||
} |
|||
else |
|||
{ |
|||
_pathway.Path.Clear(); |
|||
} |
|||
} |
|||
|
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 89ec3dfe690498548a5787eb410bb855 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue