AutoCAD 3DMAX C語言 Pro/E UG JAVA編程 PHP編程 Maya動畫 Matlab應用 Android
Photoshop Word Excel flash VB編程 VC編程 Coreldraw SolidWorks A Designer Unity3D
 首頁 > Unity3D

【Unity C#編程】自定義編輯器(一)

51自學網 2014-05-24 http://www.0532cf.com

在這一篇Unity C#教程中,將在編輯器中創建一個自定義可視化序列和列表。你將學會:

這個教程適用于Unity4.3版本或以上。老版本的可以點擊這里here

自定義列表

創建測試數據

Unity默認的列表展示是可用的,但是你也可以選擇自定義列表。具體細節因人而異。所以使用不同的可視化組合是非常有用的。通過給變量添加屬性來具體指定編輯器如何顯示它們。

我們以完成的自定義數據教程項目開始,或者創建一個新的項目并導入custom-data.unitypackage

然后創建一個新的測試腳本,命名為ListTester ,其中有些測試序列,并用它制作一個新的預制以及預制實例,這樣我們就能看到它按預期工作了。

1
2
3
4
5
6
7
8
9
10
11
12
using UnityEngine;
 
public class ListTester : MonoBehaviour {
 
public int[] integers;
 
public Vector3[] vectors;
 
public ColorPoint[] colorPoints;
 
public Transform[] objects;
}

新的測試對象,有著寬闊的inspector.

創建自定義Inspector

自定義列表首先要為測試組件創建自定義Inspector。創建一個C#腳本,在Editor文件夾中命名為ListTesterInspector ,作為拓展的UnityEditor.Editor,并應用UnityEditor.CustomEditor 屬性,告訴Unity我們想要給組件繪圖。

1
2
3
4
5
6
using UnityEditor;
using UnityEngine;
 
[CustomEditor(typeof(ListTester))]
public class ListTesterInspector : Editor {
}

自定義inspector腳本

為了真正改變inspector,我們需要重寫Editorclass的OnInspectorGUI方法。如果該方法是空的,那么inspector也將是空的。

1
2
public override void OnInspectorGUI () {
}

空的inspector.

屬性抽屜(property drawer)和編輯器(editor.)之間有三大不同點。

  • 第一:在編輯器中,我們用的是全部 SerializedObject,而不是單獨的SerializedProperty
  • 第二:只要對象保持選定,編輯器實例就會存在,保持引用它的數據,而不是通過方法參數得到它。
  • 第三:我們可以使用EditorGUILayout,這個會自動為我們定位位置。

我們可以通過serializedObject屬性序列化對象。為了準備它用來編輯,首先要把它與它所代表的組件同步,通過調用它的Update方法。然后就可以展示屬性了。在我們做完之后,需要通過ApplyModifiedProperties方法提交所有修改。這將照看到Unity所有的撤銷歷史記錄。在這兩者之間我們將繪制屬性。

1
2
3
4
5
6
7
8
public override void OnInspectorGUI () {
serializedObject.Update();
EditorGUILayout.PropertyField(serializedObject.FindProperty("integers"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("vectors"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("colorPoints"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("objects"));
serializedObject.ApplyModifiedProperties();
}

空屬性的Inspector

該字段再次可見了,但是它們是空的。這是因為PropertyField 不展示任何具體選項,就像序列元素一樣,除非我們告訴它這么做。

1
2
3
4
5
6
7
8
public override void OnInspectorGUI () {
serializedObject.Update();
EditorGUILayout.PropertyField(serializedObject.FindProperty("integers"), true);
EditorGUILayout.PropertyField(serializedObject.FindProperty("vectors"), true);
EditorGUILayout.PropertyField(serializedObject.FindProperty("colorPoints"), true);
EditorGUILayout.PropertyField(serializedObject.FindProperty("objects"), true);
serializedObject.ApplyModifiedProperties();
}

有具體選項的Inspector

原文鏈接:http://catlikecoding.com/unity/tutorials/editor/custom-list/


建議使用電驢(eMule)下載分享的資源。

說明
:本教程來源互聯網或網友分享或出版商宣傳分享,僅為學習研究或媒體推廣,51zixue.net不保證資料的完整性。
 
上一篇:【Unity C#編程】自定義編輯器(二)  下一篇:Unity動態字體文字破碎的解決方法(Dynamic Font Broken)
彩客网 15a31.net | 1483xx.com | 91.ag | 3245j.com | 711066.com | www.1019990.com | www.861000.com | www.yl8553hb.com | www.89888.com | www.593477.com | pj12323.com | a2554.com | www.289333.com | www.4499nsb.com | www.811030.com | feicai0752.com | 5659822.com | www.ylg1108.com | www.78680v.com | www.178719.com | 10878.com | www.7435s.com | www.cc55826.com | www.57578d.com | 00dd8332.com | 3122gg.com | www.6778msc.com | www.35898e.com | www.101125.com | xhtdbaidu.com | www.vip36059.com | www.80844.com | 22p1.cc | jz7.com | www.5309789.com | www.yw344.com | 684526.com | www.333222r.com | www.b32031.com | www.506257.com | 65456.com | www.k64602.com | www.954321p.com | 11005j.com | hwcp44.com | www.133004.com | www.15355c.com | 33313h.com | www.32126v.net | www.7714k.com | 8030r.com | www.76060k.com | www.2655268.com | 1665vv.com | www.1818618.com | www.47506v.com | www.094918.com | 97618f.com | www.v88130.com | www.330865.com | sha161.com | www.986076.com | www.855312.com | 4488ppp.com | www.557tk.com | www.39cp.cc | 8381hh.com | www.400658.com | www.550342.com | 80368b.com | www.hgdc700.com | www.097638.com | www.68666r.com | www.792089.com | 1043.com | www.45681b.com | www.548477.com | www.vt34.com | www.760557.com | 00755b.com | 26668u.com | pc413.cn | www.bet3651687.com | www.4331y.com | www.vns20033.com | 99909k.com | www.298980.com | www.838769.com | www.3616g.com | 2506w.com | x45638.com | www.61233s.com | www.4212t.com | 4638855.com | 199888.com | www.793093.com | www.511219.com | www.40686b.com | tz3222.com | 1408q.com | www.815055.com | www.80868e.com | www.39666.com | 2306l.com | 7773847.com | www.795917.com | www.708282.com | www.476397.com | www.631155.com | v2146.com | jixiang9.com | www.377939.com | www.35898c.com | www.yk222b.com | www.87680b.com | rrr40033.com | e1327.com | www.671075.com | www.4521l.com | www.77099.com | 2698g.com | dzj.tw | pic.caibw1.com | www.5854w.cc | www.81508y.com | www.8yw.net | www.wn2058.com | 33318b.com | w4222.com | www.055976.com | www.fo03.com | www.83993b.com | www.6661ylg.com | www.10ff8.com | 168cp-k.com | 3957p.com | 315965.com | www.511622.com | www.9478b.com | www.06820q.com | www.634599.com | www.008msc.com | feicai0531.com | 3522bb.cc | 3950z.com | 12124688.com | www.927233.com | www.967004.com | www.7893w38.com | www.0022524.com | www.8694k.com | 8899988.com | 4289x.com | hg28.com | 66885002.com | 3379v.com | www.258120.com | www.3552f.com | www.4102d.com | www.1196877.com | www.764609.com | www.bet3650814.com | 97618y.com | 2078g.com | o82365.com | 54443b.com | 8577r.cc | 36502288.com | www.97655e.com | www.hf6660.com | www.68993259.com | www.t32031.com | www.9737vv.me | www.5882323.com | www.js888200.com | www.bb2229.com | www.88837o.com | 1079.cc | 4138004.com | 80850q.com | 7742c.com | 3846hh.com | 3644o.com | zb153.com | 5478a.com | 22yy8331.com | 272f.net | nf6655.com | hg57977.com | 56988d.com | 515165.com | 2757m.com | 2546q.com | www.43131o.com | www.541811.com | www.770981.com | www.876879.com | www.707519.com | www.766927.com | www.642638.com | www.659789.com | www.663566.com | www.599399.com | www.514918.com | www.371931.com | www.130881.com | www.209983.com | www.029709.com | 8547ww.com | 1483kk.com | zhcp21.com | 10050533.com | 3822s.com | xx8159.cc | 983888c.com | e2894.com | 1597442.com | lshtq.cn | www.9679b.com | www.4261199.com | www.41610.com | www.858958.com | www.138cps.com | www.5049u.com | www.3983201.com | www.85656.com | www.979303.com | www.81678z.com | www.2373v.com | www.76wcp.com | www.709337.com | www.068673.com | 2373t.com | 3304o.com | 2757ucom | 62222o.com | 3024p.com | www.7893w9.com | www.798012.com | www.92939.com | www.28000r.com | www.js57666.com | www.96386l.com | www.26878y.com | www.tj52.com | 6668009.com | 2455o.com | rrr5701.com | yhhebei.vip | www.28758o.com | www.38144144.com | www.6880ii.com | www.hd8678.com | www.371l.cc | www.623660.com | ww333hg.com | dingji0088.com | mm33.vip | www.033033j.com | www.vv1112.com | www.oa2668.com | www.91779n.com | www.77996c.com | www.588767.com | www.55228e.com | 059j.cc | hg10a.com | 44ww8331.com | www.139835.com | www.ggx.99233x.com | www.774546.com | www.3978l.com | www.684244.com | 6js345.com | 6556pk.com | 500000917.com | www.566333.com | www.lb55567.com | www.68993229.com | www.544646.com | jidu9.com | 8977hh.com | www.365109i.com | www.hwx66.com | www.130013.com | www.81678y.com | www.355225.com | 9002y.com | js777dl.com | www.xpj171.com | www.hgdc100.com | www.9818c.cc | 9103dd.com | 50029900.com | www.777cm1.com | www.50999c.com | www.87668l.com | www.156689.com | 553955.com | jdbxjw.com | www.888365q.com | www.vn888345.cc | www.364141.com | bg222333.com | aa33336.com | www.105242.com | www.dsj11.com | www.629965.com | xpj13666.com | www.7009844.com | www.vs88.com | www.00840a.com | 66094466.com | 86226t.com | www.67797c.com | www.4996xt.com | www.36166k.com | 35yy.vip | 7726eee.com | www.xpj88003.com | www.8577c.cc | www.hcw018.com | 4995l.com | www.25288q.com | www.xpj126.com | www.343918.com | 50883.com | www.j7700.com | www.2021l.com | www.c131.vip | 69522v.com | www.1869r.com | www.8885hj.com | www.980771.com | 8722wwww.com | www.546995.com | www.800544.com | www.735898.com | 5309p.com | www.1310909.com | www.32638.com | www.082709.com | ss00558.com | www.666478.com | www.50051t.com | 1466z.com | www.56733z.com | www.80188x.com | www.580296.com | 4036nn.com | www.91293.com | www.16878k.com | js14u.com | p888.com | www.3421c.com | 3522r.vip | 1077gg.com | www.97060g.com | www.627029.com | 3778pp.com | www.683556.com | www.658zf.com | sjg007.com | www.31567.ag | www.5177.cc | 6003822.com | www.67797h.com | www.35898j.com | 3389.com | www.sb9907.com | www.5500ra8.com | hg999333w.com | www.sun8558.com | www.48330z.com | rgcp.com | 5855jj.com | www.86339o.com | 5001z.com | www.333222z.com | www.5856856.com | yyh910.com | www.m1862.com | www.3978v.com | 6601.com | www.hg7861.com | www.ya318.com | 71707o.com | www.swty566.com | www.965176.com | x01234.com | www.1168b.com | www.316106.com | 3434jjj.com | www.0600y.cc | 55331h.com | www.520195.com | www.6661f.cc | vip80188.com | www.38138m.com | 237.com | www.333222p.com | www.99677g.com | 69619.com | www.70389.com | www.320055.com | 5168222.cc | www.0600n.cc | 12742w.com | www.gp4672.com | www.701497.com | oo56988.com | www.2566y1.com | 99589aa.net | www.65175.com | www.640477.com | 588aaa.cc | www.w84g.com | 1634t.com | www.3589888.com | www.375736.com | hgw168e.com | www.66652c.com | 159666u.com | www.60468277.com | 26444l.com | www.v445566.com | www.957999.com | 7935p.com | www.88888.mx | 3614q.com | www.79095m.com | hhhhh.com | www.9101901.com | 99567j.com | www.9996nn.com | www.1368k.cc | le888g.com | www.1466y.com | alpk44.com | www.rycp160.com | 30019f.com | www.sun0009.com | www.178725.com | www.767997.com | www.3478f.cc | 44488s.com | www.52303d.com | 5733emv.com | www.48330y.com | 3656oo.com | www.0600u.cc | 39199w.com | www.30350j.com | 1407y.com | www.531789.com | j15jj.com | www.38345o.com | 68228c.com | www.938968.com | 8742b.com | www.c44hh.com | huangma18.com | www.93342.com | 51oid.com | www.818msc.net | 0080g.com | www.66442.com | 87570ht.com | www.56830f.com | 61321199.com | www.81789.com | 3788m.com | www.t948t.com | 5804e.com | www.50999z.com | 22207q.com | www.bet63j.com | 1489h.com | www.hg6668.tv | 23478.com | www.a458.com | 2096c.com | www.21202e.com | 365388.bet | www.dqz6.com | www.bet365608.com | www.394611.com | www.1590mm.com | 1468.com | www.g3065.com | 7742d.com | www.38775oo.com | www01234.com | www.26878m.com | www.81866t.com | www.590596.com | www.a80065.com | hv712.com | www.28000p.com | 83138o.com | www.fa7969.com | 59889v.com | www.900140.com | www.as0002.com | 668cp00.com | www.ac777.com | 463k7.com | www.89777u.com | feicai0795.com | www.645326.com | www.0777msc.com | 4880r.com | www.o32031.com | cc00558.com | www.99jta.com | www.4938k.com | 4774s.com | www.5981j.com | qpby2277.com | www.ya838.com | www.hg1767.com | 5804b.com | www.http://489633.com/ | 655660055.com | www.hw6689.com | www.307607.com | ddcp33.com | www.7920m.com | jing7773.com | www.853199.com | www.amdc0009.com | 8901q.com | www.83033x.com | www.yh-9.com | 80060101.com | www.761bbb.com | 50027711.com | 9964b.com | www.00773d.com | v8738.com | www.781253.com | www.hg7695.com | 2778bb.com | www.8816s.com | www.9547l.com | 928012.com | www.36584444.com | www.283804.com | 30006r.com | www.48330b.com | www.39728.com | feicai0792.com | www.32031t.com | 38822211.com | 88304j.com | www.6386a.com | 8036cc.com | 38sb.com | www.99552uu.com | 3148.com | 7720w.com | www.44118q.com | 1408o.com | 168cp-h.com | www.8722.am | jinsha69.com | 5446ww.com | www.q98478.com | www.vns990.cc | 37818.com | www.89894n.com | www.142351.com | 22207c.com | www.033.la | www.021700.com | 8344333.com | www.679822.com | www.38345m.com | 7989n.com | 68228j.com | www.3566ff.com | www.87680c.com | ll5443.com | www.fyyy3.com | www.777567.com | 5219e.com | www.192711.com | www.63606e.com | www.ag88100.com | 55984y.com | www.65707z.com | www.tk828.com | 22117q.com | 56787.com | www.yh8899.bet | www.am4088.com | 83138k.com | www.412688.com | www.556939.com | www.66yh765.com | g2649.com | www.893010.com | www.bwinyz10.com | www.jj881.com | 6245t.com | www.775701.com | www.357336.com | www.pj8458.com | 333pj8.cc | www.588088.com | www.wns123k.com | www.21365ll.com | 5856v.com | www.178759.com | www.500558.com | www.335503.com | 86811kk.com | 55331ii.com | www.8039c.com | www.28168.com | www.033033l.com | 667766xcom | www.553398.com | www.86339t.com | www.xb0020.com | 4242001.com | 88807o.com | www.23czj.com | www.bwinyz07.com | www.4972ee.com | d67890.com | 2506h.com | www.7793m.com | www.7415t.com | www.39695u.com | y4255.com | 20778866.com | www.5095k.com | www.06617a.com | www.4625o.com | 9068p.com | 2381005.com | www.fyyy3.com | www.30350f.com | www.88570.com | 4023f.com | 3522ff.com | www.190994.com | www.96386n.com | www.4972z.com | www.67797z.com | 2146e.com | 39199l.com | www.598300.com | www.55238a.com | www.64.ag | www.gd68.com | 6939.com | aa67890.com | www.153946.com | www.68568z.com | www.a69096.com | www.ccc826.com | 3685t.com | z18.com | 1188589.com | www.076wy.com | www.4102m.com | www.xj666o.com | www.28758m.com | 678210.com | js78886.com | www.50080v.com | www.6364c.com | www.12136l.com | www.365279c.com | www.40818f.com | blr8033.com | 0289a.com | 73999i.com | www.701540.com | www.81520h.com | www.47506u.com | www.88jt99.com | www.00829o.com | 5804h.com | 35222ww.com | jixiang10.com | www.062866.com | www.fl62.com | www.682021.com | www.4996xt.com | www.31399ee.com | www.8694w.com | 2355k.com | aipin11.me | 55545g.com | xpj99.am | www.199301.com | www.77yfa.com | www.404577.com | www.6687d.com | www.998855j.com | www.hg4748.com | www.ag8801.com | 3983013.com | 9366c.com | www.232775.com | www.bei08.com | www.89266.com | www.yh8377.cc | 4997n.com | pj9937.com | 4445365.com | yun999.com | sss01234.com | 69111q.com | www.529026.com | www.qbwc1.com | www.0270b.com | www.325860.com | www.0031331.com | www.5049t.com | www.44400.cc | www.pj8551.com | www.vns9998.com | 1946.bet | 3189q.com | 9309208.com | 3750.com | 074o7.com | 6556e.com | 08820055com | 2698s.com | 55145.com | www.006150.com | www.505420.com | www.745568.com | www.09gcw.com | www.98255.com | www.77114c.com | www.337756.com | www.6889771.com | www.56011w.com | www.n2894.com | www.9570118.com | www.848777a.com | www.1168l.com | www.56655j.com | www.610567.com | www.846622.com | www.184998.com | www.xb0021.com | www.2846d.com | www.54146666.com | www.2846i.com | www.y30226.com | www.10050011.com | www.655666f.com | www.39695c.com | www.440567.com | www.js30859.com | www.hg7088.sh | www.benz4242.com | www.21365jj.com | www.88807g.com | www.2846p.com | www.88554066.com | www.9b100.com | www.zs5588.com | www.929777.com | www.8517444.com | www.593333.com | www.8923dc.com | www.jjjj003.com | www.0285.com | www.wz2255.com | www.668cp55.com | www.66hg6.com | www.6606488.com | www.4078z.com | www.369408.com | www.vns33.me | www.hg7800.com | www.1122800.com | www.50026x.com | www.589zf.com | www.870300.com | www.389644.com | www.71399e.com | 5002aaa.com | 8159z.cc | 08159t.com | 4167r.com | 2105.com | 26444a.com | www.7435v.com | www.sbet345.net | www.22gp.com | www.998855x.com | www.4078m.com | www.3w111.com | www.6939f.com | www.99355.cc | www.855312.com | www.178113.com | p6662019.com | 8855670.com | 4036222.com | ag.hg999222.com | www.xjs8898.com | www.88807k.com | www.003344.cc | www.b32939.com | www.wns22.me | www.71399b.com | www.943893.com | www.195880.com | 6261t.com | js999js.com | 01234qq.com | feicai0972.com | www.4625k.com | www.48tk.com | www.8473w.com | www.11599068.com | www.9818r.cc | www.520935.com | 515165.com | 3936x.com | 67877.com | www.85770y.com | www.57798d.com | www.71071a.com | www.5856859.com | www.yi770.com | www.83993a.com | y2523.com | 3775i.com | cc1331.com | www.255251.com | www.177158.com | www.4833045.com | www.003ac.com | www.36788a.com | 27365e.com | 8381007.com | www.888167.com | www.68556.com | www.47506x.com | www.50052j.com | www.369908.com | yin3939.com | 11c53.com | www.55hggj.com | www.789238.com | www.99552aa.com | www.5086y.com | qq365x.com | 1408y.com | 3505.com | www.191949.com | www.15k0048.com | www.66376s.com | www.314077.com | 6572x.com | hg00566.com | www.vns9948.com | www.1234cp.me | www.035647.com | www.507281.com | 0343e.com | 6118r.com | www.1597sss.com | www.bwin950.co | www.35918k.com | www.50054v.com | 0802.com | www.666k8.com | www.v56789.com | www.ejylc14.com | www.507433.com | u4212.com | yh888j.com | www.508814.com | www.55676q.com | www.717224.com | 817.com | 2649tt.com | www.hg5689.com | www.flb906.com | www.622989.com | hg00566com | 0600s.cc | www.tyc8879.com | www.9646x.com | www.119705.com | xpjxianlu.com | www.xinhao3344.com | www.90506.com | www.26878t.com | 3844cc.com | wlb33.com | www.js7888.co | www.hg6688.net | www.575872.com | 3983004.com | www.xw3333.com | www.6776dd.com | www.070wy.com | yh7788.bet | 2767b.com | www.77731h.com | www.33997s.com | 5001e.com | yth22.net | www.5858564.com | www.95333w.com | 66300vip34.com | 86811z.com | www.29019.com | www.7239f.com | yiqunhs.com | 2146r.com | www.9920992.com | www.76520q.com | byj10.com | 081792.com | www.79500r.com | www.66yfa.com | 914907.com | www.bh33123.com | www.4996fs.com | www.770001.com | 65561177.com | www.4446358.com | www.5446n.com | www.205882.com | 2359933.com | www.57798d.com | www.77801y.com | aa3336.com | lpj88.com | www.3066mm.com | www.494969.com | 3404r.cc | www.pj8474.com | www.80065c.com | 876878h.com | www.hg9951.com | www.820042.com | www.196037.com | 3685c.com | www.2424394.com | www.sxyl6.com | 33599rr.com | www.330067.com | www.40R.COM | v47479.com | www.88jt09.com | www.32031z.com | c388z.com | LXYL352.com | www.03bet8.com | www.381110.com | js99870.com | www.77731y.com | www.890702.com | 36401122.com | www.087hg.com | www.c4525.com | rrr5701.com | www.112351.com | www.9356k.com | aobo45.com | www.5320jjj.com | www.5086c.com | 33432x.com | www.hg78789.com | www.1035aa.com | blr8844.com | www.000894.com | www.gyfc4.com | 4022u.com | www.3033c.com | www.730678.com | b21148.com | www.38345z.com | www.187393.com | feicai0414.com | www.377666n.com | js848.vip | www.1869x.com | www.78919e.com | 6601wz.com | www.333133g.com | www.50074b.com | 2222k5.com | www.900988.com | www.819759.com | 2127zz.com | www.c30666.vip | jianwei.com | www.yh66604.com | www.8998766.com | 1253-6.com | www.jing6661.com | www.987581.com | 655ib.com | www.4996fs.com | 168cp-r.com | www.bet3650514.com | www.71399h.com | 88119o.com | www.yingle55.com | www.332907.com | 500000520.com | www.hg88.vip | 80892dd.com | www.js07888.com | www.hm6655.com | ylzz3338.com | www.87708a.com | 921350.com | www.53516a.com | www.978261.com | z7742.com | www.33pjjt.com | jsc19.com | www.234333.com | www.573667.com | 3089p.com | www.hb598.net | 5504q.com | www.79500b.com | 496ww.com | www.00618q.com | www.c9259.com | 0652n.com | www.48330t.com | 66300vip12.com | www.cp505.com | 50099n.com | www.3056008.com | www.911710.com | 59889h.com | www.010vip.com | 8037aaa.com | www.biying980vip.com | hg7078.biz | www.554msc.com | www.191380.com | www.355325.com | www.k795.com | 2306r.com | www.790964.com | 3788f.com | www.40288b.com | ss1915.com | www.8967v.com | 88851b.com | www.775678.com | www.33112o.com | www.yh6118.com | www.702152.com | www.8520z.com | www.32123p.com | 73055u.com | www.hn58qp.com | 3522jj.cc | www.q3410.com | 25288x.com | www.673888x.com | 65005i.com | www.cp505a.com | zgfcw.cc | www.huidasj.com | 28288c.com | www.ddpahv.com | 20775511.com |