설명 없음
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MultiInputUnit.cs 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System.Collections.Generic;
  2. using System.Collections.ObjectModel;
  3. using UnityEngine;
  4. namespace Unity.VisualScripting
  5. {
  6. public interface IMultiInputUnit : IUnit
  7. {
  8. int inputCount { get; set; }
  9. ReadOnlyCollection<ValueInput> multiInputs { get; }
  10. }
  11. public abstract class MultiInputUnit<T> : Unit, IMultiInputUnit
  12. {
  13. [SerializeAs(nameof(inputCount))]
  14. private int _inputCount = 2;
  15. [DoNotSerialize]
  16. protected virtual int minInputCount => 2;
  17. [DoNotSerialize]
  18. [Inspectable, UnitHeaderInspectable("Inputs")]
  19. public virtual int inputCount
  20. {
  21. get
  22. {
  23. return _inputCount;
  24. }
  25. set
  26. {
  27. _inputCount = Mathf.Clamp(value, minInputCount, 10);
  28. }
  29. }
  30. [DoNotSerialize]
  31. public ReadOnlyCollection<ValueInput> multiInputs { get; protected set; }
  32. protected override void Definition()
  33. {
  34. var _multiInputs = new List<ValueInput>();
  35. multiInputs = _multiInputs.AsReadOnly();
  36. for (var i = 0; i < inputCount; i++)
  37. {
  38. _multiInputs.Add(ValueInput<T>(i.ToString()));
  39. }
  40. }
  41. protected void InputsAllowNull()
  42. {
  43. foreach (var input in multiInputs)
  44. {
  45. input.AllowsNull();
  46. }
  47. }
  48. }
  49. }