Поднятия предмета в инвентарь - Форум - Все для Unity3d

Все для Unity3d> Поднятия предмета в инвентарь - Форум>
Страница 1 из 11
Форум » Unity » Вопросы » Поднятия предмета в инвентарь (Поможеш? дам +сик!)
Поднятия предмета в инвентарь
ZayRoxДата: Пятница, 08.08.2014, 20:15 | Сообщение # 1
Новый писатель
Группа: Пользователи
Сообщений: 1
Статус: Offline
Как сделать так чтоб можно было поднять предмет в инвентар, (нажал "Е" и объект появляется в инвентаре) С меня +сик.

Код:

Код
using System.Collections.Generic;
using UnityEngine;

public class Inventory : MonoBehaviour {
       
     public List<Items> item = new List<Items>();
     public activinvent Activ;
     private Vector2 scrollPosition = Vector2.zero;
     public Items select;
     public SlotsMenu Slot;
       
     void Update () {
     if(Input.GetKeyDown("i") && Activ.Inventory){
     Activ.Inventory   = false;
     }else{
     if(Input.GetKeyDown("i") && !Activ.Inventory){
     Activ.Inventory   = true;     
     }
     }
     }
       
     void OnGUI ()  {
     if(Activ.Inventory)
     UserInventor();
          
     if(select != null && select.id >0){
     InfoSelect();     
     }

     if(new Rect(0,0,Screen.width,Screen.height).Contains(Event.current.mousePosition) && select != null && !Activ.ItemDrag){
     select = null;
     }     
     SlotsControl();
      }

       
     void SlotsControl(){
      if(new Rect(Screen.width/2-210, Screen.height/1-70,64,64).Contains(Event.current.mousePosition)&&Activ.ItemDrag){
     if(Slot.Slot1.Icons == null){
     Slot.Slot1.Name = select.Name;
     Slot.Slot1.id = select.id;
     Slot.Slot1.Icons = select.Icons;
     }else{
     removeEffect(Slot.Slot1);
     Slot.Slot1.Name = select.Name;
     Slot.Slot1.id = select.id;
     Slot.Slot1.Icons = select.Icons;
     }
     if(Slot.Slot2.Name == Slot.Slot1.Name){
     removeEffect(Slot.Slot2);           
     }
      if(Slot.Slot3.Name == Slot.Slot1.Name){
     removeEffect(Slot.Slot3);           
     }
     if(Slot.Slot4.Name == Slot.Slot1.Name){
     removeEffect(Slot.Slot4);           
     }           
     if(Slot.Slot5.Name == Slot.Slot1.Name){
     removeEffect(Slot.Slot5);           
     }           
     if(Slot.Slot6.Name == Slot.Slot1.Name){
     removeEffect(Slot.Slot6);           
     }           
     }
          
     if(new Rect(Screen.width/2-210 + 70, Screen.height/1-70,64,64).Contains(Event.current.mousePosition)&&Activ.ItemDrag){
     if(Slot.Slot2.Icons == null){
     Slot.Slot2.Name = select.Name;
     Slot.Slot2.id = select.id;
     Slot.Slot2.Icons = select.Icons;
     }else{
     removeEffect(Slot.Slot2);
     Slot.Slot2.Name = select.Name;
     Slot.Slot2.id = select.id;
     Slot.Slot2.Icons = select.Icons;
     }
     if(Slot.Slot1.Name == Slot.Slot2.Name){
     removeEffect(Slot.Slot1);           
     }
      if(Slot.Slot3.Name == Slot.Slot2.Name){
     removeEffect(Slot.Slot3);           
     }
     if(Slot.Slot4.Name == Slot.Slot2.Name){
     removeEffect(Slot.Slot4);           
     }           
     if(Slot.Slot5.Name == Slot.Slot2.Name){
     removeEffect(Slot.Slot5);           
     }           
     if(Slot.Slot6.Name == Slot.Slot2.Name){
     removeEffect(Slot.Slot6);           
     }     
     }
          
     if(new Rect(Screen.width/2-210 + 140, Screen.height/1-70,64,64).Contains(Event.current.mousePosition)&&Activ.ItemDrag){
     if(Slot.Slot3.Icons == null){
     Slot.Slot3.Name = select.Name;
     Slot.Slot3.id = select.id;
     Slot.Slot3.Icons = select.Icons;
     }else{
     removeEffect(Slot.Slot3);
     Slot.Slot3.Name = select.Name;
     Slot.Slot3.id = select.id;
     Slot.Slot3.Icons = select.Icons;
     }
     if(Slot.Slot1.Name == Slot.Slot3.Name){
     removeEffect(Slot.Slot1);           
     }
      if(Slot.Slot2.Name == Slot.Slot3.Name){
     removeEffect(Slot.Slot2);           
     }
     if(Slot.Slot4.Name == Slot.Slot3.Name){
     removeEffect(Slot.Slot4);           
     }           
     if(Slot.Slot5.Name == Slot.Slot3.Name){
     removeEffect(Slot.Slot5);           
     }           
     if(Slot.Slot6.Name == Slot.Slot3.Name){
     removeEffect(Slot.Slot6);           
     }
     }
          
     if(new Rect(Screen.width/2-210 + 210, Screen.height/1-70,64,64).Contains(Event.current.mousePosition)&&Activ.ItemDrag){
     if(Slot.Slot4.Icons == null){
     Slot.Slot4.Name = select.Name;
     Slot.Slot4.id = select.id;
     Slot.Slot4.Icons = select.Icons;
     }else{
     removeEffect(Slot.Slot4);
     Slot.Slot4.Name = select.Name;
     Slot.Slot4.id = select.id;
     Slot.Slot4.Icons = select.Icons;
     }
     if(Slot.Slot1.Name == Slot.Slot4.Name){
     removeEffect(Slot.Slot1);           
     }
      if(Slot.Slot2.Name == Slot.Slot4.Name){
     removeEffect(Slot.Slot2);           
     }
     if(Slot.Slot3.Name == Slot.Slot4.Name){
     removeEffect(Slot.Slot3);           
     }           
     if(Slot.Slot5.Name == Slot.Slot4.Name){
     removeEffect(Slot.Slot5);           
     }           
     if(Slot.Slot6.Name == Slot.Slot4.Name){
     removeEffect(Slot.Slot6);           
     }
     }
          
     if(new Rect(Screen.width/2-210 + 280, Screen.height/1-70,64,64).Contains(Event.current.mousePosition)&&Activ.ItemDrag){
     if(Slot.Slot5.Icons == null){
     Slot.Slot5.Name = select.Name;
     Slot.Slot5.id = select.id;
     Slot.Slot5.Icons = select.Icons;
     }else{
     removeEffect(Slot.Slot5);
     Slot.Slot5.Name = select.Name;
     Slot.Slot5.id = select.id;
     Slot.Slot5.Icons = select.Icons;
     }
     if(Slot.Slot1.Name == Slot.Slot5.Name){
     removeEffect(Slot.Slot1);           
     }
      if(Slot.Slot2.Name == Slot.Slot5.Name){
     removeEffect(Slot.Slot2);           
     }
     if(Slot.Slot3.Name == Slot.Slot5.Name){
     removeEffect(Slot.Slot3);           
     }           
     if(Slot.Slot4.Name == Slot.Slot5.Name){
     removeEffect(Slot.Slot4);           
     }           
     if(Slot.Slot6.Name == Slot.Slot5.Name){
     removeEffect(Slot.Slot6);           
     }
     }
          
     if(new Rect(Screen.width/2-210 + 350, Screen.height/1-70,64,64).Contains(Event.current.mousePosition)&&Activ.ItemDrag){
     if(Slot.Slot6.Icons == null){
     Slot.Slot6.Name = select.Name;
     Slot.Slot6.id = select.id;
     Slot.Slot6.Icons = select.Icons;
     }else{
     removeEffect(Slot.Slot6);
     Slot.Slot6.Name = select.Name;
     Slot.Slot6.id = select.id;
     Slot.Slot6.Icons = select.Icons;
     }
     if(Slot.Slot1.Name == Slot.Slot6.Name){
     removeEffect(Slot.Slot1);           
     }
      if(Slot.Slot2.Name == Slot.Slot6.Name){
     removeEffect(Slot.Slot2);           
     }
     if(Slot.Slot3.Name == Slot.Slot6.Name){
     removeEffect(Slot.Slot3);           
     }           
     if(Slot.Slot4.Name == Slot.Slot6.Name){
     removeEffect(Slot.Slot4);           
     }           
     if(Slot.Slot5.Name == Slot.Slot6.Name){
     removeEffect(Slot.Slot5);           
     }
     }
          
     if(Slot.Slot1.Icons == null){
     GUI.Box(new Rect(Screen.width/2-210, Screen.height/1-70,64,64),"");
     GUI.Label(new Rect(Screen.width/2-210, Screen.height/1-70,64,64),"");
     }else{
     if(GUI.Button(new Rect(Screen.width/2-210, Screen.height/1-70,64,64),Slot.Slot1.Icons)){
     removeEffect(Slot.Slot1);
     }
     GUI.Label(new Rect(Screen.width/2-210, Screen.height/1-70,64,64),"");
     if(Slot.Slot1.id < 10)
     GUI.Label(new Rect(Screen.width/2-210+43, Screen.height/1-70+40,64,64),"x"+Slot.Slot1.id);
     if(Slot.Slot1.id < 100 && Slot.Slot1.id > 9)
     GUI.Label(new Rect(Screen.width/2-210+35, Screen.height/1-70+40,64,64),"x"+Slot.Slot1.id);
     if(Slot.Slot1.id < 1000 && Slot.Slot1.id > 99)
     GUI.Label(new Rect(Screen.width/2-210+29, Screen.height/1-70+40,64,64),"x"+Slot.Slot1.id);
     if(Slot.Slot1.id < 10000 && Slot.Slot1.id > 999)
     GUI.Label(new Rect(Screen.width/2-210+21, Screen.height/1-70+40,64,64),"x"+Slot.Slot1.id);
     }
     if(Slot.Slot2.Icons == null){
     GUI.Box(new Rect(Screen.width/2-210 + 70, Screen.height/1-70,64,64),"");
     GUI.Label(new Rect(Screen.width/2-210 + 70, Screen.height/1-70,64,64),"");
     }else{
     if(GUI.Button(new Rect(Screen.width/2-210 + 70, Screen.height/1-70,64,64),Slot.Slot2.Icons)){
     removeEffect(Slot.Slot2);           
     }
     GUI.Label(new Rect(Screen.width/2-210 + 70, Screen.height/1-70,64,64),"");
     if(Slot.Slot2.id < 10)
     GUI.Label(new Rect(Screen.width/2-210+43+ 70, Screen.height/1-70+40,64,64),"x"+Slot.Slot2.id);
     if(Slot.Slot2.id < 100 && Slot.Slot2.id > 9)
     GUI.Label(new Rect(Screen.width/2-210+35+ 70, Screen.height/1-70+40,64,64),"x"+Slot.Slot2.id);
     if(Slot.Slot2.id < 1000 && Slot.Slot2.id > 99)
     GUI.Label(new Rect(Screen.width/2-210+29+ 70, Screen.height/1-70+40,64,64),"x"+Slot.Slot2.id);
     if(Slot.Slot2.id < 10000 && Slot.Slot2.id > 999)
     GUI.Label(new Rect(Screen.width/2-210+21+ 70, Screen.height/1-70+40,64,64),"x"+Slot.Slot2.id);
     }     
     if(Slot.Slot3.Icons == null){
     GUI.Box(new Rect(Screen.width/2-210 + 140, Screen.height/1-70,64,64),"");
     GUI.Label(new Rect(Screen.width/2-210 + 140, Screen.height/1-70,64,64),"");
     }else{
     if(GUI.Button(new Rect(Screen.width/2-210 + 140, Screen.height/1-70,64,64),Slot.Slot3.Icons)){
     removeEffect(Slot.Slot3);           
     }
     GUI.Label(new Rect(Screen.width/2-210 + 140, Screen.height/1-70,64,64),"");
     if(Slot.Slot3.id < 10)
     GUI.Label(new Rect(Screen.width/2-210+43+ 140, Screen.height/1-70+40,64,64),"x"+Slot.Slot3.id);
     if(Slot.Slot3.id < 100 && Slot.Slot3.id > 9)
     GUI.Label(new Rect(Screen.width/2-210+35+ 140, Screen.height/1-70+40,64,64),"x"+Slot.Slot3.id);
     if(Slot.Slot3.id < 1000 && Slot.Slot3.id > 99)
     GUI.Label(new Rect(Screen.width/2-210+29+ 140, Screen.height/1-70+40,64,64),"x"+Slot.Slot3.id);
     if(Slot.Slot3.id < 10000 && Slot.Slot3.id > 999)
     GUI.Label(new Rect(Screen.width/2-210+21+ 140, Screen.height/1-70+40,64,64),"x"+Slot.Slot3.id);
     }
     if(Slot.Slot4.Icons == null){
     GUI.Box(new Rect(Screen.width/2-210 + 210, Screen.height/1-70,64,64),"");
     GUI.Label(new Rect(Screen.width/2-210 + 210, Screen.height/1-70,64,64),"");
     }else{
     if(GUI.Button(new Rect(Screen.width/2-210 + 210, Screen.height/1-70,64,64),Slot.Slot4.Icons)){
     removeEffect(Slot.Slot4);           
     }
     GUI.Label(new Rect(Screen.width/2-210 + 210, Screen.height/1-70,64,64),"");
     if(Slot.Slot4.id < 10)
     GUI.Label(new Rect(Screen.width/2-210+43+ 210, Screen.height/1-70+40,64,64),"x"+Slot.Slot4.id);
     if(Slot.Slot4.id < 100 && Slot.Slot4.id > 9)
     GUI.Label(new Rect(Screen.width/2-210+35+ 210, Screen.height/1-70+40,64,64),"x"+Slot.Slot4.id);
     if(Slot.Slot4.id < 1000 && Slot.Slot4.id > 99)
     GUI.Label(new Rect(Screen.width/2-210+29+ 210, Screen.height/1-70+40,64,64),"x"+Slot.Slot4.id);
     if(Slot.Slot4.id < 10000 && Slot.Slot4.id > 999)
     GUI.Label(new Rect(Screen.width/2-210+21+ 210, Screen.height/1-70+40,64,64),"x"+Slot.Slot4.id);
     }
     if(Slot.Slot5.Icons == null){
     GUI.Box(new Rect(Screen.width/2-210 + 280, Screen.height/1-70,64,64),"");
     GUI.Label(new Rect(Screen.width/2-210 + 280, Screen.height/1-70,64,64),"");
     }else{
     if(GUI.Button(new Rect(Screen.width/2-210 + 280, Screen.height/1-70,64,64),Slot.Slot5.Icons)){
     removeEffect(Slot.Slot5);           
     }
     GUI.Label(new Rect(Screen.width/2-210 + 280, Screen.height/1-70,64,64),"");
     if(Slot.Slot5.id < 10)
     GUI.Label(new Rect(Screen.width/2-210+43+ 280, Screen.height/1-70+40,64,64),"x"+Slot.Slot5.id);
     if(Slot.Slot5.id < 100 && Slot.Slot5.id > 9)
     GUI.Label(new Rect(Screen.width/2-210+35+ 280, Screen.height/1-70+40,64,64),"x"+Slot.Slot5.id);
     if(Slot.Slot5.id < 1000 && Slot.Slot5.id > 99)
     GUI.Label(new Rect(Screen.width/2-210+29+ 280, Screen.height/1-70+40,64,64),"x"+Slot.Slot5.id);
     if(Slot.Slot5.id < 10000 && Slot.Slot5.id > 999)
     GUI.Label(new Rect(Screen.width/2-210+21+ 280, Screen.height/1-70+40,64,64),"x"+Slot.Slot5.id);
     }
     if(Slot.Slot6.Icons == null){
     GUI.Box(new Rect(Screen.width/2-210 + 350, Screen.height/1-70,64,64),"");
     GUI.Label(new Rect(Screen.width/2-210 + 350, Screen.height/1-70,64,64),"");
     }else{
     if(GUI.Button(new Rect(Screen.width/2-210 + 350, Screen.height/1-70,64,64),Slot.Slot6.Icons)){
     removeEffect(Slot.Slot6);           
     }
     GUI.Label(new Rect(Screen.width/2-210 + 350, Screen.height/1-70,64,64),"");
     if(Slot.Slot6.id < 10)
     GUI.Label(new Rect(Screen.width/2-210+43+ 350, Screen.height/1-70+40,64,64),"x"+Slot.Slot6.id);
     if(Slot.Slot6.id < 100 && Slot.Slot6.id > 9)
     GUI.Label(new Rect(Screen.width/2-210+35+ 350, Screen.height/1-70+40,64,64),"x"+Slot.Slot6.id);
     if(Slot.Slot6.id < 1000 && Slot.Slot6.id > 99)
     GUI.Label(new Rect(Screen.width/2-210+29+ 350, Screen.height/1-70+40,64,64),"x"+Slot.Slot6.id);
     if(Slot.Slot6.id < 10000 && Slot.Slot6.id > 999)
     GUI.Label(new Rect(Screen.width/2-210+21+ 350, Screen.height/1-70+40,64,64),"x"+Slot.Slot6.id);
     }
          
     }
       
     void UserInventor()  {
     GUI.Box (new Rect(Screen.width/2-220,Screen.height/2-110,440,310),"asdadasdasda");
     GUI.Label (new Rect(Screen.width/2-210,Screen.height/2-110,100,30),"Backpack");     
       
       
     scrollPosition = GUI.BeginScrollView(new Rect(Screen.width/2-220,Screen.height/2-80,440,270),scrollPosition, new Rect(Screen.width/2-220,Screen.height/2-80,10,13*item.Count));     
     int y = 0;
     int x = 0;

     if(item.Count > 0)
     {
     foreach(Items it in item)
     {
     if(it.rect.x == 0 && it.rect.y == 0)
     it.rect = new Rect(Screen.width/2-210 + 70 * x, Screen.height/2-80+70 * y,64,64);
     if(it.id != 0){
                
     //if(!Activ.Drag && it != select){
     if(!it.Drag){
     if(GUI.Button(new Rect(it.rect),it.Icons))
     {
                 
     }
     if(it.id < 10)
     GUI.Label(new Rect(it.rect.x+43,it.rect.y+40,64,64),"x"+it.id);
     if(it.id < 100 && it.id > 9)
     GUI.Label(new Rect(it.rect.x+35,it.rect.y+40,64,64),"x"+it.id);
     if(it.id < 1000 && it.id > 99)
     GUI.Label(new Rect(it.rect.x+29,it.rect.y+40,64,64),"x"+it.id);
     if(it.id < 10000 && it.id > 999)
     GUI.Label(new Rect(it.rect.x+21,it.rect.y+40,64,64),"x"+it.id);
     }else{
     GUI.Box(new Rect(it.rect),"");                 
     }
                   
     if(!it.Drag && !Activ.ItemDrag){
     if(new Rect(it.rect).Contains(Event.current.mousePosition))
     select = it;
     }else{
                      
     }
     //Debug.Log (item.IndexOf(it));
             
     }else{
     GUI.Box(new Rect(it.rect),"");              
     }
     ++x;
     if(x > 5){
     y++;
     x = 0;
     }
     if(Activ.ItemDrag){
     if(new Rect(it.rect).Contains(Event.current.mousePosition)){
     if(Input.GetMouseButtonUp(0)){
     Rect old = select.rect;
     Rect New = it.rect;
     it.rect = old;
     select.rect = New;                       
     }
     }
     }
     }
     }
GUI.EndScrollView ();
}
       
void InfoSelect(){
if(Input.GetMouseButtonDown(0)){
select.Drag = true;     
Activ.ItemDrag = true;
}
if(Input.GetMouseButtonUp(0) && select.Drag){
select.Drag = false;
Activ.ItemDrag = false;
if(select.Name == Slot.Slot1.Name){
select.id = 0;
}
if(select.Name == Slot.Slot2.Name){
select.id = 0;
}
if(select.Name == Slot.Slot3.Name){
select.id = 0;
}
if(select.Name == Slot.Slot4.Name){
select.id = 0;
}
if(select.Name == Slot.Slot5.Name){
select.id = 0;
}
if(select.Name == Slot.Slot6.Name){
select.id = 0;
}
}

if(!select.Drag){
GUI.BeginGroup(new Rect(Input.mousePosition.x, Screen.height - Input.mousePosition.y, 164, 70));
GUI.Box(new Rect(0,0, 164, 70), "");
if(select.Icons != null)
GUI.DrawTexture(new Rect(10,10,50,50),select.Icons);
GUI.Label (new Rect(65,20,70,50),select.Name);// вверх,на середину,далее ОК
GUI.EndGroup();
}else{
GUI.DrawTexture(new Rect(Input.mousePosition.x - 30, Screen.height - Input.mousePosition.y - 30,64,64),select.Icons);
Activ.ItemDrag = true;
}
}
       
void removeEffect(Items it){
foreach(Items s in item){
if(s.Name == it.Name){
s.Name = it.Name;
s.Icons = it.Icons;
s.id = it.id;
it.Name = "";
it.Icons = null;
it.id = 0;
return;
}
}        
}
       
[System.Serializable]
public class activinvent
{
public bool Inventory;
public bool ItemDrag;
}

[System.Serializable]
public class SlotsMenu
{
public Items Slot1 = null;
public Items Slot2 = null;
public Items Slot3 = null;
public Items Slot4 = null;
public Items Slot5 = null;
public Items Slot6 = null;
}     
       
}

[System.Serializable]
public class Items
{
      public string Name = "";
      public int id;
      public Texture2D Icons = null;
     public Rect rect;
     public bool Drag;
}

[System.Serializable]
public class ItemPick
{
public string name1;
public string name2;
public int name1id;
public int name2id;
public bool name1es;
public bool name2es;
}

[System.Serializable]
public class ItemPickOut
{
public int out1id;
public int out2id;
}


Всём добра :)

Сообщение отредактировал ZayRox - Пятница, 08.08.2014, 20:17
 
Форум » Unity » Вопросы » Поднятия предмета в инвентарь (Поможеш? дам +сик!)
Страница 1 из 11
Поиск:
Свернуть
Развернуть
Необходима авторизация
0
ТОП-5 САЙТА
НОВЫЕ ИГРЫ
ГОРЯЧИЕ ТЕМЫ
СЛУЧАЙНЫЕ ФАЙЛЫ