123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- using System;
- using UnityEngine;
- [AddComponentMenu("NGUI/Examples/Equipment")]
- public class InvEquipment : MonoBehaviour
- {
- public InvGameItem[] equippedItems
- {
- get
- {
- return this.mItems;
- }
- }
- public InvGameItem Replace(InvBaseItem.Slot slot, InvGameItem item)
- {
- InvBaseItem invBaseItem = (item == null) ? null : item.baseItem;
- if (slot == InvBaseItem.Slot.None)
- {
- if (item != null)
- {
- Debug.LogWarning("Can't equip \"" + item.name + "\" because it doesn't specify an item slot");
- }
- return item;
- }
- if (invBaseItem != null && invBaseItem.slot != slot)
- {
- return item;
- }
- if (this.mItems == null)
- {
- int num = 8;
- this.mItems = new InvGameItem[num];
- }
- InvGameItem result = this.mItems[slot - InvBaseItem.Slot.Weapon];
- this.mItems[slot - InvBaseItem.Slot.Weapon] = item;
- if (this.mAttachments == null)
- {
- this.mAttachments = base.GetComponentsInChildren<InvAttachmentPoint>();
- }
- int i = 0;
- int num2 = this.mAttachments.Length;
- while (i < num2)
- {
- InvAttachmentPoint invAttachmentPoint = this.mAttachments[i];
- if (invAttachmentPoint.slot == slot)
- {
- GameObject gameObject = invAttachmentPoint.Attach((invBaseItem == null) ? null : invBaseItem.attachment);
- if (invBaseItem != null && gameObject != null)
- {
- Renderer component = gameObject.GetComponent<Renderer>();
- if (component != null)
- {
- component.material.color = invBaseItem.color;
- }
- }
- }
- i++;
- }
- return result;
- }
- public InvGameItem Equip(InvGameItem item)
- {
- if (item != null)
- {
- InvBaseItem baseItem = item.baseItem;
- if (baseItem != null)
- {
- return this.Replace(baseItem.slot, item);
- }
- Debug.LogWarning("Can't resolve the item ID of " + item.baseItemID);
- }
- return item;
- }
- public InvGameItem Unequip(InvGameItem item)
- {
- if (item != null)
- {
- InvBaseItem baseItem = item.baseItem;
- if (baseItem != null)
- {
- return this.Replace(baseItem.slot, null);
- }
- }
- return item;
- }
- public InvGameItem Unequip(InvBaseItem.Slot slot)
- {
- return this.Replace(slot, null);
- }
- public bool HasEquipped(InvGameItem item)
- {
- if (this.mItems != null)
- {
- int i = 0;
- int num = this.mItems.Length;
- while (i < num)
- {
- if (this.mItems[i] == item)
- {
- return true;
- }
- i++;
- }
- }
- return false;
- }
- public bool HasEquipped(InvBaseItem.Slot slot)
- {
- if (this.mItems != null)
- {
- int i = 0;
- int num = this.mItems.Length;
- while (i < num)
- {
- InvBaseItem baseItem = this.mItems[i].baseItem;
- if (baseItem != null && baseItem.slot == slot)
- {
- return true;
- }
- i++;
- }
- }
- return false;
- }
- public InvGameItem GetItem(InvBaseItem.Slot slot)
- {
- if (slot != InvBaseItem.Slot.None)
- {
- int num = slot - InvBaseItem.Slot.Weapon;
- if (this.mItems != null && num < this.mItems.Length)
- {
- return this.mItems[num];
- }
- }
- return null;
- }
- private InvGameItem[] mItems;
- private InvAttachmentPoint[] mAttachments;
- }
|