Home - imagine-uniandes/Tweenity2.0 GitHub Wiki
Tweenity Graph Editor - UI Documentation
Overview
Tweenity Graph Editor is a custom Unity Editor Window designed to manage and visualize node-based structures. The system uses a modular and extensible Model-View-Controller (MVC) architecture to promote separation of concerns and maintainability.
Architecture Pattern:
As of 2025-04-07, the Tweenity Graph Editor follows a strict and robust Model–View–Controller (MVC) architecture, designed for modularity, scalability, and maintainability in Unity's Editor environment.
This separation of concerns ensures clean code boundaries and predictable data flow throughout the system.
Models/
)
Model Layer (The Model layer is responsible for representing all data structures that define the graph logic.
- Each node in the graph is represented by a class inheriting from
TweenityNodeModel
. - Node variants such as
DialogueNodeModel
,StartNodeModel
,ReminderNodeModel
, etc., encapsulate specific properties relevant to their behavior. - Nodes are uniquely identified via
NodeID
(UUID). - All nodes are stored and managed via
GraphModel
, which:- Prevents multiple
Start
nodes from being added. - Provides methods to add, retrieve, and remove nodes.
- Prevents multiple
- The
NodeType
enum defines the classification of supported node types. GraphParser
handles serialization/deserialization of graph data to and from.twee
format, enabling round-trip editing between the visual editor and Twine-based workflows.
Controllers/
)
Controller Layer (The Controller acts as the central orchestrator of the application, maintaining the state of the graph and ensuring synchronization between UI and data.
GraphController
:- Mediates all interactions initiated by UI elements (view components).
- Manages the lifecycle of nodes: creation, deletion, editing, and transformation (e.g., changing node type).
- Ensures business logic is enforced (e.g., only one Start node, valid connections).
- Updates the view after changes to the model, including rerendering and refreshing.
- Coordinates connection logic between nodes using a click-to-connect workflow (
StartConnectionFrom
/TryConnectTo
). - Delegates serialization to
GraphParser
for export/import. - Responds to UI events from toolbars, right/left panels, and graph interaction.
Views/
)
View Layer (The View layer is composed of Unity UI Toolkit (UIElements
) visual components and GraphView-based rendering.
- Views are logic-free and strictly presentational.
- They display the state of the model but delegate all data manipulation to the controller.
- Each section of the UI is modular:
TweenityGraphView
: Central canvas for node rendering and connection drawing.TweenityNode
: Visual representation of a node (title, type, description, color).- Right Panel:
- Each node type has a dedicated view (e.g.,
DialogueView
,MultipleChoiceView
). - All extend
TweenityNodeView
, which handles shared fields like title, description, and node type.
- Each node type has a dedicated view (e.g.,
- Toolbars (top and bottom): trigger controller methods for save/export/debug actions.
- Left Panel: Currently hosts search functionality, designed for future hierarchy visualization.
Interaction Flow Summary
- User interacts with the UI (e.g., changes title, clicks connect, edits responses).
- The View notifies the Controller (e.g.,
GraphController.UpdateNodeTitle()
). - The Controller updates the Model, and then triggers any necessary view updates (e.g., rerendering the node).
- The Model holds the true state, while Views are synced representations.
This separation ensures that the controller is the single source of truth for application logic, while the model maintains all persistent state and the views remain highly reusable.
Project Structure
Models/
)
1. Models (- GraphModel.cs: Represents a Complete node graph containing all nodes and their connections
- NodeType.cs: Enum of supported node types.
- Node Models (
Models/Nodes/
): Data representations of each node type likeStartNodeModel
,DialogueNodeModel
,TimeoutNodeModel
, etc. - Responsibilities:
- Contain and validate node data.
- Enforce structural constraints (e.g., only one
StartNode
). - Manage custom properties per node type (
Responses
,Choices
, etc.). - Support
.twee
import/export viaGraphParser
.
Controllers/
)
2. Controllers (-
GraphController.cs:
- Central manager of application state and graph logic.
- Adds/removes/updates nodes.
- Handles connection creation and cleanup.
- Renders changes in
GraphView
. - Exports/imports graph using
GraphParser
. - Returns error messages for invalid operations.
-
GraphParser.cs:
- Converts graphs to and from
.twee
format. - Used for import/export compatibility with Twine-based story structures.
- Converts graphs to and from
Views/
)
3. Views (Toolbar (TweenityToolbar.cs)
- Save, Load, Export
.twee
, Zoom tools, Add Node button. - All actions delegate to
GraphController
.
Left Panel (TweenityLeftPanel.cs)
- Search bar with real-time filtering.
- All events routed through controller.
Graph View (TweenityGraphView.cs)
- Visual display of graph using a common
TweenityNode
. - Handles zoom, panning, node rendering, and edge connections.
- Calls
RenderConnections
to draw visual links. - Each node has input/output ports.
Right Panel (TweenityRightPanel.cs)
- Dynamically renders editable fields for selected node.
- Each node view (
StartView
,DialogueView
, etc.) inherits fromTweenityNodeView
. - Common editable fields: title, description, type.
- Type-specific fields:
- Dialogue:
DialogueText
,Responses
- MultipleChoice:
Question
,Choices
- Random:
Paths
- Reminder:
ReminderText
,ReminderTimer
- Timeout:
Condition
,TimeoutDuration
, dual connection buttons
- Dialogue:
- On error, resets dropdown and shows warning via
EditorUtility.DisplayDialog
.
Bottom Toolbar (TweenityBottomToolbar.cs)
- Debugging buttons:
Debugging
: Logs full graph state.Current Selection
: Logs selected node(s).
Key Concepts & Interaction Flow
- All interactions go through
GraphController
. - Views are logic-free and reflect model state only.
- Right panel views are initialized with both the node model and controller.
- Dynamic node type changes are supported (with validation).
- Node connections handled via
StartConnectionFrom
andTryConnectTo
logic. - Visual nodes auto-update appearance and labels using
UpdateFromModel
.
Visual Styling per NodeType
NodeType | Background Color | Text Color |
---|---|---|
Start | Soft Green (#81C784 ) |
Deep Green (#1B5E20 ) |
End | Vivid Red (#EF5350 ) |
White (#FFFFFF ) |
Dialogue | Soft Purple (#BA68C8 ) |
Light Gray (#FAFAFA ) |
MultipleChoice | Yellow-Orange (#FFB300 ) |
Dark Brown (#422800 ) |
Reminder | Sky Blue (#64B5F6 ) |
Indigo (#0D47A1 ) |
Timeout | Light Blue (#90CAF9 ) |
Slate Blue (#1E3C50 ) |
Random | Amber Yellow (#FFD54F ) |
Dark Brown (#422800 ) |
NoType | Dark Gray (#333333 ) |
Light Gray (#DADADA ) |
Last updated: 2025-04-07