/// <summary> /// Equip the specified item automatically replacing an existing one. /// </summary> public InvGameItem Replace(InvBaseItem.Slot slot, InvGameItem item) { InvBaseItem baseItem = (item != null) ? item.baseItem : null; if (slot != InvBaseItem.Slot.None) { // If the item is not of appropriate type, we shouldn't do anything if (baseItem != null && baseItem.slot != slot) { return(item); } if (mItems == null) { // Automatically figure out how many item slots we need int count = (int)InvBaseItem.Slot._LastDoNotUse; mItems = new InvGameItem[count]; } // Equip this item InvGameItem prev = mItems[(int)slot - 1]; mItems[(int)slot - 1] = item; // Get the list of all attachment points if (mAttachments == null) { mAttachments = GetComponentsInChildren <InvAttachmentPoint>(); } // Equip the item visually for (int i = 0, imax = mAttachments.Length; i < imax; ++i) { InvAttachmentPoint ip = mAttachments[i]; if (ip.slot == slot) { GameObject go = ip.Attach(baseItem != null ? baseItem.attachment : null); if (baseItem != null && go != null) { Renderer ren = go.GetComponent <Renderer>(); if (ren != null) { ren.material.color = baseItem.color; } } } } return(prev); } else if (item != null) { Debug.LogWarning("Can't equip \"" + item.name + "\" because it doesn't specify an item slot"); } return(item); }
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 Replace(InvBaseItem.Slot slot, InvGameItem item) { InvBaseItem item2 = (item == null) ? null : item.baseItem; if (slot != InvBaseItem.Slot.None) { if ((item2 != null) && (item2.slot != slot)) { return(item); } if (this.mItems == null) { int num = 8; this.mItems = new InvGameItem[num]; } InvGameItem item3 = this.mItems[((int)slot) - 1]; this.mItems[((int)slot) - 1] = item; if (this.mAttachments == null) { this.mAttachments = base.GetComponentsInChildren <InvAttachmentPoint>(); } int index = 0; int length = this.mAttachments.Length; while (index < length) { InvAttachmentPoint point = this.mAttachments[index]; if (point.slot == slot) { GameObject obj2 = point.Attach((item2 == null) ? null : item2.attachment); if ((item2 != null) && (obj2 != null)) { Renderer renderer = obj2.renderer; if (renderer != null) { renderer.material.color = item2.color; } } } index++; } return(item3); } if (item != null) { Debug.LogWarning("Can't equip \"" + item.name + "\" because it doesn't specify an item slot"); } return(item); }
public InvGameItem Replace(InvBaseItem.Slot slot, InvGameItem item) { InvBaseItem invBaseItem = item?.baseItem; if (slot != 0) { if (invBaseItem != null && invBaseItem.slot != slot) { return(item); } if (mItems == null) { int num = 8; mItems = new InvGameItem[num]; } InvGameItem result = mItems[(int)(slot - 1)]; mItems[(int)(slot - 1)] = item; if (mAttachments == null) { mAttachments = GetComponentsInChildren <InvAttachmentPoint>(); } int i = 0; for (int num2 = mAttachments.Length; i < num2; i++) { InvAttachmentPoint invAttachmentPoint = mAttachments[i]; if (invAttachmentPoint.slot != slot) { continue; } GameObject gameObject = invAttachmentPoint.Attach(invBaseItem?.attachment); if (invBaseItem != null && gameObject != null) { Renderer renderer = gameObject.renderer; if (renderer != null) { renderer.material.color = invBaseItem.color; } } } return(result); } if (item != null) { Debug.LogWarning("Can't equip \"" + item.name + "\" because it doesn't specify an item slot"); } return(item); }