Skip to content

uzimaru0000/Veauty-GameObject

Repository files navigation

Veauty-GameObject

Runtime package that renders and updates Veauty virtual trees as Unity GameObjects.

Requirements

  • Unity 6000.5 or later (Unity 6)
  • com.uzimaru.veauty

Install

Add to Packages/manifest.json:

{
  "dependencies": {
    "com.uzimaru.veauty": "https://github.com/uzimaru0000/Veauty.git",
    "com.uzimaru.veauty-gameobject": "https://github.com/uzimaru0000/Veauty-GameObject.git"
  }
}

Usage

Mount a Veauty tree under a GameObject with VeautyObject.

using UnityEngine;
using Veauty;
using Veauty.GameObject;
using Veauty.GameObject.Attributes;
using Veauty.VTree;

public class Counter : MonoBehaviour
{
    private VeautyObject app;

    void Start()
    {
        this.app = new VeautyObject(this.gameObject, Render);
    }

    static IVTree Render()
    {
        var count = Hooks.UseState(0);
        return new Node<GameObject>(
            "Counter",
            new IAttribute<GameObject>[] {
                new Position(Vector3.zero, true)
            },
            CountLabel(count)
        );
    }

    [Component]
    static IVTree CountLabel(State<int> count)
    {
        var renderCount = Hooks.UseRef(0);
        renderCount.Current++;

        return new Node<GameObject>(
            $"Count-{count.Value}",
            new IAttribute<GameObject>[] {
                new Active(count.Value % 2 == 0)
            }
        );
    }
}

Methods marked with [Component] get their own hook scope and lifecycle — no manual FunctionComponents.Create() wrapping needed.

Node types

// Basic node
new Node<GameObject>("Name", attrs, children...)

// Typed node — adds a Unity component to the GameObject
new Node<GameObject, Rigidbody>("Body", attrs, children...)

// Keyed node — efficient list diffing
new KeyedNode<GameObject>("Items", attrs,
    ("player", playerNode),
    ("enemy",  enemyNode)
)

Built-in attributes

Attribute Effect Reset value on removal
Active(bool) Sets activeSelf true
Tag(string) Sets tag "Untagged"
Position(Vector3, isLocal) Sets position Vector3.zero
Rotation(Quaternion, isLocal) Sets rotation Quaternion.identity
Scale(Vector3) Sets local scale Vector3.one

Runtime behavior

  • VeautyObject rebuilds the virtual tree on state changes and applies only the diff to existing GameObjects.
  • Typed nodes add their component on render. When the component type changes, the old one is destroyed (MonoBehaviour components only) and a new one is added.
  • Keyed node moves reuse existing GameObjects.
  • If the mounter has a RectTransform, child nodes are also created with RectTransform (for uGUI interop).

Documentation

About

An implementation of a virtual object using Veauty for GameObjects.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages