Skip to content

Commit

Permalink
12
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxq committed Mar 3, 2016
1 parent 9b6742d commit 7e4d2b2
Show file tree
Hide file tree
Showing 20 changed files with 162 additions and 13 deletions.
Binary file modified Assets/InventoryMaster/Resources/ItemDatabase.asset
Binary file not shown.
Binary file modified Assets/InventoryMaster/Resources/Prefabs/Item.prefab
Binary file not shown.
File renamed without changes.
78 changes: 78 additions & 0 deletions Assets/InventoryMaster/Scripts/Hotbar/HotBarProcess.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using KBEngine;

public class HotBarProcess : MonoBehaviour, IPointerDownHandler
{
public static HotBarProcess _instance;
private Inventory inventory = null;
private int itemId = -1;

private Text text; //text for the itemValue
private Image image_icon; //图标
private Image image_cool; //冷却
// Use this for initialization
void Start () {
UnityEngine.GameObject canvas = UnityEngine.GameObject.FindGameObjectWithTag("Canvas");
if (canvas.transform.Find("Panel - Inventory(Clone)") != null)
inventory = canvas.transform.Find("Panel - Inventory(Clone)").GetComponent<Inventory>();

this.gameObject.SetActive(false);
}

void Awake()
{
_instance = this;
image_icon = transform.GetChild(0).GetComponent<Image>();
text = transform.GetChild(1).GetComponent<Text>(); //get the text(itemValue GameObject) of the item
image_cool = transform.GetChild(2).GetComponent<Image>();
}
void Update()
{
if (itemId == -1)
return;
//如果快捷栏有物品,则刷新物品状态
if (inventory == null)
{
UnityEngine.GameObject canvas = UnityEngine.GameObject.FindGameObjectWithTag("Canvas");
inventory = canvas.transform.Find("Panel - Inventory(Clone)").GetComponent<Inventory>();
}
if (inventory == null)
return;
//物品已使用完或者消失
UnityEngine.GameObject itemobject = inventory.getItemGameObject(itemId);
if (itemobject == null)
{
this.itemId = -1;
this.gameObject.SetActive(false);
return;
}

image_icon.sprite = itemobject.GetComponent<ItemOnObject>().item.itemIcon;
text.rectTransform.localPosition = itemobject.transform.GetChild(1).GetComponent<Text>().transform.localPosition;
text.enabled = true;
text.text = itemobject.transform.GetChild(1).GetComponent<Text>().text;
image_cool.sprite = itemobject.transform.GetChild(2).GetComponent<Image>().sprite;
}
//放到快捷栏
public void upItem(int itemId)
{
this.itemId = itemId;
this.gameObject.SetActive(true);
}
//点击使用
public void OnPointerDown(PointerEventData data)
{
UnityEngine.GameObject itemobject = inventory.getItemGameObject(itemId);
if (itemobject != null)
{
KBEngine.Avatar p = (KBEngine.Avatar)KBEngineApp.app.player();
if (p != null)
{
p.useItemRequest(itemobject.GetComponent<ItemOnObject>().item.itemIndex);
}
}
}
}
12 changes: 12 additions & 0 deletions Assets/InventoryMaster/Scripts/Hotbar/HotBarProcess.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions Assets/InventoryMaster/Scripts/Inventory/Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,24 @@ public GameObject getItemGameObject(Item item)
}
return null;
}
public GameObject getItemGameObject(int itemId)
{
int itemIndex = -1;
foreach(Item item in ItemsInInventory)
{
if (item.itemID == itemId)
{
itemIndex = item.itemIndex;
break;
}
}
if (itemIndex != -1 && SlotContainer.transform.GetChild(itemIndex).childCount != 0)
{
return SlotContainer.transform.GetChild(itemIndex).GetChild(0).gameObject;
}
else
return null;
}



Expand Down
8 changes: 5 additions & 3 deletions Assets/InventoryMaster/Scripts/Item/ItemOnObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@ public class ItemOnObject : MonoBehaviour //Saves the Item in
{
public Item item; //Item
private Text text; //text for the itemValue
private Image image;
private Image image_icon; //图标
private Image image_cool; //冷却

void Update()
{
text.text = "" + item.itemValue; //sets the itemValue
image.sprite = item.itemIcon;
image_icon.sprite = item.itemIcon;
//GetComponent<ConsumeItem>().item = item;
}

void Start()
{
image = transform.GetChild(0).GetComponent<Image>();
image_icon = transform.GetChild(0).GetComponent<Image>();
transform.GetChild(0).GetComponent<Image>().sprite = item.itemIcon; //set the sprite of the Item
text = transform.GetChild(1).GetComponent<Text>(); //get the text(itemValue GameObject) of the item
image_cool = transform.GetChild(2).GetComponent<Image>();
}
}
36 changes: 26 additions & 10 deletions Assets/InventoryMaster/Scripts/Tooltip/Tooltip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ public class Tooltip : MonoBehaviour
public UnityEngine.GameObject btn_unEquip;
public UnityEngine.GameObject btn_use;
public UnityEngine.GameObject btn_drop;
public UnityEngine.GameObject btn_hotBar;

//GUI
public float tooltipHeight;

private Image tooltipImageIcon;
private Text tooltipNameText;
private Text tooltipDescText;
private Text tooltipDescText;
private Text tooltipAttrText;

void Start()
{
Expand All @@ -47,6 +49,7 @@ public void setVariables()
tooltipImageIcon = transform.GetChild(1).GetComponent<Image>();
tooltipNameText = transform.GetChild(2).GetComponent<Text>();
tooltipDescText = transform.GetChild(3).GetComponent<Text>();
tooltipAttrText = transform.GetChild(4).GetComponent<Text>();
}

public void activateTooltip() //if you activate the tooltip through hovering over an item
Expand All @@ -56,21 +59,31 @@ public void activateTooltip() //if you activate the tooltip throug

tooltipImageIcon.sprite = item.itemIcon; //and the itemIcon...
tooltipNameText.text = item.itemName; //,itemName...
tooltipDescText.text = item.itemDesc; //and itemDesc is getting set
tooltipDescText.text = item.itemDesc; //and itemDesc is getting set

tooltipAttrText.text = "";
foreach(ItemAttribute attr in item.itemAttributes)
{
tooltipAttrText.text += attr.attributeName + ": " + attr.attributeValue + "\n";
}
}
private void setOperateByType(TooltipType ttype)
{
btn_equip.SetActive(false);
btn_unEquip.SetActive(false);
btn_use.SetActive(false);
btn_drop.SetActive(false);
btn_hotBar.SetActive(false);
if (ttype == TooltipType.Inventory)
{
btn_drop.SetActive(true);
if (item.isEquipItem())
btn_equip.SetActive(true);
if (item.isConsumeItem())
{
btn_use.SetActive(true);
btn_hotBar.SetActive(true);
}
}
else if (ttype == TooltipType.Equipment)
{
Expand All @@ -82,7 +95,7 @@ public void deactivateTooltip() //deactivating the tooltip after you
{
this.transform.gameObject.SetActive(false);
}
public void equipTooltip() //deactivating the tooltip after you went out of a slot
public void equipTooltip()
{

}
Expand Down Expand Up @@ -149,14 +162,17 @@ public void unEquipItem()

public void useItem()
{
KBEngine.Avatar p = (KBEngine.Avatar)KBEngineApp.app.player();
if (p != null)
{
p.useItemRequest(item.itemIndex);
deactivateTooltip();
}
}

KBEngine.Avatar p = (KBEngine.Avatar)KBEngineApp.app.player();
if (p != null)
{
p.useItemRequest(item.itemIndex);
deactivateTooltip();
}

public void hotBarItem()
{
HotBarProcess._instance.upItem(item.itemID);
}

}
Binary file modified Assets/login.unity
Binary file not shown.
11 changes: 11 additions & 0 deletions Assets/script/LimitCD.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


class LimitCD
{

}

12 changes: 12 additions & 0 deletions Assets/script/LimitCD.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Assets/world.unity
Binary file not shown.

0 comments on commit 7e4d2b2

Please sign in to comment.