Descripción

Los Arrays (arreglos) le permiten a usted almacenar varios objetos en una sola variable.

La clase Array solo está disponible en Javascript.

Aquí hay un ejemplo básico de lo que puede hacer con la clase array:

There are two types of arrays in Unity, builtin arrays and normal Javascript Arrays. Builtin arrays (native .NET arrays), are extremely fast and efficient but they can not be resized.

Estos son tipados estáticamente lo que le permite a usted editarlos en el inspector. Aquí hay un ejemplo básico de cómo puede utilizar los arreglos integrados:

// example c# script showing how
// an array can be implemented.
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { // Exposes an float array in the inspector, which you can edit there. public float[] values; void Start() { foreach (float value in values) { print(value); }

// Since we can't resize builtin arrays // we have to recreate the array to resize it values = new float[10];

// assign the second element values[1] = 5.0F; } }

Los arrays integrados son útiles en el código de rendimiento crítico (Con el javascript de Unity y los arreglos integrado fácilmente podría procesar 2 millones de vértices usando mesh interface en un segundo).

Normal Javascript Arrays on the other hand can be resized, sorted and can do all other operations you would expect from an array class. Javascript Arrays do not show up in the inspector. Note: You can easily convert between Javascript Arrays and builtin arrays.

Note that Array functions are upper case following Unity's naming convention. As a convenience for javascript users, Unity also accepts lower case functions for the array class.

Nota: Unity no soporta la serialización de una lista de Listas, ni un Array (arreglo) de Arrays (arreglos).

Variables

lengthThe length property that returns or sets the number of elements in the Array.

Constructores

ArrayCrea un Array de tamaño fijo.

Funciones Públicas

AddAgrega value al final del array.
ClearVacía el array. El tamaño del array será cero (0).
ConcatConcat une dos o más Arrays.
JoinUne el contenido de un Array en un String.
PopElimina el último elemento del array, y lo devuelve.
PushAgrega value al final del array.
RemoveAtElimina del Array el elemento en la posición index.
ShiftElimina el primer elemento del Array y lo devuelve.
SortOrdena todos los elementos del Array.
UnshiftUnshift agrega uno o más elementos al principio de un arreglo y devuelve la nueva longitud del arreglo.