mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-10 06:34:16 +00:00
add inspector for MovementAgent
This commit is contained in:
parent
9b521a7e96
commit
07e1a7fff6
2 changed files with 71 additions and 0 deletions
60
Assets/Scripts/Editor/MovementAgentInspector.cs
Normal file
60
Assets/Scripts/Editor/MovementAgentInspector.cs
Normal file
|
@ -0,0 +1,60 @@
|
|||
using SanAndreasUnity.Utilities;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
namespace SanAndreasUnity.Editor
|
||||
{
|
||||
[CustomEditor(typeof(MovementAgent))]
|
||||
public class MovementAgentInspector : UnityEditor.Editor
|
||||
{
|
||||
static string[] s_propertyNames = new string[]
|
||||
{
|
||||
nameof(NavMeshAgent.hasPath),
|
||||
nameof(NavMeshAgent.pathPending),
|
||||
nameof(NavMeshAgent.pathStatus),
|
||||
nameof(NavMeshAgent.isPathStale),
|
||||
nameof(NavMeshAgent.isOnNavMesh),
|
||||
nameof(NavMeshAgent.isStopped),
|
||||
nameof(NavMeshAgent.remainingDistance),
|
||||
nameof(NavMeshAgent.desiredVelocity),
|
||||
nameof(NavMeshAgent.velocity),
|
||||
};
|
||||
|
||||
static string[] s_propertyNamesToExcludeWhenNotOnNavMesh = new string[]
|
||||
{
|
||||
nameof(NavMeshAgent.isStopped),
|
||||
nameof(NavMeshAgent.remainingDistance),
|
||||
};
|
||||
|
||||
static PropertyInfo[] s_propertyInfos = s_propertyNames
|
||||
.Select(n => typeof(NavMeshAgent).GetProperty(n, BindingFlags.Instance | BindingFlags.Public))
|
||||
.ToArray();
|
||||
|
||||
static PropertyInfo[] s_propertyInfosWhenNotOnNavMesh = s_propertyNames.Except(s_propertyNamesToExcludeWhenNotOnNavMesh)
|
||||
.Select(n => typeof(NavMeshAgent).GetProperty(n, BindingFlags.Instance | BindingFlags.Public))
|
||||
.ToArray();
|
||||
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
base.DrawDefaultInspector();
|
||||
|
||||
GUILayout.Space(10);
|
||||
GUILayout.Label("Nav mesh agent info:");
|
||||
GUILayout.Space(10);
|
||||
|
||||
var movementAgent = (MovementAgent)this.target;
|
||||
|
||||
if (movementAgent.NavMeshAgent != null)
|
||||
{
|
||||
bool isOnNavMesh = movementAgent.NavMeshAgent.isOnNavMesh;
|
||||
EditorUtils.DrawPropertiesInInspector(movementAgent.NavMeshAgent, isOnNavMesh ? s_propertyInfos : s_propertyInfosWhenNotOnNavMesh, false);
|
||||
EditorGUILayout.LabelField("Diff between simulation position: " + (movementAgent.NavMeshAgent.nextPosition - movementAgent.transform.position));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
11
Assets/Scripts/Editor/MovementAgentInspector.cs.meta
Normal file
11
Assets/Scripts/Editor/MovementAgentInspector.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fc5625d4b142cbf43b20d98df8080f1a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in a new issue