Variables#
Variables / Variables
Can Read
Can Write
Description#
The collection of Game Objects of a Variable or Local Variable
Code#
using System;
using System.Collections.Generic;
using UnityEngine;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Get, Set]
[Title("Variables")]
[Category("Variables/Variables")]
[Description("The collection of Game Objects of a Variable or Local Variable")]
[Image(typeof(IconVariable), ColorTheme.Type.TextLight, typeof(BadgeVariable))]
[Keywords("Variable", "Local", "Global")]
[Serializable]
public class TypeCollectionGameObjectsVariables : TypeCollectionGameObjects
{
[SerializeField] private GetVariable m_Variable;
public TypeCollectionGameObjectsVariables()
{
this.m_Variable = new GetVariable();
}
public TypeCollectionGameObjectsVariables(LocalVariable localVariable)
{
this.m_Variable = new GetVariable(localVariable);
}
public TypeCollectionGameObjectsVariables(GlobalVariable variable)
{
this.m_Variable = new GetVariable(variable);
}
public override void Get(Args args, List<GameObject> values)
{
values.Clear();
Variable variable = this.m_Variable.Get(args);
if (variable == null) return;
int count = variable.Count;
for (int i = 0; i < count; ++i)
{
values.Add(variable.Get<GameObject>(i));
}
}
public override void Set(List<GameObject> values, Args args)
{
Variable variable = this.m_Variable.Get(args);
if (variable == null) return;
variable.Clear();
for (int i = 0; i < values.Count; i++)
{
GameObject value = values[i];
variable.Insert(i, value);
}
}
public override string ToString()
{
return this.m_Variable.ToString();
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
}
}