当前位置:编程学习 > wap >>

一个关于U3d的GUI的问题

我把源代码 给大家发一下 你们看看 这是哪里错了    这是一个u3d中用GUI做的一个界面
大家注意我在Start()初始化的方法中  注释了一个if语句 在我没有注释之前这个还是运行成功的
但是在我加了这句话之后   整个U3d软件死机了  不能动了 运行不了不说 而且把整个软件关都关不上了  需要从任务管理器中关闭整个软件才行  这是为什么 哪位大神 给看看 
public class Item
{
public var icon:Texture;
public var name:String;
public var amount:int;

var itemName:String;

public function SetUpItemName()
{
var inLength:int = this.name.Length + this.amount.ToString().Length;

if(inLength<25)
{
while(this.name.Length<17)
this.name += "";
}

if(inLength<10)
itemName = this.name +" "+ this.amount.ToString();
else 
itemName = this.name + this.amount.ToString();
}

public function GetItemName()
{
return itemName;
}


}

public var customSkin:GUISkin;
public var tHero:Texture;

public var tStatusBox1:Texture;
public var tStatusBox2:Texture;
public var tSkillBox:Texture;

public var fullHP:int = 9999;
public var fullMP:int = 999;
public var currentHP:int = 9999;
public var currentMP:int = 999;
public var currentLV:int = 99;
public var currentEXP:int = 9999999;
public var currentNEXT:int = 99999;
public var currentATK:int = 999;
public var currentDEF:int = 999;
public var currentAGI:int = 999; 
public var currentINT:int = 999;
public var currentLUC:int = 999;

private var atkLabel:Rect = new Rect(529,70,50,25);
private var defLabel:Rect = new Rect(529,95,50,25);
private var agiLabel:Rect = new Rect(529,119,50,25);
private var intLabel:Rect = new Rect(529,150,50,25);
private var lucLabel:Rect = new Rect(529,177,50,25);

private var statTexture1:Rect = new Rect(252,77,331,125);
private var statTexture2:Rect = new Rect(252,244,331,125);
private var hpLabel:Rect = new Rect(313,70,120,25);
private var mpLabel:Rect = new Rect(313,95,120,25);
private var lvLabel:Rect = new Rect(313,119,120,25);
private var expLabel:Rect = new Rect(313,150,120,25);
private var nextLabel:Rect = new Rect(313,173,120,25);

private var uneuip:String = "UNEQUIP";

private var weaponLabel:Rect = new Rect(252,264,180,40);
private var armorLabel:Rect = new Rect(252,324,180,40);
private var accessLabel:Rect = new Rect(252,386,180,40);
private var skillTexture:Rect = new Rect(464,288,119,117);
private var skillBox:Rect = new Rect(460,284,117,125);

private var bOpenMenu:boolean = false;
private var myWindow:Rect = new Rect(10,10,640,480);
private var closeButton:Rect = new Rect(598,8,26,22);
private var tabButton:Rect = new Rect(35,15,490,40);
private var inToolBar:int = 0;
private var sToolbars:String[] = ["STA-US","INVENTORY","EQUIPMENT"];

private var rHero:Rect = new Rect(19,35,225,441);
private var stateBox:Rect = new Rect(237,57,360,155);
private var weaponBox:Rect = new Rect(237,230,360,207);

private var guiWeaponCon:GUIContent;
private var guiArmorCon:GUIContent;
private var guiAccessCon:GUIContent;
private var guiSkillCon:GUIContent;

private var stateTexture1:Rect = new Rect(252,71,331,125);
private var stateTexture2:Rect = new Rect(252,244,331,125);

private var rItemBox:Rect = new Rect(237,67,360,247);
private var rTipBox:Rect = new Rect(237,330,360,107);
private var rItemsButton:Rect = new Rect(257,67,340,227);
private var rTipButton:Rect = new Rect(257,350,340,87);
private var rVerScroll:Rect = new Rect(600,87,20,227);

private var fScrollFos:float = 1.0f;
private var scrollPosition:Vector2 = Vector2.zero;
private var scrollPosition2:Vector2 = Vector2.zero;

public var items:Item[];
private var currentItem:Item;
private var inToolItems:int = 0;




function Start()
{
bOpenMenu = false;

guiWeaponCon = GUIContent(uneuip);
guiArmorCon = GUIContent(uneuip);
guiAccessCon = GUIContent(uneuip);
guiSkillCon = GUIContent("");

/* if(items.Length>0)
{
items[0].SetUpItemName();
currentItem=items[0];
}
*/
}

function Update()
{
if(Input.GetKey(KeyCode.M))
bOpenMenu = true;
}

function OnGUI()
{
      

GUI.skin = customSkin;
if(bOpenMenu)
{
myWindow = GUI.Window(0,myWindow,DoMyWindow,"");

myWindow.x = Mathf.Clamp(myWindow.x,0.0,Screen.width-myWindow.width);
myWindow.y = Mathf.Clamp(myWindow.y,0.0,Screen.height-myWindow.height);
}
}

function DoMyWindow(windowsId:int)
{


inToolBar = GUI.Toolbar(tabButton,inToolBar,sToolbars,GUI.skin.GetStyle("TabButton"));

switch(inToolBar)
{
case 0:
StatusWindow();
break;
case 1:
 ItemWindow();
break;
case 2:
break;
}

if(GUI.Button(closeButton,"",GUI.skin.GetStyle("ExitButton")))
bOpenMenu = false;

GUI.DragWindow();
GUI.DrawTexture(rHero,tHero);


}

public function StatusWindow()
{
GUI.Box(stateBox,"");
GUI.Box(weaponBox,"");
GUI.DrawTexture(stateTexture1,tStatusBox1);
GUI.DrawTexture(stateTexture2,tStatusBox2);
GUI.DrawTexture(skillBox,tSkillBox);

GUI.Label(hpLabel,currentHP.ToString()+"/"+fullHP.ToString(),"TextAmount");
GUI.Label(mpLabel,currentMP.ToString()+"/"+fullMP.ToString(),"TextAmount");
GUI.Label(lvLabel,currentLV.ToString(),"TextAmount");
GUI.Label(expLabel,currentEXP.ToString(),"TextAmount");
GUI.Label(nextLabel,currentNEXT.ToString(),"TextAmount");
GUI.Label(atkLabel,currentATK.ToString(),"TextAmount");
GUI.Label(defLabel,currentDEF.ToString(),"TextAmount");
GUI.Label(agiLabel,currentAGI.ToString(),"TextAmount");
GUI.Label(intLabel,currentINT.ToString(),"TextAmount");



GUI.Label(lucLabel,currentLUC.ToString());

GUI.Label(weaponLabel,guiWeaponCon,"TextItem");

GUI.Label(armorLabel,guiArmorCon,"TextItem");

GUI.Label(accessLabel,guiAccessCon,"TextItem");

GUI.Label(skillTexture,guiSkillCon,"TextItem");
}

public function ItemWindow()
{
var aa:GUIStyle = new GUIStyle();
aa.fontSize = 15;
aa.normal.textColor = Color.black;
  
var inItems:int = 8;
GUI.Box(rItemBox,"");
GUI.Box(rTipBox,"");

scrollPosition = GUI.BeginScrollView(new Rect(257,87,320,200),scrollPosition,new Rect(0,0,230,40*inItems)); 

var itemsContent:GUIContent[] = new GUIContent[inItems];

for(var i:int=0;i<inItems;i++)
{
if(items.Length>0)
{
if(i==0)
itemsContent[i]=GUIContent(currentItem.itemName,currentItem.icon,"This is test text  This is test text  This is test text  This is test text  This is test text");
else
itemsContent[i]=GUIContent(currentItem.itemName,currentItem.icon,"This is key" + i);
}
else 
itemsContent[i] = GUIContent("NONE","");
}

inToolItems = GUI.SelectionGrid(new Rect(0,0,280,40*inItems),inToolItems,itemsContent,1,GUI.skin.GetStyle("SelectedItem"));

GUI.EndScrollView();

var sInfo:String = itemsContent[inToolItems].tooltip;

if(sInfo == "")
sInfo = "show item information here";

var style:GUIStyle = GUI.skin.GetStyle("label");

if(GUI.tooltip != "")
{
var fHeight:float = style.CalcHeight(GUIContent(GUI.tooltip),330.0);

scrollPosition2 = GUI.BeginScrollView(new Rect(257,343,320,75),scrollPosition2,new Rect(0,0,280,fHeight));

GUI.Label(new Rect(0,0,280,fHeight),GUI.tooltip);
}
else 
{
fHeight = style.CalcHeight(GUIContent(sInfo),330.0);

scrollPosition2 = GUI.BeginScrollView(new Rect(257,343,320,75),scrollPosition2,new Rect(0,0,280,fHeight));

GUI.Label(new Rect(0,0,280,fHeight),sInfo,aa);
}

GUI.EndScrollView();

} Unity3D
补充:移动开发 ,  Android
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,