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)
彩客网 www.48330g.com | www.296395.com | 703.ceo | www.14168d.com | 91019j.com | www.50052g.com | www.wn0002.com | www.602266.com | www.xpj171.com | 55402dh.com | www.b456x.com | 474.com | www.302551.com | 81366v.com | www.3479i.com | www.36536509.com | 5802xx.com | www.ggq.99233q.com | g8381.com | www.52303f.com | www.ag9811.com | www.220892.com | www.009789.com | 867203.com | www.7957988.com | 5hg7788.com | www.500227.com | www.44799.com | 22890.co | www.0194003.com | 1213ttt.com | www.314213.com | www.vs1368.com | q86811.com | www.66376p.com | www.hhh6666.com | www.36788a.com | www.5966ppp.com | 3568d.com | www.16878y.com | www.87680m.com | 66458d.com | www.704909.com | 6868269.com | www.912594.com | www.kj803.com | 9068s.com | www.5854f.cc | www.hg56555.com | pj88ll.com | www.86267x.com | www.866918.com | 00787.com | www.blr1144.com | www.hg9998.com | mgm3242a.com | www.55717q.com | 54443k.com | sxmlr.net | www.pjc44.vip | 5004ss.com | 3mgmzzz.com | www.656133.com | 131ttt.net | 6766rr.com | www.1764x.com | www.bet365608.com | 2618e.com | www.ya2019t.com | www.333133d.com | blm733.com | www.61655w.com | www.hg0318.com | 85698k.com | www.396.cc | www.jty649.com | 3467l.am | www.330637.com | www.55070p.com | 8036kk.com | 2373w.com | www.0343u.com | www.p32126.cc | 51200gg.com | www.2875s.com | www.87849.com | 55323y.com | www.335294.com | www.4196g.com | www.aicaidd.com | 3178uu.com | www.65707j.com | www.58767.com | www.511174.com | www.b35pp.com | 80892ss.com | dxcp33.com | www.26163r.com | www.hg2286.com | 6868sw.cc | 20775599.com | www.cp3.mobi | www.biying920vip.com | www.379568.com | 55882007.com | www.djcp004.com | www.ba309.com | www.18438e.com | 3404i.cc | 809h50.com | www.954321w.com | www.amdc55.com | 45637p.com | 4195cc.com | www.73166b.com | www.pj111111.com | 8901n.com | 256777c.com | www.786126.com | www.xpj4.net | www.js839.com | 83378c.com | 3559dddd.com | www.400662.com | www.1764q.com | www.33352055.com | 131a.net | 1669w.com | www.205882.com | www.55717.com | www.87865.com | 61322255.com | 168cp-i.com | www.511642.com | www.v904488.com | www.3814222.com | 3156yyy.com | 111122ee.com | 55155b.com | www.50054g.com | www.4972g.com | www.9996zz.com | 85686.com | ss2649.com | www.506586.com | www.5958121.com | www.8yw.net | 7736q.com | nn1915.com | 6363dd.com | www.808712.com | www.77424.com | www.45066.com | 1164.com | 6118e.com | 1389b.com | www.297277.com | www.bet73f.com | www.4828228.com | www.09527w.com | 30019r.com | 0267.com | 7792h.com | www.541522.com | www.61233j.com | www.30350u.com | www.65471188.com | www.030xpj.com | 2096f.com | j669933.com | hsh88.com | www.763659.com | www.3978r.com | www.5981y.com | www.331suncity.net | www.56733e.com | d62365.com | 999hg.com | 105boo.com | www.802533.com | www.78949k.com | www.804sun.com | www.4963ee.com | www.6888tm.com | www.jsth518.com | 2455z.com | 30688s.com | 8884001.com | 9339999e.com | www.214654.com | www.qucw7.com | www.151019.com | www.p32031.com | www.20199pp.com | www.24xjw.com | www.bet3650614.com | 3844n.com | mm00558.com | 888.vip | 50067v.com | 1213ggg.com | n444000.com | www.355284.com | www.c1825.com | www.6832p.com | www.15355u.com | www.62778844.com | www.614586.com | www.4694z.com | www.6444555.com | www.hg0780.com | www.56520l.com | 1389x.com | 83086h.com | g2146.com | 42428822.com | 3467x.cc | 54243366.com | 760hd.vip | 4288uu.com | 0022ylc.com | 0099066.com | 1669m.com | 56728.com | k3405.com | hg1698.com | 28758z.com | 0029d.com | 3049m.com | zx3144.com | 8036vv.com | 6766rr.com | 00774xx.com | 33zz8332.com | 7176789.com | 7196.com | pj7778.com | 5509o.com | feicai0793.com | 1106766.com | 52688a.com | yd91.com | 9994cc8.com | 7894e.com | 8159vvv.cc | 8547mm.com | tt888k.com | c4255.com | 3559nnnn.com | js802hd.com | 3122cc.com | cu28.com | www.hg7288.com | www.25673f.com | www.p78888.com | www.2288098.com | www.0860j.com | www.48588c.com | www.js88058.com | www.a80047.com | www.238288.com | www.a7793.com | www.54968.com | www.530056.com | www.5655999.com | www.919654.com | www.86267p.com | www.5522p.cc | www.701269.com | www.338053.com | www.43131z.com | 11989r.com | le888o.com | l99474.com | 4066nn.com | 44488v.com | www.yh8007.com | www.msc77.la | www.t0524.com | www.11.sb | www.4809r.com | www.yh66988.com | www.8667y.com | www.755874.com | www.168323.com | 28288c.com | zb153.com | 686.org | 4433vn77.com | www.537msc.com | www.2220365.com | www.4996cq.com | www.179101.com | www.08500w.com | www.605134.com | 2767t.com | 87965oo.com | 00rr8332.com | www.xpj8818.com | www.330246.com | www.6662ylg.com | www.25229.com | www.5091o.com | www.178387.com | sbfa999.com | 40420011.com | www.8806js.com | www.999133.com | www.848777u.com | www.4331o.com | www.721709.com | 2546c.com | 73055w.com | 8742aa.com | www.448222.com | www.4996hz.com | www.68568w.com | www.348177.com | 5360i.com | 33318b.com | www.365775.com | www.938y.cc | www.9989587.com | www.936399.com | 66885002.com | 36403300.com | www.alpk44.com | www.jinying28.com | www.pgylc.com | www.686783.com | 90307l.com | x33g.vip | www.pj990.com | www.4521u.com | www.3416y.com | cao568.com | 4488ppp.com | www.ylhg5858.com | www.c44jj.com | www.99677m.com | www.178625.com | j84105.com | 32365v.com | www.555305.com | www.yh68071.com | www.369071.com | 00773x.com | www.210zr.com | www.721408.com | www.rfdc02.com | www.035059.com | 20053388.com | www.hg77719.com | www.9170105.com | www.513.vip | 67890ppp.com | hbpc3258.com | www.agcpw.com | www.26878q.com | 38821155.com | 2078a.com | www.378878.com | www.504446.com | v93901.com | 7570800.com | www.85016.com | www.1466o.com | www.xinyc8.com | 3679aa.com | www.15515533.com | www.bjl917.com | www.111307.com | 3614v.com | www.999133.com | www.hb598.cc | ca5055.com | 1077uu.com | www.jjjj33333.com | www.33588t.com | 30019e.com | y00351.com | www.ww55826.com | www.938627.com | 3644o.com | www.pj7019.com | www.837292.com | www.097710.com | 888.cm | www.85966.com | www.3479u.com | 91019f.net | www.333222o.com | www.ba503.com | www.66376o.com | ting0055.com | www.58665g.com | www.caim2.com | 2012bet88.com | www.yh556699.com | www.68689g.com | 69443344.com | www.338830.com | www.792065.com | 77424466.com | www.505vns.com | www.56011d.com | 9645ss.com | i2306.com | www.46630.app | www.022197.com | 2078a.com | www.hs6666.com | www.178670.com | YLHG5858.com | www.999msc.net | www.978127.com | 2229gp.com | www.138cpy.com | www.755740.com | 33318b.com | www.5504v.com | www.520691.com | 11662007.com | www.4996xm.com | vv968.com | 32355hh.com | www.h36599.com | 123456.cc | www.hjdc2000.vip | www.61655z.com | 30006a.com | www.35789.com | www.849770.com | 6261oo.com | www.9737bb.com | www.43131x.com | 8989770.com | www.q98478.com | 3222b.cc | www.991866.com | www.844141.com | e58955.com | www.623906.com | 123456xx.cc | www.y1155.com | www.21202j.com | 08159k.com | www.1168v.com | www.41518u.com | www.ds22222.com | www.068336.com | 80188.com | www.5049k.com | www.150957.com | www.sjs11.com | www.yh7773.com | 111000hh.com | www.99113a.com | 3685s.com | www.39695z.com | www.1368j.cc | 14683333.com | www.5508.am | cp014.com | www.184897.com | 4809c.com | www.777444g.com | www.axc5.com | 0747w.com | www.260655.com | laok222.com | www.932367.com | ww2649.com | www.558337.com | www.361576.com | www.zr9933.com | www.083wy.com | 00bb8331.com | www.ampj3432.com | 566777c.com | www.88325s.com | blmdc6.com | www.58665k.com | 44tt8332.com | www.zx5551.com | xx888w.com | www.0805u.com | www.957588.com | www.727xpj.com | www.974674.com | 4633366.com | www.009ac.com | 228888r.com | www.9478f.com | 99111kk.com | www.71233w.com | 9287999.com | www.633594.com | p45638.com | www.6939i.com | 40400.com | www.48330m.com | 55193.com | www.cb900.cc | 22uu8332.com | www.546230.com | 80850nn.com | www.yt2019.com | a5959.com | www.99638b.com | gc8.com | www.32123n.com | 30006g.com | www.022zj.cc | www.a2a333.cc | www.897743.com | www.0636h.com | www.577062.com | www.pj15778.com | www.177806.com | www.k2229k.com | 2934c.com | www.56655x.com | 3522n.vip | www.00778x.com | 9339999.com | www.x2666.com | df8d.com | www.106ak.com | www.cr345.net | www.375957.com | www.w8586.com | 0496556.com | www.5001600.com | 8569899.com | www.0088psb.com | 61323377.com | www.39391.cc | www.wnsr818.com | www.330817.com | www.8898hg.com | ddcp33.com | www.47506l.com | emb8578.com | www.60123z.com | www.555xin2.com | www.391110.com | www.624444d.com | 3122x.com | www.sbd026.net | 3678eee.com | www.bet73i.com | www.zun371.com | www.77802i.com | www.301393.com | xpj8182.cc | www.33112p.com | www.7777wns.com | 4136x.com | www.36008.com | 67890i.com | www.62118c.com | www.ag6051.com | 2229vip.com | www.q32939.com | 4288xx.com | www.097wy.com | www.ty7000.com | 3242q.com | www.880317.com | ylg11111.com | www.198109.com | www.0849j.com | 838388b.com | www.809216.com | www.ld003.com | 3967p.com | www.ya308.com | www.xpj1535.com | xs9411.com | www.0270q.com | www.hg609.com | 88851b.com | www.x94600.com | 3822o.com | 4412.com | www.601709.com | 4395599.com | www.193161.com | www.71071p.com | 52599o.com | www.596702.com | www.m9478.com | 32008.com | www.799439.com | www.cctv577.com | 86611h.com | www.855271.com | www.www904744.com | y7062.com | www.915056.com | www.wwww.6230z.com | 4167c.com | www.898140.com | www.10mscc.com | mm99977.com | www.582477.com | www.5146z8.com | csj600.com | www.36788e.com | www.4058ll.com | amjsc01.com | 48281111.com | www.68993226.com | www.u27229.com | 38238m.com | www.09559.cc | www.hg8423.com | YLHG3838.com | www.320667.com | www.9911331.com | 3168b.com | 9498.us | www.bet73a.com | www.hg1115k.com | quannengsoft.cn | www.960883.com | www.27363f.com | 3163.com | yl2827.com | www.bet73c.com | www.888423.net | 7599gg.com | www.330836.com | www.9895h.com | www.76060x.com | 57157i.com | www.ya308.com | www.668cp11.com | 3379uu.com | 4255hhh.com | www.29178d.com | www.05899.com | 55818z.com | a32689.net | www.86267f.com | www.123f4.com | 11005r.com | www.055979.com | www.55676n.com | www.hg2367.com | 5003hh.com | 3685e.com | www.68993275.com | www.2605505.vip | chinapsp.cn | 59889e.com | www.21229.com | www.0400005.com | 009900h.com | 65005m.com | www.8499f.com | www.8967z.com | www.hg6969.org | 998n.cc | www.223805.com | www.90555.net | www.203203.com | 83377z.com | man993.com | www.573898.com | www.33074.com | www.5536kj.com | 88am.cc | 4694f.com | www.647377.com | www.3434bbb.com | www.89hghg.com | 6572m.com | jszg2.com | www.609719.com | www.5551883.com | www.22076.com | 9103jj.com | 3y.com | www.36788o.com | www.50052p.com | www.hg8vv.com | www.88807b.com | 4182l.com | 228118.com | www.525059.com | www.yl13444.com | www.07179.com | www.a1a777.cc | hhvip666.com | 131bbb.net | www.21202ii.com | www.7758.com | www.1389oo.com | www.pj5556.com | 50067x.com | 8159zz.cc | a997.com | www.kc66.com | www.4809v.com | www.542suncity.com | www.k32126.cc | 1031878.com | 10050535.com | jlykk.com | www.qj63.com | www.9822az.com | www.370175.com | www.00829k.com | feicai0316.com | 0134.com | 01234yyy.com | www.431128.com | www.50064x.com | www.30350p.com | www.4516.com | www.777444u.com | 009900d.com | 3559pp.com | 99111pp.com | www.106526.com | www.7793m.com | www.578888.vip | www.c526688.com | www.0907ww.com | 59599y.com | zunyi801.com | 3412233.com | feicai0777.com | www.354911.com | www.33ttz.com | www.93gj07.com | www.18k0048.com | www.yl2290.com | www.88807k.com | 7792w.com | 5309a.com | 3435a.com | dyxjjjc.gov | 36402222.com | 500000730.com | www.111505.com | www.701524.com | www.0014d.com | www.32365.Com | www.7240y.com | www.47506l.com | www.hg702.com | www.2011.vip | www.3350.com | www.tyc55.com | www.v27229.com | www.888vip1.com | 5004gg.com | 7935k.com | 33313o.com | 2836516.com | vvv40033.com | 2214o.com | 7893w38.com | 134767.com | c91234567.com | 33558448.com | wnsr8815.com | 4546119.com | ss8159.cc | 3550f.com | 8790m.com | xh00020.com | 28758j.com | 433.com | wlb22.com | 2418006.com | 20833f.com | xianboba.com | aa3335.com | www.50052v.com | www.87668v.com | www.111505.com | www.117318.com | www.177478.com | www.186796.com | www.193723.com | www.109615.com | www.77803u.com | 6002aa.com | 32126b.net | 131y.net | hh4255.com | 6699vn77.com | 6446vip.com | c9.com | hg0886.tv | d4212.com | 4289p.com | 2757c.com | bwin8t.com | 33115gg.com | bm1395.cc | www.hj3888.com | www.hg94444.com | www.32126z.net | www.935770.com | www.bbb839.com | www.77731q.com | www.4694c.com | www.06387733.com | www.1764n.com | www.770802.com | www.71399h.com | www.2934r.com | www.818646.com | www.372082.com | 9566362.com | 77662007.com | 866666g.com | 5019kzc.com | hg1044.com | 364830.com | www.bh33123.com | www.pj4180.com | www.fa208.com | www.56655s.com | www.4996xa.com | www.rrqp333.com | www.84499d.com | www.qmkl7.com | www.390706.com | 69445566.com | feicai0570.com | 5906gg.com | 4581.com | 55331d.com | 3522cc.com | hg792.com | ff555w.com | www.hgcn88.com | 6175oo.com | www.682833.com | www.97780099.net | www.hg206.com | www.009159.com | www.88c668.com | www.9b800.com | www.7240j.com | www.f2894.com | www.99383.com | www.920564.com | www.375916.com | 2222138.com | 80892h.com | 22jj8331.com | vns100.net | 3807g.com | 776093.com | www.b8867.com | www.508814.com | www.bwinyz27.com | www.8582bb.com | www.8499w.com | www.211857.com | 11422m.com | 223639.com | 5856ppp.com | 87965uu.com | www.ag822.com | www.v36.com | www.5220666.com | www.606117.com | www.782478.com | sytydn.com | 1104dh.com | 55nn8332.com | www.943a29.com | www.csh365.com | www.dzj0707.com | www.98vs88.com | www.065wy.com | www.2350j.com | 22291155.com | 39990055.com | hga017.com | www.28758j.com | www.76775a.com | www.bwin900.co | www.65707d.com | www.180121.com | JS1388p.com | jj67890.com | www.28758j.com | www.6650.bet | www.3846ee.com | www.fyyy2.com | aa33337.com | 75991c.com | bdg1100.com | www.bet815.com | www.cp98.com | www.37266a.com | www.983112.com | 131f.net | 2222138.com | 8159t.cc | www.6491v.com | www.glc22.com | www.6766msc.com | www.379.net | www.zfcp3.com | 123456nn.cc | 8569811c.com | www.555545.com | www.a456x.com | www.80065n.com | www.933345.com | 37818.com | 8827oo.com | www.7669g.net | www.6668ylg.com | www.022am.cc | www.257015.com | 496.vc | www.7435g.com | www.131msc.com | www.5981t.com | www.66wcw.com | 226688f.vip | 52688i.com | a3144.com | www.55526s.com | www.33588n.com | baidu886.com | 38850011.com | www.3421n.com | www.8080999i.com | www.855876.com | 50023355.com | 2709b.com | www.50000.com | www.5086c.com | www.399280.com | mf703.com | www.9996ss.com | www.300msc.com | www.1434v.com | www.001879.com | fff5701.com | www.hg9222.com | www.35252f.com | www.739233.com | rbbet99.com | www.7380r.com | www.18617.com | www.196039.com | 3807p.com | 8988q.com | www.343478.com | www.8499z.com | 97000.net | 052979.com | www.8553j.com | www.18005.com | pp7742.com | 2013.com | www.05bet8.com | www.50051n.com | 0239.cc | www.7720p.com | www.8967z.com | www.8999ka.com | pj88jj.com | www.00618z.com | www.y8853.com | www.178795.com | 55797c.com | www.am3366.com | www.0600o.cc | 31325e.com | 5856jj.com | www.b36365.com | www.66621j.com | 360urlscan.com | 99339193.com | www.a.1308pj.com | www.035168.com | 225605.com | www.09569v.com | www.xy52aa.com | 8547r.com | www.a8a8789.com | www.07679l.com | 62222r.com | 93922q.com | www.444xhtd.com | www.67258d.com | 4255x.com | www.betgobet.com | www.wqdlcn.com | 0615019.com | 032526.com | www.081355.com | www.368477.com | fc9596.com | www.caipiao88d.com | www.320477.com | 33318t.com | www.bg999111.com | www.5953588.com | chinajtw.com | www.32666y.com | www.dy910.com | 77009193.com | www.pj5559.com | www.00889.com | 35442444.com | www.hg0462.com | www.7116c.com | 00048o.com | www.hg8968.com | www.3479e.com | 44269999.com | www.729696.com | www.594911.com | zzz8827.com | www.69567q.com | 8827sss.com | www.200448.com | www.js02348.com | 188qq888.com | www.588277.com | www.590833.com | 876878a.com | www.hg0180.com | www.cp208.com | qmbc4.com | www.55526t.com | www.252359.com | 33313e.com | www.1429.com? | 1463.com | www.pj5794.com | www.cpyz1.com | 6261pp.com | www.4078k.com | 77116556.com | www.789sbet.net | www.78gcw.com | 23599v.com | www.4963ss.com | 0747uu.com | 365488.bet | www.8905b.com | 5528839.com | www.295111.com | www.bei08.com | 4136z.com | www.4521r.com | 2267z.com | 37730vip.com | www.ylylc00.com | 287733.com | www.9737nn.com | b01234.com | www.09569f.com | www.949498.com | 3844m.com | www.99677x.com | fucaiwang.pw | www.jz95533.com | 500c.vip | www.98qxw.com | www.89911.cc | ddcp7.com | www.954321t.com | 3513008.com |