目录
一、 人员分工
二、 业务流程图
三、 系统功能结构图
四、 UML类图
五、 详细设计
(1)背包界面
(2)物品栏界面
(3)人物装备界面
六、 遇到的问题和解决方法
七、附录(代码实现)
装备组人员:3人
分工:
1.
系统分析
项目创建
公共类设计
2.
系统目标
编码规范
运行环境
数据库与数据表设计
3.
人员分工
开发问题及解决
系统功能结构
业务流程图
UML类图
模块设计
装备业务流程图
装备功能模块
Press”i”,打开背包栏
Press”c”,打开人物装备栏
float x = y * gameObject.GetComponent
Request error (error): UnityEditor.AsyncHTTPClient:Done(State, Int32)
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[System.Serializable]
public class Item
{
public string itemName; //itemName of the item
public int itemID; //itemID of the item
public string itemDesc; //itemDesc of the item
public Sprite itemIcon; //itemIcon of the item
public GameObject itemModel; //itemModel of the item
public int itemValue = 1; //itemValue is at start 1
public ItemType itemType; //itemType of the Item
public float itemWeight; //itemWeight of the item
public int maxStack = 1;
public int indexItemInList = 999;
public int rarity;
[SerializeField]
public List
public Item(){}
public Item(string name, int id, string desc, Sprite icon, GameObject model, int maxStack, ItemType type, string sendmessagetext, List
{
itemName = name;
itemID = id;
itemDesc = desc;
itemIcon = icon;
itemModel = model;
itemType = type;
this.maxStack = maxStack;
this.itemAttributes = itemAttributes;
}
public Item getCopy()
{
return (Item)this.MemberwiseClone();
}
}
using UnityEngine;
using System.Collections;
public class PickUpItem : MonoBehaviour
{
public Item item;
private Inventory _inventory;
private GameObject _player;
// Use this for initialization
void Start()
{
_player = GameObject.FindGameObjectWithTag("Player");
if (_player != null)
_inventory = _player.GetComponent
}
// Update is called once per frame
void Update()
{
if (_inventory != null && Input.GetKeyDown(KeyCode.E))
{
float distance = Vector3.Distance(this.gameObject.transform.position, _player.transform.position);
if (distance <= 3)
{
bool check = _inventory.checkIfItemAllreadyExist(item.itemID, item.itemValue);
if (check)
Destroy(this.gameObject);
else if (_inventory.ItemsInInventory.Count < (_inventory.width * _inventory.height))
{
_inventory.addItemToInventory(item.itemID, item.itemValue);
_inventory.updateItemList();
_inventory.stackableSettings();
Destroy(this.gameObject);
}
}
}
if (Input.GetMouseButton(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);//从摄像机发出到点击坐标的射线
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo))
{
Debug.DrawLine(ray.origin, hitInfo.point);//划出射线,只有在scene视图中才能看到
GameObject gameObj = hitInfo.collider.gameObject;
Debug.Log("click object name is " + gameObj.name);
if (gameObj.tag == "Item")//当射线碰撞目标为boot类型的物品 ,执行拾取操作
{
_inventory.addItemToInventory(item.itemID, item.itemValue);
_inventory.updateItemList();
_inventory.stackableSettings();
Destroy(this.gameObject);
Debug.Log("pick up!");
}
}
}
}
}
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System;
public class ConsumeItem : MonoBehaviour, IPointerDownHandler
{
public Item item;
private static Tooltip tooltip;
public ItemType[] itemTypeOfSlot;
public static EquipmentSystem eS;
public GameObject duplication;
public static GameObject mainInventory;
void Start()
{
item = GetComponent
if (GameObject.FindGameObjectWithTag("Tooltip") != null)
tooltip = GameObject.FindGameObjectWithTag("Tooltip").GetComponent
if (GameObject.FindGameObjectWithTag("EquipmentSystem") != null)
eS = GameObject.FindGameObjectWithTag("Player").GetComponent
if (GameObject.FindGameObjectWithTag("MainInventory") != null)
mainInventory = GameObject.FindGameObjectWithTag("MainInventory");
}
public void OnPointerDown(PointerEventData data)
{
if (this.gameObject.transform.parent.parent.parent.GetComponent
{
bool gearable = false;
Inventory inventory = transform.parent.parent.parent.GetComponent
if (eS != null)
itemTypeOfSlot = eS.itemTypeOfSlots;
if (data.button == PointerEventData.InputButton.Right)
{
//item from craft system to inventory
if (transform.parent.GetComponent
{
bool check = GameObject.FindGameObjectWithTag("Player").GetComponent
if (!check)
{
GameObject.FindGameObjectWithTag("Player").GetComponent
GameObject.FindGameObjectWithTag("Player").GetComponent
}
CraftSystem cS = GameObject.FindGameObjectWithTag("Player").GetComponent
cS.deleteItems(item);
CraftResultSlot result = GameObject.FindGameObjectWithTag("Player").GetComponent
result.temp = 0;
tooltip.deactivateTooltip();
gearable = true;
GameObject.FindGameObjectWithTag("MainInventory").GetComponent
}
else
{
bool stop = false;
if (eS != null)
{
for (int i = 0; i < eS.slotsInTotal; i++)
{
if (itemTypeOfSlot[i].Equals(item.itemType))
{
if (eS.transform.GetChild(1).GetChild(i).childCount == 0)
{
stop = true;
if (eS.transform.GetChild(1).GetChild(i).parent.parent.GetComponent
else
inventory.EquiptItem(item);
this.gameObject.transform.SetParent(eS.transform.GetChild(1).GetChild(i));
this.gameObject.GetComponent
eS.gameObject.GetComponent
inventory.updateItemList();
gearable = true;
if (duplication != null)
Destroy(duplication.gameObject);
break;
}
}
}
if (!stop)
{
for (int i = 0; i < eS.slotsInTotal; i++)
{
if (itemTypeOfSlot[i].Equals(item.itemType))
{
if (eS.transform.GetChild(1).GetChild(i).childCount != 0)
{
GameObject otherItemFromCharacterSystem = eS.transform.GetChild(1).GetChild(i).GetChild(0).gameObject;
Item otherSlotItem = otherItemFromCharacterSystem.GetComponent
if (item.itemType == ItemType.UFPS_Weapon)
{
inventory.UnEquipItem1(otherItemFromCharacterSystem.GetComponent
inventory.EquiptItem(item);
}
else
{
inventory.EquiptItem(item);
if (item.itemType != ItemType.Backpack)
inventory.UnEquipItem1(otherItemFromCharacterSystem.GetComponent
}
if (this == null)
{
GameObject dropItem = (GameObject)Instantiate(otherSlotItem.itemModel);
dropItem.AddComponent
dropItem.GetComponent
dropItem.transform.localPosition = GameObject.FindGameObjectWithTag("Player").transform.localPosition;
inventory.OnUpdateItemList();
}
else
{
otherItemFromCharacterSystem.transform.SetParent(this.transform.parent);
otherItemFromCharacterSystem.GetComponent
if (this.gameObject.transform.parent.parent.parent.GetComponent
createDuplication(otherItemFromCharacterSystem);
this.gameObject.transform.SetParent(eS.transform.GetChild(1).GetChild(i));
this.gameObject.GetComponent
}
gearable = true;
if (duplication != null)
Destroy(duplication.gameObject);
eS.gameObject.GetComponent
inventory.OnUpdateItemList();
break;
}
}
}
}
}
}
if (!gearable && item.itemType != ItemType.UFPS_Ammo && item.itemType != ItemType.UFPS_Grenade)
{
Item itemFromDup = null;
if (duplication != null)
itemFromDup = duplication.GetComponent
inventory.ConsumeItem(item);
item.itemValue--;
if (itemFromDup != null)
{
duplication.GetComponent
if (itemFromDup.itemValue <= 0)
{
if (tooltip != null)
tooltip.deactivateTooltip();
inventory.deleteItemFromInventory(item);
Destroy(duplication.gameObject);
}
}
if (item.itemValue <= 0)
{
if (tooltip != null)
tooltip.deactivateTooltip();
inventory.deleteItemFromInventory(item);
Destroy(this.gameObject);
}
}
}
}
}
public void consumeIt()
{
Inventory inventory = transform.parent.parent.parent.GetComponent
bool gearable = false;
if (GameObject.FindGameObjectWithTag("EquipmentSystem") != null)
eS = GameObject.FindGameObjectWithTag("Player").GetComponent
if (eS != null)
itemTypeOfSlot = eS.itemTypeOfSlots;
Item itemFromDup = null;
if (duplication != null)
itemFromDup = duplication.GetComponent
bool stop = false;
if (eS != null)
{
for (int i = 0; i < eS.slotsInTotal; i++)
{
if (itemTypeOfSlot[i].Equals(item.itemType))
{
if (eS.transform.GetChild(1).GetChild(i).childCount == 0)
{
stop = true;
this.gameObject.transform.SetParent(eS.transform.GetChild(1).GetChild(i));
this.gameObject.GetComponent
eS.gameObject.GetComponent
inventory.updateItemList();
inventory.EquiptItem(item);
gearable = true;
if (duplication != null)
Destroy(duplication.gameObject);
break;
}
}
}
if (!stop)
{
for (int i = 0; i < eS.slotsInTotal; i++)
{
if (itemTypeOfSlot[i].Equals(item.itemType))
{
if (eS.transform.GetChild(1).GetChild(i).childCount != 0)
{
GameObject otherItemFromCharacterSystem = eS.transform.GetChild(1).GetChild(i).GetChild(0).gameObject;
Item otherSlotItem = otherItemFromCharacterSystem.GetComponent
if (item.itemType == ItemType.UFPS_Weapon)
{
inventory.UnEquipItem1(otherItemFromCharacterSystem.GetComponent
inventory.EquiptItem(item);
}
else
{
inventory.EquiptItem(item);
if (item.itemType != ItemType.Backpack)
inventory.UnEquipItem1(otherItemFromCharacterSystem.GetComponent
}
if (this == null)
{
GameObject dropItem = (GameObject)Instantiate(otherSlotItem.itemModel);
dropItem.AddComponent
dropItem.GetComponent
dropItem.transform.localPosition = GameObject.FindGameObjectWithTag("Player").transform.localPosition;
inventory.OnUpdateItemList();
}
else
{
otherItemFromCharacterSystem.transform.SetParent(this.transform.parent);
otherItemFromCharacterSystem.GetComponent
if (this.gameObject.transform.parent.parent.parent.GetComponent
createDuplication(otherItemFromCharacterSystem);
this.gameObject.transform.SetParent(eS.transform.GetChild(1).GetChild(i));
this.gameObject.GetComponent
}
gearable = true;
if (duplication != null)
Destroy(duplication.gameObject);
eS.gameObject.GetComponent
inventory.OnUpdateItemList();
break;
}
}
}
}
}
if (!gearable && item.itemType != ItemType.UFPS_Ammo && item.itemType != ItemType.UFPS_Grenade)
{
if (duplication != null)
itemFromDup = duplication.GetComponent
inventory.ConsumeItem(item);
item.itemValue--;
if (itemFromDup != null)
{
duplication.GetComponent
if (itemFromDup.itemValue <= 0)
{
if (tooltip != null)
tooltip.deactivateTooltip();
inventory.deleteItemFromInventory(item);
Destroy(duplication.gameObject);
}
}
if (item.itemValue <= 0)
{
if (tooltip != null)
tooltip.deactivateTooltip();
inventory.deleteItemFromInventory(item);
Destroy(this.gameObject);
}
}
}
public void createDuplication(GameObject Item)
{
Item item = Item.GetComponent
GameObject dup = mainInventory.GetComponent
Item.GetComponent
dup.GetComponent
}
}
using UnityEngine;
using System.Collections;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine.UI;
using System.Collections.Generic;
public class Inventory : MonoBehaviour
{
//Prefabs
[SerializeField]
private GameObject prefabCanvasWithPanel;
[SerializeField]
private GameObject prefabSlot;
[SerializeField]
private GameObject prefabSlotContainer;
[SerializeField]
private GameObject prefabItem;
[SerializeField]
private GameObject prefabDraggingItemContainer;
[SerializeField]
private GameObject prefabPanel;
//Itemdatabase
[SerializeField]
private ItemDataBaseList itemDatabase;
//GameObjects which are alive
[SerializeField]
private string inventoryTitle;
[SerializeField]
private RectTransform PanelRectTransform;
[SerializeField]
private Image PanelImage;
[SerializeField]
private GameObject SlotContainer;
[SerializeField]
private GameObject DraggingItemContainer;
[SerializeField]
private RectTransform SlotContainerRectTransform;
[SerializeField]
private GridLayoutGroup SlotGridLayout;
[SerializeField]
private RectTransform SlotGridRectTransform;
//Inventory Settings
[SerializeField]
public bool mainInventory;
[SerializeField]
public List
[SerializeField]
public int height;
[SerializeField]
public int width;
[SerializeField]
public bool stackable;
[SerializeField]
public static bool inventoryOpen;
//GUI Settings
[SerializeField]
public int slotSize;
[SerializeField]
public int iconSize;
[SerializeField]
public int paddingBetweenX;
[SerializeField]
public int paddingBetweenY;
[SerializeField]
public int paddingLeft;
[SerializeField]
public int paddingRight;
[SerializeField]
public int paddingBottom;
[SerializeField]
public int paddingTop;
[SerializeField]
public int positionNumberX;
[SerializeField]
public int positionNumberY;
InputManager inputManagerDatabase;
//event delegates for consuming, gearing
public delegate void ItemDelegate(Item item);
public static event ItemDelegate ItemConsumed;
public static event ItemDelegate ItemEquip;
public static event ItemDelegate UnEquipItem;
public delegate void InventoryOpened();
public static event InventoryOpened InventoryOpen;
public static event InventoryOpened AllInventoriesClosed;
void Start()
{
if (transform.GetComponent
this.gameObject.SetActive(false);
updateItemList();
inputManagerDatabase = (InputManager)Resources.Load("InputManager");
}
public void sortItems()
{
int empty = -1;
for (int i = 0; i < SlotContainer.transform.childCount; i++)
{
if (SlotContainer.transform.GetChild(i).childCount == 0 && empty == -1)
empty = i;
else
{
if (empty > -1)
{
if (SlotContainer.transform.GetChild(i).childCount != 0)
{
RectTransform rect = SlotContainer.transform.GetChild(i).GetChild(0).GetComponent
SlotContainer.transform.GetChild(i).GetChild(0).transform.SetParent(SlotContainer.transform.GetChild(empty).transform);
rect.localPosition = Vector3.zero;
i = empty + 1;
empty = i;
}
}
}
}
}
void Update()
{
updateItemIndex();
}
public void setAsMain()
{
if (mainInventory)
this.gameObject.tag = "Untagged";
else if (!mainInventory)
this.gameObject.tag = "MainInventory";
}
public void OnUpdateItemList()
{
updateItemList();
}
public void closeInventory()
{
this.gameObject.SetActive(false);
checkIfAllInventoryClosed();
}
public void openInventory()
{
this.gameObject.SetActive(true);
if (InventoryOpen != null)
InventoryOpen();
}
public void checkIfAllInventoryClosed()
{
GameObject canvas = GameObject.FindGameObjectWithTag("Canvas");
for (int i = 0; i < canvas.transform.childCount; i++)
{
GameObject child = canvas.transform.GetChild(i).gameObject;
if (!child.activeSelf && (child.tag == "EquipmentSystem" || child.tag == "Panel" || child.tag == "MainInventory" || child.tag == "CraftSystem"))
{
if (AllInventoriesClosed != null && i == canvas.transform.childCount - 1)
AllInventoriesClosed();
}
else if (child.activeSelf && (child.tag == "EquipmentSystem" || child.tag == "Panel" || child.tag == "MainInventory" || child.tag == "CraftSystem"))
break;
else if (i == canvas.transform.childCount - 1)
{
if (AllInventoriesClosed != null)
AllInventoriesClosed();
}
}
}
public void ConsumeItem(Item item)
{
if (ItemConsumed != null)
ItemConsumed(item);
}
public void EquiptItem(Item item)
{
if (ItemEquip != null)
ItemEquip(item);
}
public void UnEquipItem1(Item item)
{
if (UnEquipItem != null)
UnEquipItem(item);
}
#if UNITY_EDITOR
[MenuItem("Master System/Create/Inventory and Storage")] //creating the menu item
public static void menuItemCreateInventory() //create the inventory at start
{
GameObject Canvas = null;
if (GameObject.FindGameObjectWithTag("Canvas") == null)
{
GameObject inventory = new GameObject();
inventory.name = "Inventories";
Canvas = (GameObject)Instantiate(Resources.Load("Prefabs/Canvas - Inventory") as GameObject);
Canvas.transform.SetParent(inventory.transform, true);
GameObject panel = (GameObject)Instantiate(Resources.Load("Prefabs/Panel - Inventory") as GameObject);
panel.GetComponent
panel.transform.SetParent(Canvas.transform, true);
GameObject draggingItem = (GameObject)Instantiate(Resources.Load("Prefabs/DraggingItem") as GameObject);
draggingItem.transform.SetParent(Canvas.transform, true);
Inventory temp = panel.AddComponent
Instantiate(Resources.Load("Prefabs/EventSystem") as GameObject);
panel.AddComponent
temp.getPrefabs();
}
else
{
GameObject panel = (GameObject)Instantiate(Resources.Load("Prefabs/Panel - Inventory") as GameObject);
panel.transform.SetParent(GameObject.FindGameObjectWithTag("Canvas").transform, true);
panel.GetComponent
Inventory temp = panel.AddComponent
panel.AddComponent
DestroyImmediate(GameObject.FindGameObjectWithTag("DraggingItem"));
GameObject draggingItem = (GameObject)Instantiate(Resources.Load("Prefabs/DraggingItem") as GameObject);
draggingItem.transform.SetParent(GameObject.FindGameObjectWithTag("Canvas").transform, true);
temp.getPrefabs();
}
}
#endif
public void setImportantVariables()
{
PanelRectTransform = GetComponent
SlotContainer = transform.GetChild(1).gameObject;
SlotGridLayout = SlotContainer.GetComponent
SlotGridRectTransform = SlotContainer.GetComponent
}
public void getPrefabs()
{
if (prefabCanvasWithPanel == null)
prefabCanvasWithPanel = Resources.Load("Prefabs/Canvas - Inventory") as GameObject;
if (prefabSlot == null)
prefabSlot = Resources.Load("Prefabs/Slot - Inventory") as GameObject;
if (prefabSlotContainer == null)
prefabSlotContainer = Resources.Load("Prefabs/Slots - Inventory") as GameObject;
if (prefabItem == null)
prefabItem = Resources.Load("Prefabs/Item") as GameObject;
if (itemDatabase == null)
itemDatabase = (ItemDataBaseList)Resources.Load("ItemDatabase");
if (prefabDraggingItemContainer == null)
prefabDraggingItemContainer = Resources.Load("Prefabs/DraggingItem") as GameObject;
if (prefabPanel == null)
prefabPanel = Resources.Load("Prefabs/Panel - Inventory") as GameObject;
setImportantVariables();
setDefaultSettings();
adjustInventorySize();
updateSlotAmount(width, height);
updateSlotSize();
updatePadding(paddingBetweenX, paddingBetweenY);
}
public void updateItemList()
{
ItemsInInventory.Clear();
for (int i = 0; i < SlotContainer.transform.childCount; i++)
{
Transform trans = SlotContainer.transform.GetChild(i);
if (trans.childCount != 0)
{
ItemsInInventory.Add(trans.GetChild(0).GetComponent
}
}
}
public bool characterSystem()
{
if (GetComponent
return true;
else
return false;
}
public void setDefaultSettings()
{
if (GetComponent
{
height = 5;
width = 5;
slotSize = 50;
iconSize = 45;
paddingBetweenX = 5;
paddingBetweenY = 5;
paddingTop = 35;
paddingBottom = 10;
paddingLeft = 10;
paddingRight = 10;
}
else if (GetComponent
{
height = 1;
width = 9;
slotSize = 50;
iconSize = 45;
paddingBetweenX = 5;
paddingBetweenY = 5;
paddingTop = 10;
paddingBottom = 10;
paddingLeft = 10;
paddingRight = 10;
}
else if (GetComponent
{
height = 3;
width = 3;
slotSize = 55;
iconSize = 45;
paddingBetweenX = 5;
paddingBetweenY = 5;
paddingTop = 35;
paddingBottom = 95;
paddingLeft = 25;
paddingRight = 25;
}
else
{
height = 4;
width = 2;
slotSize = 50;
iconSize = 45;
paddingBetweenX = 100;
paddingBetweenY = 20;
paddingTop = 35;
paddingBottom = 10;
paddingLeft = 10;
paddingRight = 10;
}
}
public void adjustInventorySize()
{
int x = (((width * slotSize) + ((width - 1) * paddingBetweenX)) + paddingLeft + paddingRight);
int y = (((height * slotSize) + ((height - 1) * paddingBetweenY)) + paddingTop + paddingBottom);
PanelRectTransform.sizeDelta = new Vector2(x, y);
SlotGridRectTransform.sizeDelta = new Vector2(x, y);
}
public void updateSlotAmount(int width, int height)
{
if (prefabSlot == null)
prefabSlot = Resources.Load("Prefabs/Slot - Inventory") as GameObject;
if (SlotContainer == null)
{
SlotContainer = (GameObject)Instantiate(prefabSlotContainer);
SlotContainer.transform.SetParent(PanelRectTransform.transform);
SlotContainerRectTransform = SlotContainer.GetComponent
SlotGridRectTransform = SlotContainer.GetComponent
SlotGridLayout = SlotContainer.GetComponent
}
if (SlotContainerRectTransform == null)
SlotContainerRectTransform = SlotContainer.GetComponent
SlotContainerRectTransform.localPosition = Vector3.zero;
List
List
foreach (Transform child in SlotContainer.transform)
{
if (child.tag == "Slot") { slotList.Add(child.gameObject); }
}
while (slotList.Count > width * height)
{
GameObject go = slotList[slotList.Count - 1];
ItemOnObject itemInSlot = go.GetComponentInChildren
if (itemInSlot != null)
{
itemsToMove.Add(itemInSlot.item);
ItemsInInventory.Remove(itemInSlot.item);
}
slotList.Remove(go);
DestroyImmediate(go);
}
if (slotList.Count < width * height)
{
for (int i = slotList.Count; i < (width * height); i++)
{
GameObject Slot = (GameObject)Instantiate(prefabSlot);
Slot.name = (slotList.Count + 1).ToString();
Slot.transform.SetParent(SlotContainer.transform);
slotList.Add(Slot);
}
}
if (itemsToMove != null && ItemsInInventory.Count < width * height)
{
foreach (Item i in itemsToMove)
{
addItemToInventory(i.itemID);
}
}
setImportantVariables();
}
public void updateSlotAmount()
{
if (prefabSlot == null)
prefabSlot = Resources.Load("Prefabs/Slot - Inventory") as GameObject;
if (SlotContainer == null)
{
SlotContainer = (GameObject)Instantiate(prefabSlotContainer);
SlotContainer.transform.SetParent(PanelRectTransform.transform);
SlotContainerRectTransform = SlotContainer.GetComponent
SlotGridRectTransform = SlotContainer.GetComponent
SlotGridLayout = SlotContainer.GetComponent
}
if (SlotContainerRectTransform == null)
SlotContainerRectTransform = SlotContainer.GetComponent
SlotContainerRectTransform.localPosition = Vector3.zero;
List
List
foreach (Transform child in SlotContainer.transform)
{
if (child.tag == "Slot") { slotList.Add(child.gameObject); }
}
while (slotList.Count > width * height)
{
GameObject go = slotList[slotList.Count - 1];
ItemOnObject itemInSlot = go.GetComponentInChildren
if (itemInSlot != null)
{
itemsToMove.Add(itemInSlot.item);
ItemsInInventory.Remove(itemInSlot.item);
}
slotList.Remove(go);
DestroyImmediate(go);
}
if (slotList.Count < width * height)
{
for (int i = slotList.Count; i < (width * height); i++)
{
GameObject Slot = (GameObject)Instantiate(prefabSlot);
Slot.name = (slotList.Count + 1).ToString();
Slot.transform.SetParent(SlotContainer.transform);
slotList.Add(Slot);
}
}
if (itemsToMove != null && ItemsInInventory.Count < width * height)
{
foreach (Item i in itemsToMove)
{
addItemToInventory(i.itemID);
}
}
setImportantVariables();
}
public void updateSlotSize(int slotSize)
{
SlotGridLayout.cellSize = new Vector2(slotSize, slotSize);
updateItemSize();
}
public void updateSlotSize()
{
SlotGridLayout.cellSize = new Vector2(slotSize, slotSize);
updateItemSize();
}
void updateItemSize()
{
for (int i = 0; i < SlotContainer.transform.childCount; i++)
{
if (SlotContainer.transform.GetChild(i).childCount > 0)
{
SlotContainer.transform.GetChild(i).GetChild(0).GetComponent
SlotContainer.transform.GetChild(i).GetChild(0).GetChild(2).GetComponent
}
}
}
public void updatePadding(int spacingBetweenX, int spacingBetweenY)
{
SlotGridLayout.spacing = new Vector2(paddingBetweenX, paddingBetweenY);
SlotGridLayout.padding.bottom = paddingBottom;
SlotGridLayout.padding.right = paddingRight;
SlotGridLayout.padding.left = paddingLeft;
SlotGridLayout.padding.top = paddingTop;
}
public void updatePadding()
{
SlotGridLayout.spacing = new Vector2(paddingBetweenX, paddingBetweenY);
SlotGridLayout.padding.bottom = paddingBottom;
SlotGridLayout.padding.right = paddingRight;
SlotGridLayout.padding.left = paddingLeft;
SlotGridLayout.padding.top = paddingTop;
}
public void addAllItemsToInventory()
{
for (int k = 0; k < ItemsInInventory.Count; k++)
{
for (int i = 0; i < SlotContainer.transform.childCount; i++)
{
if (SlotContainer.transform.GetChild(i).childCount == 0)
{
GameObject item = (GameObject)Instantiate(prefabItem);
item.GetComponent
item.transform.SetParent(SlotContainer.transform.GetChild(i));
item.GetComponent
item.transform.GetChild(0).GetComponent
updateItemSize();
break;
}
}
}
stackableSettings();
}
public bool checkIfItemAllreadyExist(int itemID, int itemValue)
{
updateItemList();
int stack;
for (int i = 0; i < ItemsInInventory.Count; i++)
{
if (ItemsInInventory[i].itemID == itemID)
{
stack = ItemsInInventory[i].itemValue + itemValue;
if (stack <= ItemsInInventory[i].maxStack)
{
ItemsInInventory[i].itemValue = stack;
GameObject temp = getItemGameObject(ItemsInInventory[i]);
if (temp != null && temp.GetComponent
temp.GetComponent
return true;
}
}
}
return false;
}
public void addItemToInventory(int id)
{
for (int i = 0; i < SlotContainer.transform.childCount; i++)
{
if (SlotContainer.transform.GetChild(i).childCount == 0)
{
GameObject item = (GameObject)Instantiate(prefabItem);
item.GetComponent
item.transform.SetParent(SlotContainer.transform.GetChild(i));
item.GetComponent
item.transform.GetChild(0).GetComponent
item.GetComponent
break;
}
}
stackableSettings();
updateItemList();
}
public GameObject addItemToInventory(int id, int value)
{
for (int i = 0; i < SlotContainer.transform.childCount; i++)
{
if (SlotContainer.transform.GetChild(i).childCount == 0)
{
GameObject item = (GameObject)Instantiate(prefabItem);
ItemOnObject itemOnObject = item.GetComponent
itemOnObject.item = itemDatabase.getItemByID(id);
if (itemOnObject.item.itemValue <= itemOnObject.item.maxStack && value <= itemOnObject.item.maxStack)
itemOnObject.item.itemValue = value;
else
itemOnObject.item.itemValue = 1;
item.transform.SetParent(SlotContainer.transform.GetChild(i));
item.GetComponent
item.transform.GetChild(0).GetComponent
itemOnObject.item.indexItemInList = ItemsInInventory.Count - 1;
if (inputManagerDatabase == null)
inputManagerDatabase = (InputManager)Resources.Load("InputManager");
return item;
}
}
stackableSettings();
updateItemList();
return null;
}
public void addItemToInventoryStorage(int itemID, int value)
{
for (int i = 0; i < SlotContainer.transform.childCount; i++)
{
if (SlotContainer.transform.GetChild(i).childCount == 0)
{
GameObject item = (GameObject)Instantiate(prefabItem);
ItemOnObject itemOnObject = item.GetComponent
itemOnObject.item = itemDatabase.getItemByID(itemID);
if (itemOnObject.item.itemValue < itemOnObject.item.maxStack && value <= itemOnObject.item.maxStack)
itemOnObject.item.itemValue = value;
else
itemOnObject.item.itemValue = 1;
item.transform.SetParent(SlotContainer.transform.GetChild(i));
item.GetComponent
itemOnObject.item.indexItemInList = 999;
if (inputManagerDatabase == null)
inputManagerDatabase = (InputManager)Resources.Load("InputManager");
updateItemSize();
stackableSettings();
break;
}
}
stackableSettings();
updateItemList();
}
public void updateIconSize(int iconSize)
{
for (int i = 0; i < SlotContainer.transform.childCount; i++)
{
if (SlotContainer.transform.GetChild(i).childCount > 0)
{
SlotContainer.transform.GetChild(i).GetChild(0).GetChild(0).GetComponent
}
}
updateItemSize();
}
public void updateIconSize()
{
for (int i = 0; i < SlotContainer.transform.childCount; i++)
{
if (SlotContainer.transform.GetChild(i).childCount > 0)
{
SlotContainer.transform.GetChild(i).GetChild(0).GetChild(0).GetComponent
}
}
updateItemSize();
}
public void stackableSettings(bool stackable, Vector3 posi)
{
for (int i = 0; i < SlotContainer.transform.childCount; i++)
{
if (SlotContainer.transform.GetChild(i).childCount > 0)
{
ItemOnObject item = SlotContainer.transform.GetChild(i).GetChild(0).GetComponent
if (item.item.maxStack > 1)
{
RectTransform textRectTransform = SlotContainer.transform.GetChild(i).GetChild(0).GetChild(1).GetComponent
Text text = SlotContainer.transform.GetChild(i).GetChild(0).GetChild(1).GetComponent
text.text = "" + item.item.itemValue;
text.enabled = stackable;
textRectTransform.localPosition = posi;
}
}
}
}
public void deleteAllItems()
{
for (int i = 0; i < SlotContainer.transform.childCount; i++)
{
if (SlotContainer.transform.GetChild(i).childCount != 0)
{
Destroy(SlotContainer.transform.GetChild(i).GetChild(0).gameObject);
}
}
}
public List
{
List
for (int i = 0; i < SlotContainer.transform.childCount; i++)
{
if (SlotContainer.transform.GetChild(i).childCount != 0)
theList.Add(SlotContainer.transform.GetChild(i).GetChild(0).GetComponent
}
return theList;
}
public void stackableSettings()
{
for (int i = 0; i < SlotContainer.transform.childCount; i++)
{
if (SlotContainer.transform.GetChild(i).childCount > 0)
{
ItemOnObject item = SlotContainer.transform.GetChild(i).GetChild(0).GetComponent
if (item.item.maxStack > 1)
{
RectTransform textRectTransform = SlotContainer.transform.GetChild(i).GetChild(0).GetChild(1).GetComponent
Text text = SlotContainer.transform.GetChild(i).GetChild(0).GetChild(1).GetComponent
text.text = "" + item.item.itemValue;
text.enabled = stackable;
textRectTransform.localPosition = new Vector3(positionNumberX, positionNumberY, 0);
}
else
{
Text text = SlotContainer.transform.GetChild(i).GetChild(0).GetChild(1).GetComponent
text.enabled = false;
}
}
}
}
public GameObject getItemGameObjectByName(Item item)
{
for (int k = 0; k < SlotContainer.transform.childCount; k++)
{
if (SlotContainer.transform.GetChild(k).childCount != 0)
{
GameObject itemGameObject = SlotContainer.transform.GetChild(k).GetChild(0).gameObject;
Item itemObject = itemGameObject.GetComponent
if (itemObject.itemName.Equals(item.itemName))
{
return itemGameObject;
}
}
}
return null;
}
public GameObject getItemGameObject(Item item)
{
for (int k = 0; k < SlotContainer.transform.childCount; k++)
{
if (SlotContainer.transform.GetChild(k).childCount != 0)
{
GameObject itemGameObject = SlotContainer.transform.GetChild(k).GetChild(0).gameObject;
Item itemObject = itemGameObject.GetComponent
if (itemObject.Equals(item))
{
return itemGameObject;
}
}
}
return null;
}
public void changeInventoryPanelDesign(Image image)
{
Image inventoryDesign = transform.GetChild(0).GetChild(0).GetComponent
inventoryDesign.sprite = (Sprite)image.sprite;
inventoryDesign.color = image.color;
inventoryDesign.material = image.material;
inventoryDesign.type = image.type;
inventoryDesign.fillCenter = image.fillCenter;
}
public void deleteItem(Item item)
{
for (int i = 0; i < ItemsInInventory.Count; i++)
{
if (item.Equals(ItemsInInventory[i]))
ItemsInInventory.RemoveAt(item.indexItemInList);
}
}
public void deleteItemFromInventory(Item item)
{
for (int i = 0; i < ItemsInInventory.Count; i++)
{
if (item.Equals(ItemsInInventory[i]))
ItemsInInventory.RemoveAt(i);
}
}
public void deleteItemFromInventoryWithGameObject(Item item)
{
for (int i = 0; i < ItemsInInventory.Count; i++)
{
if (item.Equals(ItemsInInventory[i]))
{
ItemsInInventory.RemoveAt(i);
}
}
for (int k = 0; k < SlotContainer.transform.childCount; k++)
{
if (SlotContainer.transform.GetChild(k).childCount != 0)
{
GameObject itemGameObject = SlotContainer.transform.GetChild(k).GetChild(0).gameObject;
Item itemObject = itemGameObject.GetComponent
if (itemObject.Equals(item))
{
Destroy(itemGameObject);
break;
}
}
}
}
public int getPositionOfItem(Item item)
{
for (int i = 0; i < SlotContainer.transform.childCount; i++)
{
if (SlotContainer.transform.GetChild(i).childCount != 0)
{
Item item2 = SlotContainer.transform.GetChild(i).GetChild(0).GetComponent
if (item.Equals(item2))
return i;
}
}
return -1;
}
public void addItemToInventory(int ignoreSlot, int itemID, int itemValue)
{
for (int i = 0; i < SlotContainer.transform.childCount; i++)
{
if (SlotContainer.transform.GetChild(i).childCount == 0 && i != ignoreSlot)
{
GameObject item = (GameObject)Instantiate(prefabItem);
ItemOnObject itemOnObject = item.GetComponent
itemOnObject.item = itemDatabase.getItemByID(itemID);
if (itemOnObject.item.itemValue < itemOnObject.item.maxStack && itemValue <= itemOnObject.item.maxStack)
itemOnObject.item.itemValue = itemValue;
else
itemOnObject.item.itemValue = 1;
item.transform.SetParent(SlotContainer.transform.GetChild(i));
item.GetComponent
itemOnObject.item.indexItemInList = 999;
updateItemSize();
stackableSettings();
break;
}
}
stackableSettings();
updateItemList();
}
public void updateItemIndex()
{
for (int i = 0; i < ItemsInInventory.Count; i++)
{
ItemsInInventory[i].indexItemInList = i;
}
}
}
using System;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class EquipmentSystem : MonoBehaviour
{
[SerializeField]
public int slotsInTotal;
[SerializeField]
public ItemType[] itemTypeOfSlots = new ItemType[999];
void Start()
{
ConsumeItem.eS = GetComponent
}
public void getSlotsInTotal()
{
Inventory inv = GetComponent
slotsInTotal = inv.width * inv.height;
}
#if UNITY_EDITOR
[MenuItem("Master System/Create/Equipment")] //creating the menu item
public static void menuItemCreateInventory() //create the inventory at start
{
GameObject Canvas = null;
if (GameObject.FindGameObjectWithTag("Canvas") == null)
{
GameObject inventory = new GameObject();
inventory.name = "Inventories";
Canvas = (GameObject)Instantiate(Resources.Load("Prefabs/Canvas - Inventory") as GameObject);
Canvas.transform.SetParent(inventory.transform, true);
GameObject panel = (GameObject)Instantiate(Resources.Load("Prefabs/Panel - EquipmentSystem") as GameObject);
panel.GetComponent
panel.transform.SetParent(Canvas.transform, true);
GameObject draggingItem = (GameObject)Instantiate(Resources.Load("Prefabs/DraggingItem") as GameObject);
draggingItem.transform.SetParent(Canvas.transform, true);
Instantiate(Resources.Load("Prefabs/EventSystem") as GameObject);
Inventory inv = panel.AddComponent
panel.AddComponent
panel.AddComponent
inv.getPrefabs();
}
else
{
GameObject panel = (GameObject)Instantiate(Resources.Load("Prefabs/Panel - EquipmentSystem") as GameObject);
panel.transform.SetParent(GameObject.FindGameObjectWithTag("Canvas").transform, true);
panel.GetComponent
Inventory inv = panel.AddComponent
panel.AddComponent
DestroyImmediate(GameObject.FindGameObjectWithTag("DraggingItem"));
GameObject draggingItem = (GameObject)Instantiate(Resources.Load("Prefabs/DraggingItem") as GameObject);
panel.AddComponent
draggingItem.transform.SetParent(GameObject.FindGameObjectWithTag("Canvas").transform, true);
inv.getPrefabs();
}
}
#endif
}
using UnityEngine;
using System.Collections;
#if UNITY_EDITOR
using UnityEditor;
#endif
using System.Collections.Generic;
using System.Linq;
public class Hotbar : MonoBehaviour
{
[SerializeField]
public KeyCode[] keyCodesForSlots = new KeyCode[999];
[SerializeField]
public int slotsInTotal;
#if UNITY_EDITOR
[MenuItem("Master System/Create/Hotbar")] //creating the menu item
public static void menuItemCreateInventory() //create the inventory at start
{
GameObject Canvas = null;
if (GameObject.FindGameObjectWithTag("Canvas") == null)
{
GameObject inventory = new GameObject();
inventory.name = "Inventories";
Canvas = (GameObject)Instantiate(Resources.Load("Prefabs/Canvas - Inventory") as GameObject);
Canvas.transform.SetParent(inventory.transform, true);
GameObject panel = (GameObject)Instantiate(Resources.Load("Prefabs/Panel - Hotbar") as GameObject);
panel.GetComponent
panel.transform.SetParent(Canvas.transform, true);
GameObject draggingItem = (GameObject)Instantiate(Resources.Load("Prefabs/DraggingItem") as GameObject);
Instantiate(Resources.Load("Prefabs/EventSystem") as GameObject);
draggingItem.transform.SetParent(Canvas.transform, true);
Inventory inv = panel.AddComponent
panel.AddComponent
panel.AddComponent
inv.getPrefabs();
}
else
{
GameObject panel = (GameObject)Instantiate(Resources.Load("Prefabs/Panel - Hotbar") as GameObject);
panel.transform.SetParent(GameObject.FindGameObjectWithTag("Canvas").transform, true);
panel.GetComponent
Inventory inv = panel.AddComponent
panel.AddComponent
DestroyImmediate(GameObject.FindGameObjectWithTag("DraggingItem"));
GameObject draggingItem = (GameObject)Instantiate(Resources.Load("Prefabs/DraggingItem") as GameObject);
draggingItem.transform.SetParent(GameObject.FindGameObjectWithTag("Canvas").transform, true);
panel.AddComponent
inv.getPrefabs();
}
}
#endif
void Update()
{
for (int i = 0; i < slotsInTotal; i++)
{
if (Input.GetKeyDown(keyCodesForSlots[i]))
{
if (transform.GetChild(1).GetChild(i).childCount != 0 && transform.GetChild(1).GetChild(i).GetChild(0).GetComponent
{
if (transform.GetChild(1).GetChild(i).GetChild(0).GetComponent
{
Destroy(transform.GetChild(1).GetChild(i).GetChild(0).GetComponent
}
transform.GetChild(1).GetChild(i).GetChild(0).GetComponent
}
}
}
}
public int getSlotsInTotal()
{
Inventory inv = GetComponent
return slotsInTotal = inv.width * inv.height;
}
}