mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-12-11 21:22:36 +00:00
71 lines
2.4 KiB
C#
71 lines
2.4 KiB
C#
using System.Linq;
|
|
using SanAndreasUnity.Behaviours.Peds.AI;
|
|
using SanAndreasUnity.Importing.Paths;
|
|
using SanAndreasUnity.Utilities;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
namespace SanAndreasUnity.Editor
|
|
{
|
|
[CustomEditor(typeof(PedAI))]
|
|
public class PedAIInspector : UnityEditor.Editor
|
|
{
|
|
private static bool _foldoutCurrent = true;
|
|
private static bool _foldoutDestination = true;
|
|
private static bool _foldoutLinkedCurrent = true;
|
|
private static bool _foldoutLinkedDestination = true;
|
|
|
|
|
|
public override void OnInspectorGUI()
|
|
{
|
|
base.DrawDefaultInspector ();
|
|
|
|
var pedAI = (PedAI) this.target;
|
|
|
|
GUILayout.Space (10);
|
|
|
|
if (pedAI.CurrentState is IPathMovementState pathMovementState)
|
|
{
|
|
if (pathMovementState.PathMovementData.currentNode.HasValue)
|
|
DrawForNode(pathMovementState.PathMovementData.currentNode.Value, "Current node", ref _foldoutCurrent, true, ref _foldoutLinkedCurrent);
|
|
if (pathMovementState.PathMovementData.destinationNode.HasValue)
|
|
DrawForNode(pathMovementState.PathMovementData.destinationNode.Value, "Destination node", ref _foldoutDestination, true, ref _foldoutLinkedDestination);
|
|
}
|
|
}
|
|
|
|
void DrawForNode(PathNode node, string labelText, ref bool foldout, bool showLinkedNodes, ref bool foldoutLinked)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(labelText))
|
|
foldout = EditorGUILayout.Foldout(foldout, labelText, true);
|
|
|
|
if (!foldout)
|
|
return;
|
|
|
|
if (GUILayout.Button("Goto"))
|
|
GoTo(node);
|
|
|
|
EditorUtils.DrawFieldsAndPropertiesInInspector(node, 0);
|
|
|
|
if (showLinkedNodes)
|
|
{
|
|
foldoutLinked = EditorGUILayout.Foldout(foldoutLinked, "Linked nodes", true);
|
|
if (foldoutLinked)
|
|
{
|
|
foreach (var linkedNode in NodeReader.GetAllLinkedNodes(node))
|
|
{
|
|
bool f = true;
|
|
bool fLinked = false;
|
|
DrawForNode(linkedNode, "", ref f, false, ref fLinked);
|
|
}
|
|
}
|
|
}
|
|
|
|
GUILayout.Space(5);
|
|
}
|
|
|
|
void GoTo(PathNode node)
|
|
{
|
|
SceneView.sceneViews.Cast<SceneView>().ForEach(s => s.LookAt(node.Position));
|
|
}
|
|
}
|
|
}
|