Refactoring of the interaction system and preliminary integration of save/load functionality across the game. (#44)
### Interactables Architecture Refactor - Converted composition to inheritance, moved from component-based to class-based interactables. No more requirement for chain of "Interactable -> Item" etc. - Created `InteractableBase` abstract base class with common functionality that replaces the old component - Specialized child classes: `Pickup`, `ItemSlot`, `LevelSwitch`, `MinigameSwitch`, `CombinationItem`, `OneClickInteraction` are now children classes - Light updates to the interactable inspector, moved some things arround, added collapsible inspector sections in the UI for better editor experience ### State Machine Integration - Custom `AppleMachine` inheritong from Pixelplacement's StateMachine which implements our own interface for saving, easy place for future improvements - Replaced all previous StateMachines by `AppleMachine` - Custom `AppleState` extends from default `State`. Added serialization, split state logic into "EnterState", "RestoreState", "ExitState" allowing for separate logic when triggering in-game vs loading game - Restores directly to target state without triggering transitional logic - Migration tool converts existing instances ### Prefab Organization - Saved changes from scenes into prefabs - Cleaned up duplicated components, confusing prefabs hierarchies - Created prefab variants where possible - Consolidated Environment prefabs and moved them out of Placeholders subfolder into main Environment folder - Organized item prefabs from PrefabsPLACEHOLDER into proper Items folder - Updated prefab references - All scene references updated to new locations - Removed placeholder files from Characters, Levels, UI, and Minigames folders ### Scene Updates - Quarry scene with major updates - Saved multiple working versions (Quarry, Quarry_Fixed, Quarry_OLD) - Added proper lighting data - Updated all interactable components to new architecture ### Minor editor tools - New tool for testing cards from an editor window (no in-scene object required) - Updated Interactable Inspector - New debug option to opt in-and-out of the save/load system - Tooling for easier migration Co-authored-by: Michal Pikulski <michal.a.pikulski@gmail.com> Reviewed-on: #44
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Interactions
|
||||
{
|
||||
[CustomEditor(typeof(Interactable))]
|
||||
[CustomEditor(typeof(InteractableBase), true)]
|
||||
public class InteractableEditor : UnityEditor.Editor
|
||||
{
|
||||
SerializedProperty isOneTimeProp;
|
||||
@@ -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,70 +32,96 @@ 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
|
||||
Interactable interactable = (Interactable)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();
|
||||
}
|
||||
|
||||
private void CreateMoveTarget(CharacterToInteract characterType)
|
||||
{
|
||||
Interactable interactable = (Interactable)target;
|
||||
InteractableBase interactable = (InteractableBase)target;
|
||||
|
||||
// Create a new GameObject
|
||||
GameObject targetObj = new GameObject($"{characterType}MoveTarget");
|
||||
|
||||
Reference in New Issue
Block a user