SanAndreasUnity/Assets/Scripts/Editor/PedAIInspector.cs

72 lines
2.4 KiB
C#
Raw Normal View History

2021-09-11 03:29:29 +00:00
using System.Linq;
2021-09-19 18:09:11 +00:00
using SanAndreasUnity.Behaviours.Peds.AI;
2021-09-11 03:29:29 +00:00
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 _foldoutTarget = true;
2021-09-11 15:21:15 +00:00
private static bool _foldoutLinkedCurrent = true;
private static bool _foldoutLinkedTarget = true;
2021-09-11 03:29:29 +00:00
public override void OnInspectorGUI()
{
base.DrawDefaultInspector ();
var pedAI = (PedAI) this.target;
GUILayout.Space (10);
2021-09-26 18:29:42 +00:00
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, "Target node", ref _foldoutTarget, true, ref _foldoutLinkedTarget);
}
2021-09-11 03:29:29 +00:00
}
2021-09-11 15:21:15 +00:00
void DrawForNode(PathNode node, string labelText, ref bool foldout, bool showLinkedNodes, ref bool foldoutLinked)
2021-09-11 03:29:29 +00:00
{
if (!string.IsNullOrWhiteSpace(labelText))
foldout = EditorGUILayout.Foldout(foldout, labelText, true);
if (!foldout)
return;
if (GUILayout.Button("Goto"))
GoTo(node);
EditorUtils.DrawFieldsAndPropertiesInInspector(node, 0);
2021-09-11 15:21:15 +00:00
if (showLinkedNodes)
2021-09-11 03:29:29 +00:00
{
2021-09-11 15:21:15 +00:00
foldoutLinked = EditorGUILayout.Foldout(foldoutLinked, "Linked nodes", true);
if (foldoutLinked)
2021-09-11 03:29:29 +00:00
{
2021-09-11 15:21:15 +00:00
foreach (var linkedNode in NodeReader.GetAllLinkedNodes(node))
2021-09-11 03:29:29 +00:00
{
bool f = true;
2021-09-11 15:21:15 +00:00
bool fLinked = false;
DrawForNode(linkedNode, "", ref f, false, ref fLinked);
2021-09-11 03:29:29 +00:00
}
}
}
GUILayout.Space(5);
}
void GoTo(PathNode node)
{
SceneView.sceneViews.Cast<SceneView>().ForEach(s => s.LookAt(node.Position));
}
}
}