Amanita

repository·develop·Indexed 42 days ago

https://github.com/atelier-mycelia/amanita

A modernized, community-driven, and free spiritual successor to the Fungus asset package for Unity. It facilitates narrative-driven game development and interactive storytelling—such as visual novels and point-and-click adventures—through visual scripting, allowing users to create games without coding experience. Supports Unity 6 LTS and Unity 2022 LTS.

Tokens
87K
Snippets
270
Records
352
Agent score
53%

What's inside Amanita

  1. Overview of Fungus for Interactive Storytelling

    develop

    Fungus is a free, open-source tool for Unity 3D designed to create interactive storytelling games. It is optimized for both beginners with no coding experience and power users seeking a fast visual scripting workflow.

    Common use cases include:

    • Visual Novels
    • Point and Click Adventure Games
    • Children's Stories
    • Hidden Object Games
    • eLearning applications
  2. Understand the Playground demonstration structure

    develop

    The Playground is a collection of scenes designed to demonstrate how to configure and use physics-driven behavior in Unity3D using Fungus. These scenes are not standalone games but serve as technical demonstrations of integrating Fungus flowcharts with Unity physics components.

    Key Architectural Patterns:

    • Multi-Flowchart Control: A single scene uses multiple flowcharts to control different aspects of the simulation, such as individual objects, game resources, game rules, and the GUI.
    • Physics Integration: Scenes utilize Rigidbody2D, Collisions, and Triggers. FungusVariable is used to hold references to Rigidbody2D components.
    • Event-Driven Logic: Triggers and Collisions are handled via EventHandlers under the MonoBehaviour Event category.
    • Communication Pattern: Game interactions use the SendMessage command to communicate specific events to a central GameRules Flowchart. The GameRules flowchart listens for these messages via EventHandlers to update game state (score, lives, etc.) and the UI.
  3. How TextAdapter enables TextMeshPro support

    develop

    Amanita uses the TextAdapter to bridge the gap between the dialog system and TextMeshPro. The TextAdapter works by searching for a component on the target GameObject that possesses a text property. Since TextMeshPro components include this property, the TextAdapter can automatically target them.

    Note: Future versions may offer deeper integration, such as leveraging TMPro's 'revealed characters' feature within the Writer component.

  4. Use SendMessage for game rule orchestration

    develop

    To decouple game objects from game logic, use the SendMessage command to notify a central controller (e.g., a GameRules Flowchart) when specific interactions occur.

    Example Workflow:

    1. Trigger Event: An object (like a Goal or Ground) detects a collision or trigger entry.
    2. Send Message: The object executes a SendMessage command.
    3. Handle Event: The GameRules Flowchart uses EventHandlers to catch the message and update variables like score or lives and refresh the UI.
  5. JSONObject features and capabilities

    develop

    The JSONObject class provides several specialized features for handling JSON in Unity/C#:

    • Performance: Optimized parse/stringify functions with minimal garbage creation. Includes an asynchronous stringify function for large datasets to prevent frame drops.
    • Parsing Control: MaxDepth parameter allows skipping nested data to save resources. Supports a strict mode to fail on non-compliant input (e.g., a raw string instead of an object/array).
    • Data Types: Supports Infinity and NaN. Can switch between double and float for numeric storage based on precision needs.
    • Special Types: Includes a Baked object type for storing stringified data within parsed objects.
    • Utilities: JSONTemplates provides serialization for common Unity types like Vector3 and Matrix4x4. ToString() supports a "pretty" flag for formatted output.
  6. Decode JSON strings into JSONObject

    develop

    To decode, pass a JSON-formatted string to the JSONObject constructor. The resulting object will contain the parsed data.

    If the root is an OBJECT, the data is stored in a public ArrayList called list, with corresponding keys stored in a keys list. If the root is an ARRAY, data is stored directly in list.

    Recursive Traversal Pattern: To process unknown JSON structures, use a recursive function that switches on the obj.type property (e.g., OBJECT, ARRAY, STRING, NUMBER, BOOL, NULL).

    string encodedString = "{\"field1\": 0.5,\"field2\": \"sampletext\",\"field3\": [1,2,3]}";
    JSONObject j = new JSONObject(encodedString);
    
    void accessData(JSONObject obj){
        switch(obj.type){
            case JSONObject.Type.OBJECT:
                for(int i = 0; i < obj.list.Count; i++){
                    string key = (string)obj.keys[i];
                    JSONObject child = (JSONObject)obj.list[i];
                    accessData(child);
                }
                break;
            case JSONObject.Type.ARRAY:
                foreach(JSONObject child in obj.list){
                    accessData(child);
                }
                break;
            case JSONObject.Type.STRING:
                Debug.Log(obj.str);
                break;
            case JSONObject.Type.NUMBER:
                Debug.Log(obj.n);
                break;
            case JSONObject.Type.BOOL:
                Debug.Log(obj.b);
                break;
            case JSONObject.Type.NULL:
                Debug.Log("NULL");
                break;
        }
    }
  7. Configure Amanita Fungus to use the Unity Input System

    develop

    To use the demos in the New InputSystem folder, you must configure your Unity project to support the new Input System package. Follow these steps:

    1. Install the Package: Add the new Input System package via the Unity Package Manager or by manually editing your manifest.json.
    2. Update Project Settings: In Project Settings -> Player, change the active Input System to the new one.
    3. Update Assembly Definitions: Open the Fungus assembly definition (.asmdef) and add Unity.InputSystem to its list of assembly references.

    Once these steps are completed, Unity should automatically set the ENABLE_INPUT_SYSTEM hash define in your project. This define triggers the use of new Input System logic within various Fungus systems, commands, and events.

  8. Implement physics-based movement and rotation in Fungus

    develop

    To implement movement and rotation for physics-driven objects in Fungus, use the following commands:

    • Movement: Use the AddForce2D command. For example, in the Football demo, input from GetAxis is combined and scaled into a vector which is then passed to AddForce2D.
    • Rotation: Use the AddTorque2D command. For example, in the Defender demo, an Input Axis is used as the input value for AddTorque2D to rotate a turret.
    • Transform Manipulation: Use the newer Transform and Vector3 related commands to manipulate object properties.
    // Conceptual usage based on Playground elements:
    // 1. Get Input
    // 2. Apply to Physics
    AddForce2D(inputVector)
    AddTorque2D(inputAxis)
  9. Use TextMeshPro with SayDialog and MenuDialog

    develop

    To use TextMeshPro (TMPro) instead of standard Unity UI Text in Amanita's dialog systems, replace the existing UI Text elements for story text, character text, and menu options with TextMeshPro Text UI elements.

    When using a SayDialog with TMPro, you must manually assign the following fields in the SayDialog component on the GameObject:

    • Name Text GO
    • Story Text GO

    This manual assignment is required because the TMPro components differ from the default prefab setup. This pattern can be applied to any custom SayDialog or menu implementations in your project.