[Array]

Attribute used for drawing flexible arrays.

Support Types

Type
Example
Description

T[]

string[]

Default C# array

List<T>

List<string>

Collection generic List

!!! info "Info" Where T is type of array elements.

Parameters

Parameter Name
Arguments
Description

OnGUI

void OnElementGUI(Rect position, SerializedProperty property, GUIContent label)

Override array element GUI.

GetHeight

float GetElementHeight(SerializedProperty array, int index)

Override array element height.

GetLabel

GUIContent GetElementLabel(SerializedProperty array, int index)

Override array element label.

OnAdd

void OnAdd(SerializedProperty array, int index)

Callback on add new element. Called after adding new element.

OnRemove

void OnRemove(SerializedProperty array, int index)

Callback on remove selected element. Called before removing selected element.

OnReorder

void OnReorder(SerializedProperty array)

Callback on reorder array list. Called after list has been reordered.

NoneElementText

string

Override none element text content.

HideFoldoutWhenEmpty

bool

When true and the array is empty, the foldout header arrow and label are hidden. The header container and add button remain visible.

ShowCount

bool

When true, the count of the array is shown in the header.

Examples

using System.Collections.Generic;
using UnityEngine;
using RenownedGames.Apex;

public class ArrayExample : MonoBehaviour
{
    [Array]
    public int[] simpleArray;

    [Array(OnAdd = "OnAddCallback", OnRemove = "OnRemoveCallback")]
    public List<string> callbackList;

    [Array(NoneElementText = "No elements in list")]
    public float[] customTextArray;

    private void OnAddCallback(SerializedProperty array, int index)
    {
        Debug.Log($"Added element at index {index}");
    }

    private void OnRemoveCallback(SerializedProperty array, int index)
    {
        Debug.Log($"Removing element at index {index}");
    }
}

Last updated