Skip to content

Components

Adding components

There are 2 ways to add components to your scene.

Right click in the hierarchy

In Hierarhcy

On a exising GameObject

In Inspector

Standard Component types

Most components can only be bind to a single type. Toggle components can only be bind to a Boolean for eaxample. Ìmage, Text and Generic components can be bind to different types. These compononts have a Type parameter where you first select the type you want to bind to.

All components have a Bind parameter. This makes it easy to Bind the content of the component to a EasyBind Store propery.

Available using Legacy or Text Mesh Pro.

Dropdown

  • Binds To: DropDown properies

Image

Image

  • Binds To: DropDown properies or Sprite properties

INFO

When binded to a DropDown property, the image shown will be the image of the current selected option.

Input Field

Available using Legacy or Text Mesh Pro.

Input

  • Binds To: String properties

Slider

Slider

  • Binds To: Float properties

Text

Available using Legacy or Text Mesh Pro.

Text

  • Binds To: Int, Float, Bool, String and DropDown properies

INFO

When binded to a DropDown property, the text shown will be the text of the current selected option.

Toggle

Toggle

  • Binds To: Bool properties

Generic Component

The Generic Component is a unique and powerful feature that enables monitoring and responding to any change in the store through Unity events.

By specifying the Type, you can attach a custom event listener to a Generic Component, which dynamically adapts based on the selected type. For example:

  • String Type Binding: When binding to a string type, the Generic Component offers the capability to bind a listener that expects a string parameter. This ensures that your event listeners are always compatible with the data they're intended to react to, enhancing the interactivity and responsiveness of your application.

This component is particularly useful for developers looking to implement complex UI behaviors and data-driven interactions within their Unity projects.

Generic

  • Binds To: All

Example event listener

First create a field in the EasyBind Store named DemoString of type string, please refer to the detailed instructions provided in the EasyBind documentation. You can find the specific steps under the section "Creating Properties" at the following link:

EasyBind Documentation - Creating Properties

To dynamically update a string property across your Unity project using the Generic component, follow these steps:

  1. Bind the Generic Component: Set it to the string type and specifically target DemoString.

  2. Script Implementation: Add the following script to a GameObject in your scene. This script will listen for changes and update its currentValue accordingly:

    csharp
    using UnityEngine;
    
    public class DemoListener : MonoBehaviour
    {
        public string currentValue;
    
        public void OnChange(string capturedValue)
        {
            currentValue = capturedValue;
        }
    }
  3. Binding the Listener: In the Generic component, locate the "On String Change" event. Add a new listener by clicking the "+" icon. Drag and drop the GameObject (which contains the DemoListener script) into the Object field of the new event listener. Select the OnChange method from the list of available functions.

By following these instructions, whenever DemoString changes anywhere in your project, the currentValue in the DemoListener script will automatically update to reflect this change. This setup ensures that your application can dynamically respond to data changes, keeping your UI and game logic synchronized with your data store.

Listening to Object and ObjectList changes

When you're utilizing the EasyBind Store to listen to changes on properties of the types Object or ObjectList, and these properties have a custom class or type assigned to them, it's necessary to perform type conversion. This conversion is from the generic object type to your specifically defined custom type. This step ensures that you can access and manipulate the properties of your custom object safely and effectively within your event listeners or data bindings.

Here’s a simple example to illustrate how to achieve this conversion in C#:

C#
public void OnObjectChange(object value)
{
    if(value is YourCustomType customObject)
    {
        // Now 'customObject' is of 'YourCustomType' and you can access its properties and methods.
    }
}