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(); } 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(); 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; }