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=-1;
// 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(0,0);
public Texture img2;
Vector2 prop2=new Vector2(50,0);
public Texture img3;
Vector2 prop3=new Vector2(100,0);
public Texture img4;
Vector2 prop4=new Vector2(150,0);
public Texture img5;
Vector2 prop5=new Vector2(200,0);
public Texture img6;
Vector2 prop6=new Vector2(250,0);
Rect BeginGroupProp=new Rect(100,100,300,100);
//———————————
//定义快捷键面板变量
Rect BeginGroupF=new Rect(200,200,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 () {
Int_commodity=-1;
// Str_img=new Texture[]{img1,img2,img3,img4,img5,img6};
imgF1=imgF2=imgF3=img;
}
void Update () {
FKeyDown();
}
void OnGUI() {
GUI.skin=guiskin;
//道具
GUI.BeginGroup(BeginGroupProp);
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.EndGroup ();
GUI.BeginGroup (BeginGroupF); //快捷键
GUI.Button (new Rect(temp1.x,temp1.y,50,50),new GUIContent("F1",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();
chuanru();
if(KJJ(Int_commodity)&&Input.GetKeyUp(KeyCode.Mouse0))
{
if(second.x>BeginGroupF.x+temp1.x&&second.y>BeginGroupF.y+temp1.y&&second.x<(BeginGroupF.x+temp1.x+50)&&second.y<(BeginGroupF.y+temp1.y+50))
{
imgF1=KJJ(Int_commodity);
Int_commodity=-1;
}
else if(second.x>BeginGroupF.x+temp2.x&&second.y>BeginGroupF.y+temp2.y&&second.x<(BeginGroupF.x+temp2.x+50)&&second.y<(BeginGroupF.y+temp2.y+50))
{
imgF2=KJJ(Int_commodity);
Int_commodity=-1;
}
else if(second.x>BeginGroupF.x+temp3.x&&second.y>BeginGroupF.y+temp3.y&&second.x<(BeginGroupF.x+temp3.x+50)&&second.y<(BeginGroupF.y+temp3.y+50))
{
imgF3=KJJ(Int_commodity);
Int_commodity=-1;
}
else if(Input.GetKeyUp(KeyCode.Mouse0))
{
Int_commodity=-1;
}
}
}
int chuanru()
{
second = Event.current.mousePosition;
if(second.x>BeginGroupProp.x+prop1.x&&second.y>BeginGroupProp.y+prop1.y&&second.x<(BeginGroupProp.x+prop1.x+50)&&second.y<(BeginGroupProp.y+prop1.y+50)&&Input.GetKeyDown(KeyCode.Mouse0))
{
Int_commodity=1;
}
else if(second.x>BeginGroupProp.x+prop2.x&&second.y>BeginGroupProp.y+prop2.y&&second.x<(BeginGroupProp.x+prop2.x+50)&&second.y<(BeginGroupProp.y+prop2.y+50)&&Input.GetKeyDown(KeyCode.Mouse0))
{
Int_commodity=2;
}
else if(second.x>BeginGroupProp.x+prop3.x&&second.y>BeginGroupProp.y+prop3.y&&second.x<(BeginGroupProp.x+prop3.x+50)&&second.y<(BeginGroupProp.y+prop3.y+50)&&Input.GetKeyDown(KeyCode.Mouse0))
{
Int_commodity=3;
}
else if(second.x>BeginGroupProp.x+prop4.x&&second.y>BeginGroupProp.y+prop4.y&&second.x<(BeginGroupProp.x+prop4.x+50)&&second.y<(BeginGroupProp.y+prop4.y+50)&&Input.GetKeyDown(KeyCode.Mouse0))
{
Int_commodity=4;
}
else if(second.x>BeginGroupProp.x+prop5.x&&second.y>BeginGroupProp.y+prop5.y&&second.x<(BeginGroupProp.x+prop5.x+50)&&second.y<(BeginGroupProp.y+prop5.y+50)&&Input.GetKeyDown(KeyCode.Mouse0))
{
Int_commodity=5;
}
else if(second.x>BeginGroupProp.x+prop6.x&&second.y>BeginGroupProp.y+prop6.y&&second.x<(BeginGroupProp.x+prop6.x+50)&&second.y<(BeginGroupProp.y+prop6.y+50)&&Input.GetKeyDown(KeyCode.Mouse0))
{
Int_commodity=6;
}
return Int_commodity;
}
//快捷键-换图片
Texture KJJ(int ABC)
{
Texture img_img=new Texture();
switch (ABC)
{
case 1:
img_img=img1;
break;
case 2:
img_img=img2;
break;
case 3:
img_img=img3;
break;
case 4:
img_img=img4;
break;
case 5:
img_img=img5;
break;
case 6:
img_img=img6;
break;
}
second = Event.current.mousePosition ;
GUI.Label(new Rect(second.x,second.y,50,50),img_img);
return img_img;
}
void FKeyDown()
{
//F1
if(Input.GetKey(KeyCode.F1))
{
if(imgF1==img1)
{
print("img1");
}else if(imgF1==img2)
{
print("img2");
}else if(imgF1==img3)
{
print("img3");
}else if(imgF1==img4)
{
print("img4");
}else if(imgF1==img5)
{
print("img5");
}else if(imgF1==img6)
{
print("img6");
}
}
//F2
if(Input.GetKey(KeyCode.F2))
{
if(imgF2==img1)
{
print("img1");
}
else if(imgF2==img2)
{
print("img2");
}
else if(imgF2==img3)
{
print("img3");
}
else if(imgF2==img4)
{
print("img4");
}
else if(imgF2==img5)
{
print("img5");
}
else if(imgF2==img6)
{
print("img6");
}
}
//F3
if(Input.GetKey(KeyCode.F3))
{
if(imgF3==img1)
{
print("img1");
}
else if(imgF3==img2)
{
print("img2");
}
else if(imgF3==img3)
{
print("img3");
}
else if(imgF3==img4)
{
print("img4");
}
else if(imgF3==img5)
{
print("img5");
}
else if(imgF3==img6)
{
print("img6");
}
}
}
}