浏览代码

Made the handles pointing into the forward direction of the pathway

/main
Yohann Puyhaubert 4 年前
当前提交
273993ab
共有 5 个文件被更改,包括 29 次插入53 次删除
  1. 12
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Config/NPCPathwayConfig.asset
  2. 3
      UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayEditor.cs
  3. 27
      UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayGizmos.cs
  4. 29
      UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayHandles.cs
  5. 11
      UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayHandles.cs.meta

12
UOP1_Project/Assets/ScriptableObjects/StateMachine/Config/NPCPathwayConfig.asset


_stopDuration: 0.5
_speed: 1
Waypoints:
- {x: 3.4739745, y: 0.033730388, z: 0.6266351}
- {x: 12.061079, y: 0.15954088, z: 9.731606}
- {x: -6.2887483, y: 0.033730388, z: 7.971367}
- {x: -15.76542, y: 0.033730388, z: -0.2936163}
- {x: -11.600259, y: 0.033730388, z: -4.42002}
- {x: 3.46387, y: 0.033730388, z: 0.55213976}
- {x: 5.6019807, y: 0.052446984, z: 7.11369}
- {x: -2.8645186, y: 0.033730388, z: 8.923655}
- {x: -6.567141, y: 0.033730388, z: -5.250761}
- {x: -9.866049, y: 0.033730388, z: -5.822654}
- {x: -11.059804, y: 0.033730388, z: -2.8135128}
- {x: -2.0687637, y: 0.033730388, z: 0.8148103}
_pathwayEditorColor: {r: 0, g: 1, b: 1, a: 1}

3
UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayEditor.cs


{
private ReorderableList _reorderableList;
private PathwayConfigSO _pathway;
private PathwayHandles _pathwayHandles;
_pathwayHandles.DispalyHandles();
PathwayGizmos.DrawHandlesPath(_pathway);
}

_reorderableList.onSelectCallback += SelectItem;
_reorderableList.onChangedCallback += ListModified;
_pathway = (target as PathwayConfigSO);
_pathwayHandles = new PathwayHandles(_pathway);
if (CheckNavMeshExistence())
{
SceneView.duringSceneGui += this.OnSceneGUI;

27
UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayGizmos.cs


{
public static void DrawHandlesPath(PathwayConfigSO pathway)
{
if (pathway.Waypoints.Count != 0)
EditorGUI.BeginChangeCheck();
// Snap the waypoints on the NavMesh
for (int i = 0; i < pathway.Waypoints.Count; i++)
DrawElements(pathway, pathway.Waypoints, 0);
NavMesh.SamplePosition(pathway.Waypoints[i], out NavMeshHit hit, 99.0f, NavMesh.AllAreas);
pathway.Waypoints[i] = hit.position;
}
// Only one waypoint use case.
if (pathway.Waypoints.Count == 1)
{
DrawWaypointLabel(pathway, pathway.Waypoints, 0);
pathway.Waypoints[0] = Handles.PositionHandle(pathway.Waypoints[0], Quaternion.identity);
if (pathway.Waypoints.Count > 1)
// All the other use cases where a path exists.
else if (pathway.Waypoints.Count > 1)
DrawElements(pathway, pathway.Waypoints, index);
DrawWaypointLabel(pathway, pathway.Waypoints, index);
List<Vector3> navMeshPath = new List<Vector3>();
NavMeshPath navPath = new NavMeshPath();
NavMesh.CalculatePath(pathway.Waypoints[index], pathway.Waypoints[nextIndex], NavMesh.AllAreas, navPath);

Handles.DrawDottedLine(navPath.corners[j], navPath.corners[j + 1], 2);
}
}
// Display handles pointing into the path forward direction (Blue handle)
if (navPath.corners.Length > 1)
{
pathway.Waypoints[index] = Handles.PositionHandle(pathway.Waypoints[index], Quaternion.LookRotation(navPath.corners[1] - navPath.corners[0]));
}
private static void DrawElements(PathwayConfigSO pathway, List<Vector3> path, int index)
private static void DrawWaypointLabel(PathwayConfigSO pathway, List<Vector3> path, int index)
{
GUIStyle style = new GUIStyle();
Vector3 textHeight = Vector3.up;

29
UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayHandles.cs


using UnityEngine;
using UnityEditor;
using UnityEngine.AI;
public class PathwayHandles
{
private PathwayConfigSO _pathway;
public PathwayHandles(PathwayConfigSO pathway)
{
_pathway = pathway;
}
public void DispalyHandles()
{
EditorGUI.BeginChangeCheck();
for (int i = 0; i < _pathway.Waypoints.Count; i++)
{
_pathway.Waypoints[i] = Handles.PositionHandle(_pathway.Waypoints[i], Quaternion.identity);
}
for (int i = 0; i < _pathway.Waypoints.Count; i++)
{
NavMesh.SamplePosition(_pathway.Waypoints[i], out NavMeshHit hit, 99.0f, NavMesh.AllAreas);
_pathway.Waypoints[i] = hit.position;
}
}
}

11
UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayHandles.cs.meta


fileFormatVersion: 2
guid: a8dcb713973bd474e9d3eb21e77c8fa4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存