File size: 1,448 Bytes
18a519f | 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 52 53 54 55 56 57 58 59 60 | using System.Collections.Generic;
using System.Collections.ObjectModel;
using UnityEngine;
namespace Unity.VisualScripting
{
public interface IMultiInputUnit : IUnit
{
int inputCount { get; set; }
ReadOnlyCollection<ValueInput> multiInputs { get; }
}
public abstract class MultiInputUnit<T> : Unit, IMultiInputUnit
{
[SerializeAs(nameof(inputCount))]
private int _inputCount = 2;
[DoNotSerialize]
protected virtual int minInputCount => 2;
[DoNotSerialize]
[Inspectable, UnitHeaderInspectable("Inputs")]
public virtual int inputCount
{
get
{
return _inputCount;
}
set
{
_inputCount = Mathf.Clamp(value, minInputCount, 10);
}
}
[DoNotSerialize]
public ReadOnlyCollection<ValueInput> multiInputs { get; protected set; }
protected override void Definition()
{
var _multiInputs = new List<ValueInput>();
multiInputs = _multiInputs.AsReadOnly();
for (var i = 0; i < inputCount; i++)
{
_multiInputs.Add(ValueInput<T>(i.ToString()));
}
}
protected void InputsAllowNull()
{
foreach (var input in multiInputs)
{
input.AllowsNull();
}
}
}
}
|