Customizing parameters with Variable


This is the documentation for Arbor 3.2.4 and earlier.

See Arbor Documentation for the latest documentation.

This section explains how to register your own parameters in ParameterContainer.

Creating a Variable script file

Generate script with Variable Generator

Create a script for your own parameters.

  • Select “Create > Arbor > Variable C# Script” from the Project window right-click menu.
  • Enter the parameter class name in the “Variable Name” field of the Variale Generator window
    Create a script by pressing “Create” button.

    • If it is a name that can not be used, an error box will be displayed, so please correct the Variable Name.
    • When the OpenEditor check box is checked, the script editor opens after pressing the “Create” button.

Example of creation

Script example created by entering “EnableInfo” in “Variable Name” and pressing “Create” button

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Arbor;

[System.Serializable]
public class EnemyInfo
{
	// Declare Serialize Fields
}

[System.Serializable]
public class FlexibleEnemyInfo : FlexibleField<EnemyInfo>
{
	public FlexibleEnemyInfo(EnemyInfo value) : base(value)
	{
	}

	public FlexibleEnemyInfo(AnyParameterReference parameter) : base(parameter)
	{
	}

	public FlexibleEnemyInfo(InputSlotAny slot) : base(slot)
	{
	}

	public static explicit operator EnemyInfo(FlexibleEnemyInfo flexible)
	{
		return flexible.value;
	}

	public static explicit operator FlexibleEnemyInfo(EnemyInfo value)
	{
		return new FlexibleEnemyInfo(value);
	}
}

[System.Serializable]
public class InputSlotEnemyInfo : InputSlot<EnemyInfo>
{
}

[System.Serializable]
public class OutputSlotEnemyInfo : OutputSlot<EnemyInfo>
{
}

[AddComponentMenu("")]
public class EnemyInfoVariable : Variable<EnemyInfo>
{
}

Commentary

  • EnemyInfo
    A class of parameters to make by yourself.
    By adding a field for serialization, you can set your own parameters with ParameterContainer.
  • FlexibleEnemyInfo
    Class for making it possible to refer to by switching between Constant, Parameter, and Calculator.
  • InputSlotEnemyInfo
    Class for the input slot of EnemyInfo.
  • OutputSlotEnemyInfo
    Class for EnemyInfo output slot.
  • EnemyInfoVariable
    Variable class to register to ParameterContainer.
    The class name and the script file name must match.

Add field

Add a field to the generated script.

As an example, let’s add some fields to EnemyInfo.

[System.Serializable]
public class EnemyInfo
{
	// Declare Serialize Fields
	public string displayName;
	public Sprite icon;
}

Addition to ParameterContainer

Add the created Variable to ParameterContainer.

  • Please create ParameterContainer in advance.
  • Press the “+” button and select “Variable> Created Variable Name”.
  • Parameters are added

Reference to Variable parameter

FlexibleField

You can refer to it by giving StateBehaviour etc a class of Flexible + Variable Name defined in the generated script file.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Arbor;

[AddComponentMenu("")]
public class EnemyInfoBehaviour : StateBehaviour {

	public FlexibleEnemyInfo enemyInfo;

	// Use this for enter state
	public override void OnStateBegin()
	{
		EnemyInfo value = enemyInfo.value;
		Debug.Log(value.displayName);
	}
}
GIF

AnyParameterReference

Use AnyParameterReference when referring directly to Parameter.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Arbor;

[AddComponentMenu("")]
public class EnemyInfoBehaviour2 : StateBehaviour {

	[ClassExtends(typeof(EnemyInfo))]
	public AnyParameterReference enemyInfo = new AnyParameterReference();

	// Use this for enter state
	public override void OnStateBegin()
	{
		Parameter enemyInfoParameter = enemyInfo.parameter;
		if (enemyInfoParameter != null)
		{
			EnemyInfo value = enemyInfoParameter.value as EnemyInfo;
			Debug.Log(value.displayName);
		}
	}
}