查看: 2888|回复: 0
打印 上一主题 下一主题

道具栏的图标 拖到 快捷键

[复制链接]

5552

主题

2

听众

8万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
11

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2012-2-16 14:25:16 |只看该作者 |倒序浏览
using UnityEngine;

using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
public GUISkin guiskin;



//~ public GUIStyle closedButton;



public GUIStyle boxbg;







public int Int_F;     //快捷键



string [] Str=new string[]{"F1","F2","F3"};







public int Int_commodity;



string [] Str_commodity=new string[]{"物品1","物品2","物品3","物品4","物品5","物品6",};







//定义道具栏面板变量



public Texture img;



Vector2 prop=new Vector2(0,100);



public Texture img1;



Vector2 prop1=new Vector2(50,100);



public Texture img2;



Vector2 prop2=new Vector2(100,100);



public Texture img3;



Vector2 prop3=new Vector2(150,100);



public Texture img4;



Vector2 prop4=new Vector2(200,100);



public Texture img5;



Vector2 prop5=new Vector2(250,100);



public Texture img6;



Vector2 prop6=new Vector2(300,100);
//---------------------------------



//定义快捷键面板变量



public Texture imgF1;



Vector2 temp1=new Vector2(0,0);



public Texture imgF2;



Vector2 temp2=new Vector2(50,0);



public Texture imgF3;



Vector2 temp3=new Vector2(100,0);
//---------------------------------











Vector2 second = Vector2.zero;



int Int_img;







Texture [] Str_img;







// Use this for initialization



void Start () {



Str_img=new Texture[]{img1,img2,img3,img4,img5,img6};



imgF1=imgF2=imgF3=img;



}
void Update () {







}







void OnGUI() {



   GUI.skin=guiskin;
  



   //道具



   GUI.Button (new Rect(prop1.x,prop1.y,50,50), img1);



   GUI.Button (new Rect(prop2.x,prop2.y,50,50), img2);



   GUI.Button (new Rect(prop3.x,prop3.y,50,50), img3);



   GUI.Button (new Rect(prop4.x,prop4.y,50,50), img4);



   GUI.Button (new Rect(prop5.x,prop5.y,50,50), img5);



   GUI.Button (new Rect(prop6.x,prop6.y,50,50), img6);



  



  



  



   GUI.BeginGroup (new Rect(0,0,200,250));               //快捷键



    GUI.Button (new Rect(temp1.x,temp1.y,50,50), imgF1);



    GUI.Button (new Rect(temp2.x,temp2.y,50,50), imgF2);



    GUI.Button (new Rect(temp3.x,temp3.y,50,50), imgF3);



   GUI.EndGroup();



  
   chua***();



    if(KJJ(Int_commodity)&&Input.GetKeyUp(KeyCode.Mouse0))



    {



     if(second.x>temp1.x&&second.y>temp1.y&&second.x<(temp1.x+50)&&second.y<(temp1.y+50))



     {



      imgF1=KJJ(Int_commodity);



      Int_commodity=-1;



     }



     else if(second.x>temp2.x&&second.y>temp2.y&&second.x<(temp2.x+50)&&second.y<(temp2.y+50))



     {



      imgF2=KJJ(Int_commodity);



      Int_commodity=-1;



     }



     else if(second.x>temp3.x&&second.y>temp3.y&&second.x<(temp3.x+50)&&second.y<(temp3.y+50))



     {



      imgF3=KJJ(Int_commodity);



      Int_commodity=-1;



     }



     else if(Input.GetKeyUp(KeyCode.Mouse0))



     {



      Int_commodity=-1;



     }



    }
}



   int chua***()



   {



    second = Event.current.mousePosition;
    if(second.x>prop1.x&&second.y>prop1.y&&second.x<(prop1.x+50)&&second.y<(prop1.y+50)&&Input.GetKey(KeyCode.Mouse0))



    {



     Int_commodity=0;



    }



    else if(second.x>prop2.x&&second.y>prop2.y&&second.x<(prop2.x+50)&&second.y<(prop2.y+50)&&Input.GetKey(KeyCode.Mouse0))



    {



     Int_commodity=1;



    }



    else if(second.x>prop3.x&&second.y>prop3.y&&second.x<(prop3.x+50)&&second.y<(prop3.y+50)&&Input.GetKey(KeyCode.Mouse0))



    {



     Int_commodity=2;



    }



    else if(second.x>prop4.x&&second.y>prop4.y&&second.x<(prop4.x+50)&&second.y<(prop4.y+50)&&Input.GetKey(KeyCode.Mouse0))



    {



     Int_commodity=3;



    }



    else if(second.x>prop5.x&&second.y>prop5.y&&second.x<(prop5.x+50)&&second.y<(prop5.y+50)&&Input.GetKey(KeyCode.Mouse0))



    {



     Int_commodity=4;



    }



    else if(second.x>prop6.x&&second.y>prop6.y&&second.x<(prop6.x+50)&&second.y<(prop6.y+50)&&Input.GetKey(KeyCode.Mouse0))



    {



     Int_commodity=5;



    }



   



    return Int_commodity;



   }







   Texture KJJ(int ABC)



   {



    Texture img_img=new Texture();



    switch (ABC)



    {



     case 0:



      img_img=img1;



     break;



     case 1:



      img_img=img2;



     break;



     case 2:



      img_img=img3;



     break;



     case 3:



      img_img=img4;



     break;



     case 4:



      img_img=img5;



     break;



     case 5:



      img_img=img6;



     break;



    }



    second = Event.current.mousePosition ;



    GUI.Label(new Rect(second.x,second.y,50,50),img_img);



    return img_img;



   }



}



转自unity3d8.com
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2024-11-13 09:41 , Processed in 0.090755 second(s), 33 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部