Update inspector to be less annoying

This commit is contained in:
Michal Pikulski
2025-11-02 10:45:14 +01:00
parent 475464dccf
commit 5d6d4c8ba1
2 changed files with 391 additions and 100 deletions

View File

@@ -14,6 +14,9 @@ namespace Interactions
SerializedProperty characterArrivedProp;
SerializedProperty interactionCompleteProp;
private bool showBaseSettings = true;
private bool showEvents = false;
private void OnEnable()
{
isOneTimeProp = serializedObject.FindProperty("isOneTime");
@@ -29,63 +32,89 @@ namespace Interactions
{
serializedObject.Update();
EditorGUILayout.LabelField("Interaction Settings", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(isOneTimeProp);
EditorGUILayout.PropertyField(cooldownProp);
EditorGUILayout.PropertyField(characterToInteractProp);
// Draw child-specific properties first (anything not part of base class)
DrawPropertiesExcluding(serializedObject,
"m_Script",
"isOneTime",
"cooldown",
"characterToInteract",
"interactionStarted",
"interactionInterrupted",
"characterArrived",
"interactionComplete");
// Add the buttons for creating move targets
// Base Interaction Settings (Collapsible)
EditorGUILayout.Space(10);
EditorGUILayout.LabelField("Character Move Targets", EditorStyles.boldLabel);
showBaseSettings = EditorGUILayout.Foldout(showBaseSettings, "Base Interaction Settings", true, EditorStyles.foldoutHeader);
if (showBaseSettings)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(isOneTimeProp);
EditorGUILayout.PropertyField(cooldownProp);
EditorGUILayout.PropertyField(characterToInteractProp);
// Character Move Targets (sub-section)
EditorGUILayout.Space(5);
EditorGUILayout.LabelField("Character Move Targets", EditorStyles.boldLabel);
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("Add Trafalgar Target"))
{
CreateMoveTarget(CharacterToInteract.Trafalgar);
}
if (GUILayout.Button("Add Pulver Target"))
{
CreateMoveTarget(CharacterToInteract.Pulver);
}
EditorGUILayout.EndHorizontal();
// Add a button for creating a "Both" target
if (GUILayout.Button("Add Both Characters Target"))
{
CreateMoveTarget(CharacterToInteract.Both);
}
// Display character target counts
InteractableBase interactable = (InteractableBase)target;
CharacterMoveToTarget[] moveTargets = interactable.GetComponentsInChildren<CharacterMoveToTarget>();
int trafalgarTargets = 0;
int pulverTargets = 0;
int bothTargets = 0;
foreach (var target in moveTargets)
{
if (target.characterType == CharacterToInteract.Trafalgar)
trafalgarTargets++;
else if (target.characterType == CharacterToInteract.Pulver)
pulverTargets++;
else if (target.characterType == CharacterToInteract.Both)
bothTargets++;
}
EditorGUILayout.LabelField($"Trafalgar Targets: {trafalgarTargets}, Pulver Targets: {pulverTargets}, Both Targets: {bothTargets}");
if (trafalgarTargets > 1 || pulverTargets > 1 || bothTargets > 1 ||
(bothTargets > 0 && (trafalgarTargets > 0 || pulverTargets > 0)))
{
EditorGUILayout.HelpBox("Warning: Multiple move targets found that may conflict. Priority order: Both > Character-specific targets.", MessageType.Warning);
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("Add Trafalgar Target"))
{
CreateMoveTarget(CharacterToInteract.Trafalgar);
}
if (GUILayout.Button("Add Pulver Target"))
{
CreateMoveTarget(CharacterToInteract.Pulver);
}
EditorGUILayout.EndHorizontal();
// Add a button for creating a "Both" target
if (GUILayout.Button("Add Both Characters Target"))
{
CreateMoveTarget(CharacterToInteract.Both);
}
// Display character target counts
InteractableBase interactable = (InteractableBase)target;
CharacterMoveToTarget[] moveTargets = interactable.GetComponentsInChildren<CharacterMoveToTarget>();
int trafalgarTargets = 0;
int pulverTargets = 0;
int bothTargets = 0;
foreach (var target in moveTargets)
{
if (target.characterType == CharacterToInteract.Trafalgar)
trafalgarTargets++;
else if (target.characterType == CharacterToInteract.Pulver)
pulverTargets++;
else if (target.characterType == CharacterToInteract.Both)
bothTargets++;
}
EditorGUILayout.LabelField($"Trafalgar Targets: {trafalgarTargets}, Pulver Targets: {pulverTargets}, Both Targets: {bothTargets}");
if (trafalgarTargets > 1 || pulverTargets > 1 || bothTargets > 1 ||
(bothTargets > 0 && (trafalgarTargets > 0 || pulverTargets > 0)))
{
EditorGUILayout.HelpBox("Warning: Multiple move targets found that may conflict. Priority order: Both > Character-specific targets.", MessageType.Warning);
}
EditorGUI.indentLevel--;
}
// Interaction Events (Collapsible)
EditorGUILayout.Space(10);
EditorGUILayout.LabelField("Interaction Events", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(interactionStartedProp);
EditorGUILayout.PropertyField(interactionInterruptedProp);
EditorGUILayout.PropertyField(characterArrivedProp);
EditorGUILayout.PropertyField(interactionCompleteProp);
showEvents = EditorGUILayout.Foldout(showEvents, "Interaction Events", true, EditorStyles.foldoutHeader);
if (showEvents)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(interactionStartedProp);
EditorGUILayout.PropertyField(interactionInterruptedProp);
EditorGUILayout.PropertyField(characterArrivedProp);
EditorGUILayout.PropertyField(interactionCompleteProp);
EditorGUI.indentLevel--;
}
serializedObject.ApplyModifiedProperties();
}

File diff suppressed because one or more lines are too long