һ
 עʺ

ɨһɨ΢

array 数组_yzc88޳游戏脚本制作教程-游戏蛮牛出品 ...

2014-12-31 12:11| : | 鿴: 1864| : 0|ԭ: ţ|: yzc88޳ǽűmanual

ժҪ: array数组arrays allow you to store multiple objects in a single variable.the array class is only only available in javascript. for more information about arraylists, dictionaries or hashtables in c# ...

array数组

arrays allow you to store multiple objects in a single variable.

the array class is only only available in javascript. for more information about arraylists, dictionaries or hashtables in c# or javascript seehere.

数组允许你在一个变量中储存多个对象?/p>

这个 数组类仅仅用于Javascript。更多用于C#或Javascript关于arraylists,字典或哈希表,?a href="http://msdn2.microsoft.com/en-us/library/system.collections.arraylist_members(vs.80).aspx">这里?/p>

这里是一个你能用数组类做什么的基本的例子?/p>

c#

javascript

array不能用于c#.

function start () {

var arr = new array ();

// 添加一个元?/span>

arr.push ("hello");

// 打印第一个元?hello"

print(arr[0]);

// 调整数组大小

arr.length = 2;

// ?"world" 赋给第二个元?/span>

arr[1] = "world";

// 遍历这个数组

for (var value : string in arr) {

print(value);

}

}

there are two types of arrays in unity, builtin arrays and normal javascript arrays.

unity 有两种类型的数组,内置数组和标准的Javascript数组?/p>

builtin arrays (native .net arrays), are extremely fast and efficient but they can not be resized.

内置的数?(原始?net 数组), 是非常快速和有效? 但是他们不能被调整大小?/p>

they are statically typed which allows them to be edited in the inspector. here is a basic example of how you can use builtin arrays.

它们是静态类型的, 这允许他们在检视面板中被编辑?

这里是一个如何使用内置数组的基本例子

c#

javascript

array不能用于c#.

// 在检视面板中暴露一个浮点数组,你可以在那里编辑?/span>

var values : float[];

function start () {

// 遍历数组

for (var value in values) {

print(value);

}

// 由于我们不能调整内置数组的大? 我们必须重新创建一个数组来调整其大?/span>

values = new float[10];

// 给第二个元素赋?/span>

values[1] = 5.0;

}

builtin arrays are useful in performance critical code (with unity's javascript and builtin arrays you could easily process 2 million vertices using the mesh interface in one second.)

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.you can easily convert between javascript arrays and builtin arrays.

内置数组在性能相关代码中是非常有用?(使用unity javascript 数组和内置数组可以很容易使用mesh interface在一秒内处理200万个顶点)?/p>

另一方面,标准Javascript数组可以调整大小、排序,并可以做所有你期望的数组类的操作,javascript数组不显示在检视面板。你能很容易的在javascript数组和内置数组之间转换?/p>

c#

javascript

array不能用于c#.

function start () {

var array = new array (vector3(0, 0, 1));

array.push(vector3(0, 0, 2));

array.push(vector3(0, 0, 3));

// 复制js数组到内置数?/span>

var builtinarray :vector3[] = array.tobuiltin(vector3);

// 将内置数组赋给Js数组

var newarr = new array (builtinarray);

// newarr包含相同的元素作为数?/span>

print (newarr);

}

note that in the following all 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.

note:unity doesn't support serialization of a list of lists, nor an array of arrays.

注意按照unity的命名规则下面所有函数首字母均为大写,为方便javascript用户,Unity也接受数组类小写函数?/p>

注意?/em>unity不支持一个列表的列表序列化,不是一个数组的数组?/p>

variables变量

length

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

数组的长度属? 返回或设置数组中元素的数? ?/div>

constructors构造函?/span>

array

creates an array of a fixed size.

创建一个固定大小的数组?/div>

functions函数

concat

concat joins two or more arrays. the method does not change the existing arrays

连接两个或更多数组,这个方法不会改变现有的数组?/div>

join

joins the contents of an array into one string.

连接数组的内容到一个字符串?/div>

push

adds value to the end of the array.

在数组的末端添加值?/div>

add

adds value to the end of the array.

在数组的末端添加值?/div>

pop

removes the last element of the array and returns it.

移除数组最后一个元素并返回它?/div>

shift

removes the first element of the array and returns it.

移除数组第一个元素并返回它?/div>

removeat

removes the element at index from the array.

从数组中移除位于索引的元素?/div>

unshift

unshift adds one or more elements to the beginning of an array and returns the new length of the array.

在数组开始位置添加一个或多个元素并返回新的数组长度?/div>

clear

empties the array. the length of the array will be zero.

清空数组,数组长度将变为0?/div>

reverse

reverses the order of all elements contained in the array.

反转数组中所有元素的顺序?/div>

sort

sorts all array elements

排序所有数组元? ?/div>

ղ

Ķ

µ