資源簡介
unity ngui計算器小案例,能使初學ngui的能容易上手,
代碼片段和文件信息
using?UnityEngine;
using?UnityEditor;
using?System.Collections.Generic;
///?
///?Inspector?class?used?to?edit?Inventory?Databases.
///?
[CustomEditor(typeof(InvDatabase))]
public?class?InvDatabaseInspector?:?Editor
{
static?int?mIndex?=?0;
bool?mConfirmDelete?=?false;
///?
///?Helper?function?that?sets?the?index?to?the?index?of?the?specified?item.
///?
public?static?void?SelectIndex?(InvDatabase?db?InvbaseItem?item)
{
mIndex?=?0;
foreach?(InvbaseItem?i?in?db.items)
{
if?(i?==?item)?break;
++mIndex;
}
}
///?
///?Draw?the?inspector?widget.
///?
public?override?void?OnInspectorGUI?()
{
EditorGUIUtility.LookLikeControls(80f);
InvDatabase?db?=?target?as?InvDatabase;
NGUIEditorTools.DrawSeparator();
InvbaseItem?item?=?null;
if?(db.items?==?null?||?db.items.Count?==?0)
{
mIndex?=?0;
}
else
{
mIndex?=?Mathf.Clamp(mIndex?0?db.items.Count?-?1);
item?=?db.items[mIndex];
}
if?(mConfirmDelete)
{
//?Show?the?confirmation?dialog
GUILayout.Label(“Are?you?sure?you?want?to?delete?‘“?+?item.name?+?“‘?“);
NGUIEditorTools.DrawSeparator();
GUILayout.BeginHorizontal();
{
GUI.backgroundColor?=?Color.green;
if?(GUILayout.Button(“Cancel“))?mConfirmDelete?=?false;
GUI.backgroundColor?=?Color.red;
if?(GUILayout.Button(“Delete“))
{
NGUIEditorTools.RegisterUndo(“Delete?Inventory?Item“?db);
db.items.RemoveAt(mIndex);
mConfirmDelete?=?false;
}
GUI.backgroundColor?=?Color.white;
}
GUILayout.EndHorizontal();
}
else
{
//?Database?icon?atlas
UIAtlas?atlas?=?EditorGUILayout.objectField(“Icon?Atlas“?db.iconAtlas?typeof(UIAtlas)?false)?as?UIAtlas;
if?(atlas?!=?db.iconAtlas)
{
NGUIEditorTools.RegisterUndo(“Databse?Atlas?change“?db);
db.iconAtlas?=?atlas;
foreach?(InvbaseItem?i?in?db.items)?i.iconAtlas?=?atlas;
}
//?Database?ID
int?dbID?=?EditorGUILayout.IntField(“Database?ID“?db.databaseID);
if?(dbID?!=?db.databaseID)
{
NGUIEditorTools.RegisterUndo(“Database?ID?change“?db);
db.databaseID?=?dbID;
}
//?“New“?button
GUI.backgroundColor?=?Color.green;
if?(GUILayout.Button(“New?Item“))
{
NGUIEditorTools.RegisterUndo(“Add?Inventory?Item“?db);
InvbaseItem?bi?=?new?InvbaseItem();
bi.iconAtlas?=?db.iconAtlas;
bi.id16?=?(db.items.Count?>?0)???db.items[db.items.Count?-?1].id16?+?1?:?0;
db.items.Add(bi);
mIndex?=?db.items.Count?-?1;
if?(item?!=?null)
{
bi.name?=?“Copy?of?“?+?item.name;
bi.description?=?item.description;
bi.slot?=?item.slot;
bi.color?=?item.color;
bi.iconName?=?item.iconName;
bi.attachment?=?item.attachment;
bi.minItemLevel?=?item.minItemLevel;
bi.maxItemLevel?=?item.maxItemLevel;
foreach?(InvStat?stat?in?item.sta
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????7589??2013-07-15?09:35??NGUI_protect\Assembly-CSharp-Editor-vs.csproj
?????文件???????7583??2013-07-15?09:35??NGUI_protect\Assembly-CSharp-Editor.csproj
?????文件??????87668??2013-07-15?09:38??NGUI_protect\Assembly-CSharp-Editor.pidb
?????文件??????13598??2013-07-15?16:17??NGUI_protect\Assembly-CSharp-vs.csproj
?????文件??????13598??2013-07-15?16:17??NGUI_protect\Assembly-CSharp.csproj
?????文件?????328540??2013-07-15?16:21??NGUI_protect\Assembly-CSharp.pidb
????I.A....?????63448??2013-07-15?16:20??NGUI_protect\Assets\Level\computers.unity
????I.A....?????11216??2012-08-23?05:49??NGUI_protect\Assets\NGUI\Examples\Animations\Button.anim
????I.A....?????10912??2012-08-23?05:49??NGUI_protect\Assets\NGUI\Examples\Animations\Checkmark.anim
????I.A....?????12904??2012-08-23?05:49??NGUI_protect\Assets\NGUI\Examples\Animations\Logo.anim
????I.A....?????11816??2012-08-23?05:48??NGUI_protect\Assets\NGUI\Examples\Animations\Window?-?Back.anim
????I.A....?????11704??2012-08-23?05:49??NGUI_protect\Assets\NGUI\Examples\Animations\Window?-?Forward.anim
????I.A....??????3546??2012-08-23?05:49??NGUI_protect\Assets\NGUI\Examples\Atlases\Fantasy\Fantasy?Atlas.mat
????I.A....??????7597??2012-08-23?05:49??NGUI_protect\Assets\NGUI\Examples\Atlases\Fantasy\Fantasy?Atlas.prefab
????I.A....???1192501??2012-08-23?05:49??NGUI_protect\Assets\NGUI\Examples\Atlases\Fantasy\Fantasy?Atlas.psd
????I.A....?????16006??2012-08-23?05:48??NGUI_protect\Assets\NGUI\Examples\Atlases\Fantasy\Fantasy?Font?-?Normal.prefab
????I.A....?????21846??2012-08-23?05:49??NGUI_protect\Assets\NGUI\Examples\Atlases\Fantasy\Fantasy?Font?-?Normal.txt
????I.A....???1654198??2012-08-23?05:49??NGUI_protect\Assets\NGUI\Examples\Atlases\Refractive\Refractive?Atlas?-?Bump.psd
????I.A....?????98430??2012-08-23?05:48??NGUI_protect\Assets\NGUI\Examples\Atlases\Refractive\Refractive?Atlas?-?Masks.psd
????I.A....??????4117??2012-08-23?05:49??NGUI_protect\Assets\NGUI\Examples\Atlases\Refractive\Refractive?Atlas.mat
????I.A....??????7185??2012-08-23?05:49??NGUI_protect\Assets\NGUI\Examples\Atlases\Refractive\Refractive?Atlas.prefab
????I.A....????354488??2012-08-23?05:48??NGUI_protect\Assets\NGUI\Examples\Atlases\Refractive\Refractive?Atlas.psd
????I.A....?????13878??2012-08-23?05:49??NGUI_protect\Assets\NGUI\Examples\Atlases\Refractive\Refractive?Font?-?Header.prefab
????I.A....?????37748??2012-08-23?05:49??NGUI_protect\Assets\NGUI\Examples\Atlases\Refractive\Refractive?Font?-?Header.txt
????I.A....?????13962??2012-08-23?05:49??NGUI_protect\Assets\NGUI\Examples\Atlases\Refractive\Refractive?Font?-?Normal.prefab
????I.A....?????31928??2012-08-23?05:49??NGUI_protect\Assets\NGUI\Examples\Atlases\Refractive\Refractive?Font?-?Normal.txt
????I.A....??????3672??2012-08-23?05:49??NGUI_protect\Assets\NGUI\Examples\Atlases\SciFi\SciFi?Atlas.mat
????I.A....??????7301??2012-08-23?05:48??NGUI_protect\Assets\NGUI\Examples\Atlases\SciFi\SciFi?Atlas.prefab
????I.A....????610522??2012-08-23?05:49??NGUI_protect\Assets\NGUI\Examples\Atlases\SciFi\SciFi?Atlas.psd
????I.A....?????13298??2012-08-23?05:49??NGUI_protect\Assets\NGUI\Examples\Atlases\SciFi\SciFi?Font?-?Header.prefab
............此處省略1727個文件信息
評論
共有 條評論