World Builder – Extensions – Portals United https://www.portalsunited.com:443 Fri, 11 Apr 2025 11:16:39 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.2 https://www.portalsunited.com:443/wp-content/uploads/2024/10/cropped-pu-favicon-alt-32x32.png World Builder – Extensions – Portals United https://www.portalsunited.com:443 32 32 World Builder – How to extend the World Builder? https://www.portalsunited.com:443/docs/world-builder-how-to-extend-the-world-builder/ https://www.portalsunited.com:443/docs/world-builder-how-to-extend-the-world-builder/#respond Wed, 23 Oct 2024 11:06:55 +0000 https://www.portalsunited.com:443/?post_type=docs&p=144 There are 3 primary ways to extend the World Builder. Those are Templates, Wizards and Plugins.

Templates are projects that are used as a base for a new project.

Wizards are special plugins that provide a step by step walk-through for easy user guidance.

With plugins, the entire World Builder can be enhanced, e.g. new menus, tools.

]]>
https://www.portalsunited.com:443/docs/world-builder-how-to-extend-the-world-builder/feed/ 0
World Builder – What is a plugin? https://www.portalsunited.com:443/docs/world-builder-what-is-a-plugin/ https://www.portalsunited.com:443/docs/world-builder-what-is-a-plugin/#respond Wed, 23 Oct 2024 10:50:29 +0000 https://www.portalsunited.com:443/?post_type=docs&p=140 Plugins are a way to extend the capabilities of the World Builder. They are inside a dll file in the Plugins folder of the World Builder.

Depending of the type of the plugin, the plugin behaves differently. The most common ones you’ll be using are Wizards, Tools, AssetsProviders and Localizations. Wizards are for a step-by-step guide for the user through some setup or content creations. Tool plugins are for extending the World Builder in general. AssetsProviders are for importing additional assets from other sources, e.g. your asset database. Localization plugins add localizations for your plugin, so that UI elements can be translated in other languages.

]]>
https://www.portalsunited.com:443/docs/world-builder-what-is-a-plugin/feed/ 0
World Builder – How to create a plugin? https://www.portalsunited.com:443/docs/world-builder-how-to-create-a-plugin/ https://www.portalsunited.com:443/docs/world-builder-how-to-create-a-plugin/#respond Wed, 23 Oct 2024 10:38:11 +0000 https://www.portalsunited.com:443/?post_type=docs&p=142 Setup

For creating a plugin, you’ll need to create your own Dynamic Linked Library (DLL). It should be a C# .NET Framework library, with dependencies for Unity Engine and World Builder Plugin Core.

You’ll find the Unity Engine dlls in the sub folder of the World Builder installation path: “[INSTALL_PATH]\World Builder\World Builder_Data\Managed”
You’ll find a dll with the name “com.nuro.world-builder.plugin-core.dll”, this dll is the Plugin Core library for the World Builder. It includes all the interfaces and classes that you’ll need to integrate your plugin into the World Builder ecosystem.

After your setup for development is done, you can start with development. A World Builder Plugin always derives from PluginBase plus all the Plugin interfaces that you want to implement. One dll may contain multiple plugins.

Example

using System;
using UnityEngine.UIElements;
using Nuro.Processes;
using WorldBuilder.Plugins;

namespace MY_PLUGIN_NAMESPACE
{
    public class MyPlugin : PluginBase, IWizard, ILocalization
    {
        public override PluginFeatureFlags Features => PluginFeatureFlags.Wizard | PluginFeatureFlags.Localization;
	public virtual string LocalizationFolderName => "My Plugin Localization";

        public string WizardName => "My Plugin";

        public string WizardDescription => "This is my new cool plugin for the World Builder";

        public bool VisibleInWizardList => true;

        public Process CreateRunProcess(VisualElement root, Action onCancel = null)
        {
            return new Process("My Plugin Run Process", null);
        }
    }
}

As you can see, we’re implementing two plugin interfaces, 1st IWizard for a wizard plugin and 2nd ILocalization for custom localization support of a plugin.

Plugins folder

To integrate the plugin,, copy your dll-file into the sub folder of the World Builder: “[INSTALL_PATH]\World Builder\Plugins\External\[PLUGIN_NAME]\”
If you have localization csv-files, they should be in the LocalizationFolderName that you specified in the plugin. For the example above it would be: “[INSTALL_PATH]\World Builder\Plugins\External\MyPlugin\My Plugin Localization\”

Plugin types

Even though there are more types of plugins available under PluginFeatureFlags, the most common ones you’ll be using are Wizard, Tool, AssetsProvider and Localization.

]]>
https://www.portalsunited.com:443/docs/world-builder-how-to-create-a-plugin/feed/ 0
World Builder – What is a wizard? https://www.portalsunited.com:443/docs/world-builder-what-is-a-wizard/ https://www.portalsunited.com:443/docs/world-builder-what-is-a-wizard/#respond Wed, 23 Oct 2024 10:59:19 +0000 https://www.portalsunited.com:443/?post_type=docs&p=136 A wizard is a special plugin for the world builder. For more information’s about plugins in general, please look into the section here.

There are two ways to run a wizard.

1st, when a project is loaded. The Builder Project Settings has a section for WizardsToRunAtOpen. This can be edited and all wizards will be run in the order they are listed here when a project is loaded. If you want to run a wizard only once, you need to remove the name of your wizard from this list.

2nd, when a wizard is started via the wizards menu. If you enable a wizard to be listed in the wizard menu, the user can start the wizard whenever they want.

]]>
https://www.portalsunited.com:443/docs/world-builder-what-is-a-wizard/feed/ 0
World Builder – Demo Plugins https://www.portalsunited.com:443/docs/world-builder-demo-plugins/ https://www.portalsunited.com:443/docs/world-builder-demo-plugins/#respond Fri, 21 Feb 2025 11:38:13 +0000 https://www.portalsunited.com:443/?post_type=docs&p=735

Settings Menu Entry Demo Plugin

This World Builder demo plugin creates a custom menu entry in the settings menu of World Builder.

Download (last updated March 11, 2025)

How to test the plugin:
– Find world-builder-demo-plugin-menu-entry.dll (bin folder) and Localization Demo Menu Entry folder (under Resources )
– Copy both of them into the Plugins folder of your World Builder installation path (default is C:\Nuro\World Builder)

XR4ED Wizard Demo Plugin

This World Builder demo plugin creates a wizard that shows all purchased products from the XR4ED shop. If this plugin is active, a demo wizard will appear in the list of wizards in the world menu of World Builder.

Download (last updated March 11, 2025)

How to test the plugin:
– Find xr4ed-world-builder-demo-plugin-wizard.dll (bin folder)
– Copy it into the Plugins folder of your World Builder installation path (default is C:\Nuro\World Builder)

See also:

World Builder – How to extend the World Builder?
World Builder – What is a plugin?
World Builder – How to create a plugin?

]]>
https://www.portalsunited.com:443/docs/world-builder-demo-plugins/feed/ 0
World Builder – Reference Provider https://www.portalsunited.com:443/docs/world-builder-reference-provider/ https://www.portalsunited.com:443/docs/world-builder-reference-provider/#respond Mon, 11 Nov 2024 10:06:18 +0000 https://www.portalsunited.com:443/?post_type=docs&p=420 Overview

The IReferenceProvider interface is a central component in the WorldBuilder plugin system. It serves as a comprehensive provider for various systems, services, UI components, and tools that are necessary for extending the WorldBuilder-base application. This interface allows access to settings, localization, asset management, UI elements, and other core systems that are usefull.

The IReferenceProvider interface aggregates a range of essential functionalities including asset importing, project and location loading, UI management, and camera control, enabling other systems or plugins to interact with these resources efficiently.

Properties and Events

Events

  • OnProjectLoaded:
    Triggered when a project has been loaded into the system. This event provides the IProject instance representing the loaded project.
  • OnLocationLoaded:
    Triggered when a location (a scene or level) is loaded. This event provides the ILocation instance representing the loaded location.

General Properties

  • LoadProcessHooks:
    Provides hooks for the loading process, allowing custom actions or extensions to be triggered during project or location loading.
  • SaveProcessHooks:
    Provides hooks for the saving process, allowing custom actions or extensions during project or location saving.
  • BuilderSettings:
    Access to the BuilderSettings, which stores and manages user preferences, configuration settings, and builder-related configurations.
  • LocalizationSystem:
    Provides access to the ILocalizationSystem responsible for managing localization and language resources within the application.
  • GlobalParameters:
    Provides access to the IParameterSystem, which handles global parameters to allow accessing them in other plugins or as triggers in an event driven architecture.
  • PluginProvider:
    Provides access to the IPluginProvider, enabling interaction with installed plugins and their associated functionality.
  • AssetDatabase:
    Provides access to the IAssetDatabase, which manages the assets within the application, such as models, textures, and other resources.
  • AssetImporter:
    Provides access to the IAssetImporter, responsible for importing new assets into the project.
  • Project:
    The current project loaded into the system, represented by an IProject instance.
  • LoadedLocation:
    The currently loaded location (e.g., scene or level) represented by an ILocation instance.
  • HiddenVisualObjectsParent:
    A Transform that holds hidden visual objects in the scene, used for managing objects that should not be directly visible to the user.
  • MouseHandler:
    Access to the IMouseHandler, which handles mouse input and interactions within the World Builder.
  • WorldEditor:
    Provides access to the IWorldEditor, which is responsible for editing a location, such as translating, rotating an scaling of objects.
  • CommandMapper:
    Provides access to the ICommandMapper, a system that maps input commands to keyboard keys.
  • HopperReference:
    Provides access to the IHopperReference, it’s a reference provider for all Portal Hopper related functionality.
  • HopperParameters:
    A dictionary containing string key-value pairs representing parameters related to the Portal Hopper.
  • PlacingManager:
    Provides access to the IPlacingManager, responsible for managing the placement of objects within the world editor (e.g., placing buildings, characters, etc.).

UI Properties

  • ThemeLoader:
    Provides access to the IUIThemeLoader, responsible for loading and managing UI themes.
  • ElementFactory:
    Provides access to the IUIElementFactory, which is responsible for creating UI elements dynamically.
  • IconProvider:
    Provides access to the IIconProvider, responsible for getting access to included icons.
  • ProgressScreen:
    Provides access to the IUIProgressScreen, which displays a progress screen to the user during lengthy operations (e.g., loading, saving, or exporting).
  • UIAnimator:
    Provides access to the IUIAnimator, responsible for animating UI elements, such as transitions or visual effects.
  • PopupSystem:
    Provides access to the IPopupSystem, responsible for displaying popup dialogs and notifications to the user.
  • MainMenu:
    Provides access to the IMenu representing the main menu UI.
  • SettingsMenu:
    Provides access to the ISubMenu for the settings UI, where users can adjust configuration options.
  • WorldMenu:
    Provides access to the ISubMenu for the world-specific settings and options menu.
  • StartUIRoot:
    A VisualElement that represents the root UI element for the start screen, the initial UI visible to the user when the application launches.
  • HUD_UIRoot:
    A VisualElement that represents the root UI element for the world builder after a world is loaded.
  • ReferenceResolution:
    A Vector2Int defining the reference resolution used for UI layout, ensuring consistency across different screen sizes and aspect ratios.
  • ProjectsScreenController:
    Provides access to the IUIProjectsScreenController, responsible for managing the UI and interactions related to the projects screen.
  • CreateProjectScreenController:
    Provides access to the IUICreateProjectScreenController, responsible for managing the UI and interactions related to the project creation screen.
  • AssetManagerController:
    Provides access to the IUIAssetManagerController, which controls the asset management UI.
  • ExportPageController:
    Provides access to the IUIExportPageController, which controls the UI for exporting the project or world.
  • InspectorController:
    Provides access to the IUIInspectorController, which handles the inspector UI for viewing and editing properties of selected objects.
  • AssetDataProvider:
    Provides access to the IUIAssetDataProvider, which provides data related to assets for use within the UI (e.g., displaying asset properties).
  • CursorController:
    Provides access to the ICursorController, which manages the cursor behavior.
  • CameraController:
    Provides access to the ICameraController, which manages the camera’s movement and positioning in the location view.
  • LocationViewToolbar:
    Provides access to the ILocationViewToolbar, a UI toolbar specific to managing views of the current location (scene or level).

Usage Example

public class MyCustomPlugin : PluginBase
{
    // A method called when the plugin is initialized
    public override void CreateSetupProcess()
    {
        base.CreateSetupProcess();

        // Subscribe to project and location loading events
        ReferenceProvider.OnProjectLoaded += OnProjectLoaded;
        ReferenceProvider.OnLocationLoaded += OnLocationLoaded;
    }

    // Event handler for when a project is loaded
    private void OnProjectLoaded(IProject project)
    {
        Debug.Log($"Project Loaded: {project.Name}");
    }

    // Event handler for when a location is loaded
    private void OnLocationLoaded(ILocation location)
    {
        Debug.Log($"Location Loaded: {location.Name}");
    }
}

Conclusion

The IReferenceProvider interface centralizes key systems, tools, and services required to build and manage worlds within the WorldBuilder environment. It simplifies interaction with various subsystems and provides structured access to the underlying functionality needed for tasks like asset management, project and location handling, UI management, and more.

]]>
https://www.portalsunited.com:443/docs/world-builder-reference-provider/feed/ 0
World Builder – UIElementFactory https://www.portalsunited.com:443/docs/world-builder-uielementfactory/ https://www.portalsunited.com:443/docs/world-builder-uielementfactory/#respond Mon, 11 Nov 2024 10:13:52 +0000 https://www.portalsunited.com:443/?post_type=docs&p=424 The IUIElementFactory interface, provides methods for creating various types of UI elements in the WorldBuilder application using Unity’s UIElements system (UIToolkit). The interface includes methods to create a wide range of UI components such as buttons, labels, text fields, toggles, sliders, dropdowns, containers, scroll views, and windows. It also provides specialized methods for creating localized UI elements, handling paths, managing selections, and creating more complex structures like tables and menus. The factory methods support customization with different styles and event handlers, allowing for flexible UI creation. Additionally, the interface includes functionality for asset selection, color pickers, signal connectors, and tag management. This setup is intended to streamline and standardize the creation of UI elements within the WorldBuilder plugin ecosystem.

]]>
https://www.portalsunited.com:443/docs/world-builder-uielementfactory/feed/ 0
World Builder – Runtime Scripting Documentation https://www.portalsunited.com:443/docs/worldbuilder-runtime-scripting-documentation/ https://www.portalsunited.com:443/docs/worldbuilder-runtime-scripting-documentation/#respond Wed, 12 Mar 2025 15:39:18 +0000 https://www.portalsunited.com:443/?post_type=docs&p=894 Introduction to Runtime Scripting

WorldBuilder’s runtime scripting system enables the creation of custom interactive components directly within the application environment using C# programming language.

Technical Framework

The runtime scripting implementation in WorldBuilder utilizes C# and the Unity engine’s core functionality. Components are created following a structured inheritance pattern:

  1. Each component inherits from DataComponentBase
  2. Properties are serialized using Newtonsoft.Json’s [JsonProperty] attributes
  3. Components leverage Unity’s lifecycle methods (Start(), Update())
  4. Inspector views are created separately to manage the component’s visual editing interface

Component Structure

A runtime component consists of two primary files:

  1. Component Implementation File: Defines behavior using C# and Unity libraries
  2. Inspector View File: Provides the interface for modifying component properties

Component Implementation Example

public class MyHoverComponent: DataComponentBase
{
    [JsonProperty("Speed")]
    public float Speed = 1.0f;

    [JsonProperty("Height")]
    public float Height = 2.0f;

    private Vector3 m_InitialPosition;

    void Start()
    {
        m_InitialPosition = transform.position;
    }

    void Update()
    {
        float newY = Mathf.Sin(Time.time * Speed) * Height + m_InitialPosition.y;
        transform.position = new Vector3(transform.position.x, newY, transform.position.z);
    }

    public override List<string> GetAssetReferences() { return null; }
    public override void AfterDeserialization() { }
}

Inspector View Example

public class MyHoverComponentInspectorView : DataComponentInspectorViewBase
{
    public override Type TypeOfDataComponent { get => typeof(MyHoverComponent); }

    public override void CreateInspectorEntries(VisualElement window, IReferenceProvider referenceProvider, IUIElementFactory elementFactory, object instance)
    {
        var hoverComponent = instance as MyHoverComponent;
        elementFactory.CreateInspectorFloatField(window, "Speed", hoverComponent.Speed, (oldValue, newValue) =>
        {
            hoverComponent.Speed = newValue;
        });

        elementFactory.CreateInspectorFloatField(window, "Height", hoverComponent.Height, (oldValue, newValue) =>
        {
            hoverComponent.Height = newValue;
        });
    }
}

Automatic Inspector Generation

WorldBuilder provides automatic inspector view generation for common data types:

  • Integer Fields
  • Float Fields
  • String Fields

For components that want to expose more complex data types in the editor need to write a custom inspector view. Inheriting from DataComponentInspectorViewBase. In the examples you can find some basic custom inspector views.

Creating Custom Components: A Tutorial

Step 1: Define Component Behavior

Create a new C# script that inherits from DataComponentBase. Define serializable properties using [JsonProperty] attributes. Implement Unity’s lifecycle methods (Start(), Update()) to control behavior.

Step 2: Create Inspector View

Create a corresponding inspector view class that inherits from DataComponentInspectorViewBase. Implement the CreateInspectorEntries() method to generate UI controls for each property using the appropriate element factory methods.

Step 3: Access Unity Libraries

Utilize Unity’s classes and functions (e.g., Vector3, Transform, Mathf, Time) for movement, calculations, and object manipulation.

Step 4: Implement Required Methods

All components must implement GetAssetReferences() and AfterDeserialization() methods to conform to the DataComponentBase contract.

Component Types and Applications

WorldBuilder’s example components demonstrate various interaction patterns:

  • MyHoverComponent: Creates oscillating vertical movement using sine waves
  • MyInteractivePulseComponent: Adjusts object scale rhythmically
  • MyLookAtComponent: Orients objects toward specified targets
  • MyOrbitComponent: Creates circular movement around target objects

Advanced Techniques

Components can reference other scene objects by name:

[JsonProperty("TargetObjectName")]
public string TargetObjectName;

void Start()
{
    var target = GameObject.Find(TargetObjectName);
    if (target)
        m_TargetTransform = target.transform;
}

This allows for complex interactions between objects in educational scenarios.

]]>
https://www.portalsunited.com:443/docs/worldbuilder-runtime-scripting-documentation/feed/ 0
World Builder – Runtime Scripting Tutorials https://www.portalsunited.com:443/docs/worldbuilder-runtime-component-tutorials/ https://www.portalsunited.com:443/docs/worldbuilder-runtime-component-tutorials/#respond Thu, 13 Mar 2025 13:27:55 +0000 https://www.portalsunited.com:443/?post_type=docs&p=1247 1. MyHoverComponent Tutorial

The Hover Component creates a simple up-and-down floating motion – perfect for highlighting objects or creating ambient movement in educational scenes!

Purpose

This component makes objects float up and down using a sine wave function, creating a smooth, natural-looking hover effect.

Step-by-Step Tutorial

1. Create the Component Script

using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
using WorldBuilder.Core.Components;

namespace MyComponents
{
    public class MyHoverComponent: DataComponentBase
    {
        [JsonProperty("Speed")]
        public float Speed = 1.0f;

        [JsonProperty("Height")]
        public float Height = 2.0f;

        private Vector3 m_InitialPosition;

        void Start()
        {
            m_InitialPosition = transform.position;
        }

        void Update()
        {
            float newY = Mathf.Sin(Time.time * Speed) * Height + m_InitialPosition.y;
            transform.position = new Vector3(transform.position.x, newY, transform.position.z);
        }

        public override List<string> GetAssetReferences() { return null; }
        public override void AfterDeserialization() { }
    }
}

2. Create the Inspector View

using UnityEngine;
using UnityEngine.UIElements;
using WorldBuilder.UI;
using WorldBuilder.Plugins;
using WorldBuilder.Plugins.UI;
using System;
using WorldBuilder.Core.Components.Inspectors;

namespace MyComponents
{
    public class MyHoverComponentInspectorView : DataComponentInspectorViewBase
    {
        public override Type TypeOfDataComponent { get => typeof(MyHoverComponent); }

        public MyHoverComponentInspectorView(Texture2D icon) : base(icon) { }

        public override void CreateInspectorEntries(VisualElement window, IReferenceProvider referenceProvider, IUIElementFactory elementFactory, object instance)
        {
            var hoverComponent = instance as MyHoverComponent;

            elementFactory.CreateInspectorFloatField(window, "Speed", hoverComponent.Speed, (oldValue, newValue) =>
            {
                hoverComponent.Speed = newValue;
            });

            elementFactory.CreateInspectorFloatField(window, "Height", hoverComponent.Height, (oldValue, newValue) =>
            {
                hoverComponent.Height = newValue;
            });
        }
    }
}

3. How It Works

  1. Component Properties:

    • Speed: Controls how quickly the object moves up and down (oscillation frequency)
    • Height: Determines the maximum distance the object moves from its starting position
  2. The Math Behind It:

    • The sine function creates a smooth wave pattern between -1 and 1
    • Multiplying by Height scales the wave to the desired amplitude
    • Adding the initial Y position centers the wave around the object’s starting point
  3. Runtime Behavior:

    • Start(): Captures the initial position when the component is initialized
    • Update(): Recalculates the position every frame using the sine wave
    • Only the Y-axis changes; X and Z remain constant

4. Using the Component

  1. Add the component to any object you want to hover
  2. Adjust the Speed parameter to control how quickly it moves (lower = slower)
  3. Adjust the Height parameter to control how far it moves from its starting position

2. MyInteractivePulseComponent Tutorial

The Pulse Component creates a rhythmic scaling effect – perfect for drawing attention to objects or creating breathing-like animations!

Purpose

This component repeatedly scales an object up and down, creating a pulsing visual effect.

Step-by-Step Tutorial

1. Create the Component Script

using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
using WorldBuilder.Core.Components;

namespace MyComponents
{
    public class MyInteractivePulseComponent : DataComponentBase
    {
        [JsonProperty("PulseSpeed")]
        public float PulseSpeed = 2.0f;

        [JsonProperty("PulseScale")]
        public float PulseScale = 1.5f;

        private Vector3 m_OriginalScale;

        void Start()
        {
            m_OriginalScale = transform.localScale;
        }

        void Update()
        {
            float scale = Mathf.Abs(Mathf.Sin(Time.time * PulseSpeed)) * PulseScale;
            transform.localScale = m_OriginalScale * (1 + scale);
        }

        public override List<string> GetAssetReferences() => null;
        public override void AfterDeserialization() { }
    }
}

2. Create the Inspector View

using UnityEngine;
using UnityEngine.UIElements;
using WorldBuilder.UI;
using WorldBuilder.Plugins;
using WorldBuilder.Plugins.UI;
using System;
using WorldBuilder.Core.Components.Inspectors;

namespace MyComponents
{
    public class MyInteractivePulseInspectorView : DataComponentInspectorViewBase
    {
        public override Type TypeOfDataComponent => typeof(MyInteractivePulseComponent);

        public MyInteractivePulseInspectorView(Texture2D icon) : base(icon) { }

        public override void CreateInspectorEntries(VisualElement window, IReferenceProvider referenceProvider, IUIElementFactory elementFactory, object instance)
        {
            var pulseComponent = instance as MyInteractivePulseComponent;

            elementFactory.CreateInspectorFloatField(window, "Pulse Speed", pulseComponent.PulseSpeed, (oldValue, newValue) =>
            {
                pulseComponent.PulseSpeed = newValue;
            }, "Hz");

            elementFactory.CreateInspectorFloatField(window, "Pulse Scale", pulseComponent.PulseScale, (oldValue, newValue) =>
            {
                pulseComponent.PulseScale = newValue;
            }, "x");
        }
    }
}

3. How It Works

  1. Component Properties:

    • PulseSpeed: Controls how quickly the object pulses (in cycles per second)
    • PulseScale: Determines how much the object’s size changes during pulsing
  2. The Math Behind It:

    • Uses a sine wave like the Hover component, but takes the absolute value
    • This creates a “bouncing” effect between 0 and 1 instead of -1 and 1
    • Multiplies by PulseScale to determine maximum size increase
    • Adds 1 to maintain the original size as the minimum
  3. Runtime Behavior:

    • Start(): Captures the initial scale when the component is initialized
    • Update(): Recalculates the scale every frame using the sine wave
    • All axes scale uniformly (the object grows/shrinks in all dimensions)

4. Using the Component

  1. Add the component to any object you want to pulse
  2. Adjust the PulseSpeed parameter (higher values make it pulse faster)
  3. Adjust the PulseScale parameter (higher values make it grow larger)

3. MyLookAtComponent Tutorial

The LookAt Component makes objects track and face a target – perfect for creating attention-directing elements in educational scenes!

Purpose

This component makes an object continuously rotate to face another specified object in the scene.

Step-by-Step Tutorial

1. Create the Component Script

using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
using WorldBuilder.Core.Components;

namespace MyComponents
{
    public class MyLookAtComponent : DataComponentBase
    {
        [JsonProperty("TargetObjectName")]
        public string TargetObjectName;

        private Transform m_TargetTransform;

        void Start()
        {
            var target = GameObject.Find(TargetObjectName);
            if (target)
                m_TargetTransform = target.transform;
        }

        void Update()
        {
            if (m_TargetTransform)
                transform.LookAt(m_TargetTransform);
        }

        public override List<string> GetAssetReferences() => null;
        public override void AfterDeserialization() { }
    }
}

2. Creating the Inspector View

For this component, we could create an inspector view similar to the others. Here’s how it might look:

using UnityEngine;
using UnityEngine.UIElements;
using WorldBuilder.UI;
using WorldBuilder.Plugins;
using WorldBuilder.Plugins.UI;
using System;
using WorldBuilder.Core.Components.Inspectors;

namespace MyComponents
{
    public class MyLookAtComponentInspectorView : DataComponentInspectorViewBase
    {
        public override Type TypeOfDataComponent => typeof(MyLookAtComponent);

        public MyLookAtComponentInspectorView(Texture2D icon) : base(icon) { }

        public override void CreateInspectorEntries(VisualElement window, IReferenceProvider referenceProvider, IUIElementFactory elementFactory, object instance)
        {
            var lookAtComponent = instance as MyLookAtComponent;

            elementFactory.CreateInspectorTextField(window, "Target Object", lookAtComponent.TargetObjectName, (oldValue, newValue) =>
            {
                lookAtComponent.TargetObjectName = newValue;
            });
        }
    }
}

3. How It Works

  1. Component Properties:

    • TargetObjectName: The name of the object this component should face toward
  2. Implementation Details:

    • Uses Unity’s built-in LookAt() method, which rotates an object to face a target
    • Finds the target by name at startup using GameObject.Find()
    • Caches the target’s transform for efficiency
    • Only rotates if a valid target is found
  3. Runtime Behavior:

    • Start(): Finds the target object by name and caches its transform
    • Update(): Continuously updates rotation to face the target every frame

4. Using the Component

  1. Add the component to any object that should face another object
  2. Set the TargetObjectName to match the exact name of the target object
  3. The object will now always rotate to face the target

4. MyOrbitComponent Tutorial

The Orbit Component creates circular movement around a target – perfect for simulating planetary motion or creating dynamic, circling elements!

Purpose

This component makes an object orbit around another specified object (or its initial position if no target is found).

Step-by-Step Tutorial

1. Create the Component Script

using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
using WorldBuilder.Core.Components;

namespace MyComponents
{
    public class MyOrbitComponent : DataComponentBase
    {
        [JsonProperty("OrbitSpeed")]
        public float OrbitSpeed = 6.0f;

        [JsonProperty("OrbitRadius")]
        public float OrbitRadius = 10.0f;

        [JsonProperty("TargetObjectName")]
        public string TargetObjectName;

        private Transform m_TargetTransform;
        private Vector3 m_CenterPoint;

        void Start()
        {
            var target = GameObject.Find(TargetObjectName);
            if (target)
                m_TargetTransform = target.transform;
            else
                m_CenterPoint = transform.position;
        }

        void Update()
        {
            Vector3 center = m_TargetTransform ? m_TargetTransform.position : m_CenterPoint;
            transform.position = center + new Vector3(
                Mathf.Cos(Time.time * OrbitSpeed) * OrbitRadius, 
                transform.position.y, 
                Mathf.Sin(Time.time * OrbitSpeed) * OrbitRadius
            );
        }

        public override List<string> GetAssetReferences() => null;
        public override void AfterDeserialization() { }
    }
}

2. Create the Inspector View

using UnityEngine;
using UnityEngine.UIElements;
using WorldBuilder.UI;
using WorldBuilder.Plugins;
using WorldBuilder.Plugins.UI;
using System;
using WorldBuilder.Core.Components.Inspectors;

namespace MyComponents
{
    public class MyOrbitComponentInspectorView : DataComponentInspectorViewBase
    {
        public override Type TypeOfDataComponent => typeof(MyOrbitComponent);

        public MyOrbitComponentInspectorView(Texture2D icon) : base(icon) {}

        public override void CreateInspectorEntries(VisualElement window, IReferenceProvider referenceProvider, IUIElementFactory elementFactory, object instance)
        {
            var orbitComponent = instance as MyOrbitComponent;

            elementFactory.CreateInspectorFloatField(window, "Orbit Speed", orbitComponent.OrbitSpeed, (oldValue, newValue) =>
            {
                orbitComponent.OrbitSpeed = newValue;
            }, "°/s", tooltip: "Speed at which object orbits around center");

            elementFactory.CreateInspectorFloatField(window, "Orbit Radius", orbitComponent.OrbitRadius, (oldValue, newValue) =>
            {
                orbitComponent.OrbitRadius = newValue;
            }, "m");

            elementFactory.CreateInspectorTextField(window, "Target Object", orbitComponent.TargetObjectName, (oldValue, newValue) =>
            {
                orbitComponent.TargetObjectName = newValue;
            });
        }
    }
}

3. How It Works

  1. Component Properties:

    • OrbitSpeed: Controls how quickly the object moves around its target (angular velocity)
    • OrbitRadius: Determines the distance from the center point
    • TargetObjectName: The name of the object to orbit around
  2. The Math Behind It:

    • Uses sine and cosine functions to create circular motion
    • Cosine controls X position, Sine controls Z position
    • Multiplying by OrbitRadius sets the circle size
    • Multiplying by Time.time * OrbitSpeed creates continuous movement
  3. Runtime Behavior:

    • Start(): Finds the target object or defaults to orbiting the initial position
    • Update(): Recalculates position every frame to create circular movement
    • Maintains the original Y position (orbits in the XZ plane)

4. Using the Component

  1. Add the component to any object that should orbit
  2. Set the TargetObjectName to the name of the center object (or leave empty to orbit initial position)
  3. Adjust OrbitSpeed to control how quickly it circles (higher = faster)
  4. Adjust OrbitRadius to control how far from the center it orbits
]]>
https://www.portalsunited.com:443/docs/worldbuilder-runtime-component-tutorials/feed/ 0
World Builder – Runtime Scripting Assemblies https://www.portalsunited.com:443/docs/world-builder-runtime-scripting-assemblies/ https://www.portalsunited.com:443/docs/world-builder-runtime-scripting-assemblies/#respond Fri, 11 Apr 2025 11:16:38 +0000 https://www.portalsunited.com:443/?post_type=docs&p=1452 Available Assemblies:

System

UnityEngine

UnityEngine.CoreModule

UnityEngine.PhysicsModule

UnityEngine.UI

UnityEngine.UIElementsModule

Newtonsoft.Json

netstandard

mscorlib

1. System

Overview:
This is the core assembly of the .NET framework. It provides the fundamental classes and base types needed by nearly every application.

Key Components:

  • Namespaces: System, System.Collections, System.IO, System.Threading, etc.
  • Common Types: Object, String, DateTime, collections like List<T> and Dictionary<TKey, TValue>, exception handling classes, and more.

Use Cases:

  • Basic data types and runtime support.
  • File and stream manipulation.
  • General-purpose utilities.

2. System.Core

Overview:
This assembly enriches your applications with LINQ (Language Integrated Query) capabilities and additional core functionalities such as extension methods, lambda expressions, and more.

Key Components:

  • Namespaces: System.Linq, System.Linq.Expressions
  • Common Types: LINQ extension methods provided in Enumerable and Queryable.

Use Cases:

  • Querying and manipulating collections in a fluent, readable style.
  • Enhancing readability and expressiveness of your code with Lambda Expressions.

3. UnityEngine

Overview:
This assembly is at the heart of Unity scripting. It provides all the base classes and functions needed to build interactive content on Unity.

Key Components:

  • Namespaces: UnityEngine
  • Common Types: GameObject, Component, MonoBehaviour, Transform, etc.

Use Cases:

  • Creating and managing game objects.
  • Implementing behaviors in the Unity runtime.
  • Accessing Unity-specific utilities such as logging and physics interactions (basic).

4. UnityEngine.CoreModule

Overview:
A more specific set of core functionalities provided by Unity. Many foundational parts of the UnityEngine are segmented into this module for better modularization.

Key Components:

  • Namespaces: Still under the umbrella of UnityEngine
  • Common Types: Essential classes and interfaces that support the Unity engine’s core operations.

Use Cases:

  • Handling core engine functionalities.
  • Directly interacting with the underlying systems of Unity.

5. UnityEngine.PhysicsModule

Overview:
This module specifically deals with Unity’s physics engine. It contains the components required for simulating physical behaviors.

Key Components:

  • Namespaces: UnityEngine
  • Common Types: Rigidbody, Collider, Physics, and other physics-related components.

Use Cases:

  • Adding realistic physics to your objects.
  • Handling collision detection and response.
  • Simulating environments like gravity, forces, and friction.

6. UnityEngine.UI

Overview:
This assembly brings in the classic Unity UI system. It allows you to build and manage interfaces using built-in UI components.

Key Components:

  • Namespaces: UnityEngine.UI
  • Common Types: Canvas, Button, Text, Image, etc.

Use Cases:

  • Designing interactive user interfaces.
  • Implementing menus, HUDs, and other UI elements.
  • Responding to user inputs through UI controls.

7. UnityEngine.UIElementsModule

Overview:
A newer, more flexible UI toolkit provided by Unity that offers a modern approach to UI development. It is designed to work with a hierarchical, style-driven system.

Key Components:

  • Namespaces: UnityEngine.UIElements
  • Common Types: VisualElement, StyleSheet, UIDocument, etc.

Use Cases:

  • Creating editor extensions or runtime UIs with modern styling.
  • Building dynamic, interactive UI using style sheets and hierarchical layouts.
  • Enjoying a more web-like approach to UI development within Unity.

8. Newtonsoft.Json

Overview:
This popular third-party assembly is your go-to for JSON parsing and serialization. It simplifies working with JSON data significantly.

Key Components:

  • Namespaces: Newtonsoft.Json
  • Common Types: JsonConvert, JsonSerializer, and various attribute classes for customization.

Use Cases:

  • Serializing objects to JSON strings.
  • Deserializing JSON data back into .NET objects.
  • Handling complex JSON structures with ease and flexibility.

9. netstandard

Overview:
netstandard represents a specification of .NET APIs that are available across all .NET implementations. It ensures uniformity and compatibility.

Key Components:

  • Namespaces: Provides foundational APIs common across different .NET platforms.
  • Common Types: Includes various core libraries and utilities that are standardized for cross-platform compatibility.

Use Cases:

  • Writing cross-platform libraries.
  • Ensuring compatibility across multiple .NET implementations (such as .NET Core, .NET Framework, Xamarin, etc.).

10. mscorlib

Overview:
Historically the core library for .NET applications, mscorlib contains essential types and base classes for the .NET framework.

Key Components:

  • Namespaces: System, along with many other central namespaces.
  • Common Types: System.Object, System.String, basic collection types, and more.

Use Cases:

  • It underpins much of the functionality you rely on in .NET.
  • Provides critical runtime support and base types used by most applications.

]]>
https://www.portalsunited.com:443/docs/world-builder-runtime-scripting-assemblies/feed/ 0