这是第一个 Unity 开放项目的repo,是 Unity 和社区合作创建的一个小型开源游戏演示,第一款游戏是一款名为 Chop Chop 的动作冒险游戏。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

106 行
1.8 KiB

using UnityEngine;
using UnityEditorInternal;
public class PathWayNavMeshUI
{
private PathwayConfigSO _pathway;
private PathwayNavMesh _pathwayNavMesh;
public PathWayNavMeshUI(PathwayConfigSO 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;
}
}
}