Variable

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 “EnemyInfo” in “Variable Name” and pressing “Create” button

EnemyInfoVariable.cs

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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>
{
}

EnemyInfoListVariable.cs

1
2
3
4
5
6
7
8
9
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Arbor;

[AddComponentMenu("")]
public class EnemyInfoListVariable : VariableList<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.
  • EnemyInfoListVariable
    VariableList 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.

1
2
3
4
5
6
7
[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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
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);
	}
}

AnyParameterReference

Use AnyParameterReference when referring directly to Parameter.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
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);
		}
	}
}