Hide
ArraySize

A decorator that limit the size of the array or list.

Note: Because of the limitation of PropertyDrawer:

  1. Delete an element will first be deleted, then the array will duplicate the last element.
  2. UI Toolkit: you might see the UI flicked when you remove an element.

Enable SaintsEditor if possible, otherwise:

  1. When the field is 0 length, it'll not be filled to target size.
  2. You can always change it to 0 size.

If you have SaintsEditor enabled, recommend to use it together with ListDrawerSettings, the + & - will be enabled/disabled accordingly.

Parameters:

  • int size the size of the array or list
  • int min min value of the size
  • int max max value of the size
  • string groupBy = "" for error message grouping

Parameters overload:

  • string callback: a callback or property for the size.

    If the value is an integer, the size is fixed to this value.

    If the value is a (int, int) tuple, a Vector2/Vector2Int, the size will be limited to the range. If any value in the range is < 0, then the side is not limited. For example, (1, -1) means the size is at least 1. (-1, 20) means the max size is 20.

    If the value is a Vector3/Vector3Int, then the x, y value will be used as the limit

    If the min >= 0 and the max < min, the max value will be ignored

  • string groupBy = "" for error message grouping

  • Allow Multiple: Yes

For example:

  • [ArraySize(3)] will make the array size fixed to 3
  • [ArraySize(1, 5)] will make the array size range to 1-5 (both included)
  • [ArraySize(min: 1)] will make the array size at least 1 (no max value specific). Useful to require a non-empty array.
using SaintsField; [ArraySize(3)] public string[] myArr;

image

using SaintsField; using SaintsField.Playa; [MinValue(1), Range(1, 10)] public int intValue; [ArraySize(nameof(intValue)), ListDrawerSettings] public string[] dynamic1; [Space] public Vector2Int v2Value; [ArraySize(nameof(v2Value)), ListDrawerSettings] public string[] dynamic2;