小马哥排列三今天预测分析一:array 鏁扮粍_unity3d娓告垙鑴氭湰鍒朵綔鏁欑▼-娓告垙铔墰鍑哄搧 ...

排列三2014079期正版藏机图 www.d0po.cn 2014-12-31 12:11| 发布者: 杨炎| 查看: 1749| 评论: 0|原作者: 蛮牛|来自: unity3d脚本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>

杩欎釜 鏁扮粍绫讳粎浠呯敤浜嶫avascript銆傛洿澶氱敤浜嶤#鎴朖avascript鍏充簬arraylists锛屽瓧鍏告垨鍝堝笇琛紝鐪?a href="//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 鏈変袱绉嶇被鍨嬬殑鏁扮粍锛屽唴缃暟缁勫拰鏍囧噯鐨凧avascript鏁扮粍銆?/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#.

// 鍦ㄦ瑙嗛潰鏉夸腑鏆撮湶涓€涓诞鐐规暟缁勶紝浣犲彲浠ュ湪閭i噷缂栬緫瀹?/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.

鍐呯疆鏁扮粍鍦ㄦ€ц兘鐩稿叧浠g爜涓槸闈炲父鏈夌敤鐨?(浣跨敤unity javascript 鏁扮粍鍜屽唴缃暟缁勫彲浠ュ緢瀹规槗浣跨敤mesh interface鍦ㄤ竴绉掑唴澶勭悊200涓囦釜椤剁偣)銆?/p>

鍙︿竴鏂归潰锛屾爣鍑咼avascript鏁扮粍鍙互璋冩暣澶у皬銆佹帓搴忥紝骞跺彲浠ュ仛鎵€鏈変綘鏈熸湜鐨勬暟缁勭被鐨勬搷浣滐紝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);

// 灏嗗唴缃暟缁勮祴缁橨s鏁扮粍

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鐢ㄦ埛锛孶nity涔熸帴鍙楁暟缁勭被灏忓啓鍑芥暟銆?/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>

上一篇:array.concat 连接下一篇:array.join 连接

相关阅读

文章点评
相关文章
  • 您访问的页面找不回来了 2019-04-07
  • 五莲科技局以“三大”助力动能转换 2019-04-07
  • 匹夫有责之一百一十二—道义大义的博客—强国博客—人民网 2019-03-30
  • 守住青山不放松 护好绿水不辞难——在渝全国人大代表聚焦“共抓大保护、不搞大开发”专题调研记略 2019-03-28
  • 经营者要想“我心换你心”,就要未雨绸缪,让不诚信的诱惑少一点,如此才能在市场中生存下来。反过来说,承担不起亏损就关门歇业,是否也是一种不诚信呢? 2019-03-21
  • 追风上市公司“跌落神坛”-热门标签-华商网数码 2019-03-21
  • 文化艺术交易场所沙龙第一期活动在京顺利举行 2019-03-16
  • 看把你高兴的屁颠屁颠的,光有赞有什么用?我给你个货真价实的 [大红包]。 2019-03-16
  • 候选企业:中国石油呼和浩特石化公司 2019-02-22
  • 我国纳米核心技术取得重大突破 2019-02-22
  • 北京:端午节民俗地图  小枣粽——竹叶红枣糯糯情  2019-01-26
  • 机器人送快递将在西安试点 识别红绿灯还能“车让人” 2019-01-26
  • 首批限竞房正式入市 戳三大盘看详情! ——凤凰网房产北京 2018-12-09
  • 世界杯频爆冷门网友大呼“天台见”!警方:不要冲动,不要跳楼 2018-08-21
  • 始终如一的是:美国优先。 2018-08-21
  • 770| 32| 34| 272| 673| 958| 340| 475| 696| 830|