ActionManager - vr4vet/Blue-Sector GitHub Wiki

ActionManager

A singleton “logger” MonoBehaviour that tracks player interactions, task progress, chat history, and idle time between tasks, then packages it all into an UploadDataDTO for AIRequest to send to Chat-Service


Setup & Dependencies

  • Prefab: ActionManager, located in VR4VET/Components/ActionManager
  • Required Components on the GameObject:
    • ActionManager.cs
    • IdleTimer
  • Also requires to function properly:
    • Optional Grabber instances (for grab/release events)
    • A running Task system via WatchManager (defines Task.Task, Task.Subtask, Task.Step)
    • A chat/NPC AI implementation (to consume global chat logs)
    • A way to send the global chat logs (Handled by AIRequest.cs through AIConversationController.cs
    • Ideally Chat-Service running on a server somewhere

Event Hooks

  1. Scene Changes

    • Registers SceneManager.sceneLoadedOnSceneLoaded
    • Writes scene.name into _uploadData.scene_name
  2. Grab & Release

    • Finds all Grabber components in the scene at OnEnable()
    • Hooks onAfterGrabEventOnGrabEvent(Grabbable grabbable)
    • Hooks onReleaseEventOnReleaseEvent(Grabbable grabbable)

To add e.g. UI-button events:

  • Register listeners in OnEnable()
  • Unregister in OnDisable()
  • Implement your handler methods on the same pattern.

Task Tracking & Logging

  • Hierarchy:
  Task (ScriptableObject)
   └─ Subtask (ScriptableObject)
       └─ Step (ScriptableObject)
  • Initialization:

    • Call ActionManager.Instance.LogTaskHierarchy(taskList) after your TaskHolder has loaded or reset the list of tasks.
    • taskList should be a List<Task.Task> (as used in WatchManager and TaskHolder).
  • Step Completion:

    • When a step is completed (typically from WatchManager.CompleteStep), call:
ActionManager.Instance.LogStepCompletion(finishedStep);
  • finishedStep should be a reference to the completed Task.Step instance.
  • Summary Generation:
    • To generate a progress summary (for display in the tablet UI, for example), call:
ActionManager.Instance.TaskSummary();
  • The summary is stored in ActionManager.Instance.LatestSummary as an HTML-formatted string with colored progress stats

(this should be updated to Text Fields on gameObjects or the like... at least it shouldn't be in the ActionManager....


Chat & AI Integration

  • Global Chat Logs:
    • Add messages via AddChatMessage(Message msg)
    • Retrieve via GetGlobalChatLogs()
  • Message DTO:
  public class Message {
    public string role;    // e.g. "user" or "assistant"
    public string content;
  }
  • AI Functionality Toggle:
    • Controlled by SetToggleBool(bool) / GetToggleBool()
    • Used by AI NPCs (e.g. “AIna” in ReceptionOutdoor scene) to determine if AI features are enabled

UploadData & Networking

  • Data Collector:
    • All info is built into _uploadData (type UploadDataDTO)
    • Sent to AIRequest when conversing with an NPC

Customization & Extension

  • Recording Custom Actions:
  ActionManager.Instance.GetUploadData()
               .user_actions
               .Add("myCustomAction: details");
  // Optionally trim:
  // ActionManager.Instance.ShortenList(ActionManager.Instance.GetUploadData().user_actions, 20);

Debugging & Troubleshooting

  • Common Warnings:
    • “IdleTimer component not found…” → add IdleTimer to prefab
    • “Could not find step X” → ensure LogStepCompletion is called with the correct Step instance
  • Resetting Logs for Tests:
  ActionManager.Instance.GetUploadData().user_actions.Clear();
  ActionManager.Instance.GetGlobalChatLogs().Clear();
  // or replace with new List<T>()
⚠️ **GitHub.com Fallback** ⚠️