/// <summary> /// Mounts the item to the specified position based on the ItemCore /// </summary> /// <param name="rParent"></param> /// <param name="rItem"></param> /// <param name="rParentMountPoint"></param> protected void MountItem(GameObject rParent, GameObject rItem, string rParentMountPoint, string rItemMountPoint = "Handle") { if (rParent == null || rItem == null) { return; } bool lIsConnected = false; #if USE_MOUNT_POINTS com.ootii.Actors.MountPoints lMountPoints = rParent.GetComponent <com.ootii.Actors.MountPoints>(); if (lMountPoints != null) { lIsConnected = lMountPoints.ConnectMountPoints(rParentMountPoint, rItem, rItemMountPoint); } #endif if (!lIsConnected) { Transform lParentBone = FindTransform(rParent.transform, rParentMountPoint); rItem.transform.parent = lParentBone; //IItemCore lItemCore = InterfaceHelper.GetComponent<IItemCore>(rItem); IItemCore lItemCore = rItem.GetComponent <IItemCore>(); if (lItemCore != null) { lItemCore.Owner = gameObject; rItem.transform.localPosition = (lItemCore != null ? lItemCore.LocalPosition : Vector3.zero); rItem.transform.localRotation = (lItemCore != null ? lItemCore.LocalRotation : Quaternion.identity); } } // Inform the combatant of the change if (rItem != null) { ICombatant lCombatant = gameObject.GetComponent <ICombatant>(); if (lCombatant != null) { IWeaponCore lWeaponCore = rItem.GetComponent <IWeaponCore>(); if (lWeaponCore != null) { string lCleanParentMountPoint = StringHelper.CleanString(rParentMountPoint); if (lCleanParentMountPoint == "righthand") { lCombatant.PrimaryWeapon = lWeaponCore; } else if (lCleanParentMountPoint == "lefthand") { lCombatant.SecondaryWeapon = lWeaponCore; } } } } }
/// <summary> /// Creates the item and attaches it to the parent mount point /// </summary> /// <param name="rParent">GameObject that is the parent (typically a character)</param> /// <param name="rResourcePath">String that is the resource path to the item</param> /// <param name="rLocalPosition">Position the item will have relative to the parent mount point</param> /// <param name="rLocalRotation">Rotation the item will have relative to the parent mount pont</param> /// <returns></returns> protected GameObject CreateAndMountItem(GameObject rParent, string rResourcePath, string rParentMountPoint = "Left Hand", string rItemMountPoint = "Handle") { GameObject lItem = null; if (rResourcePath.Length > 0) { #if USE_MOUNT_POINTS com.ootii.Actors.MountPoints lMountPoints = rParent.GetComponent <com.ootii.Actors.MountPoints>(); if (lMountPoints != null) { lItem = lMountPoints.ConnectMountPoints(rParentMountPoint, rResourcePath, rItemMountPoint); } #endif // Create and mount if we need to if (lItem == null) { Animator lAnimator = rParent.GetComponentInChildren <Animator>(); if (lAnimator != null) { lItem = GameObject.Instantiate(Resources.Load(rResourcePath)) as GameObject; MountItem(rParent, lItem, rParentMountPoint); } } // Inform the combatant of the change else { ICombatant lCombatant = gameObject.GetComponent <ICombatant>(); if (lCombatant != null) { IWeaponCore lWeaponCore = lItem.GetComponent <IWeaponCore>(); if (lWeaponCore != null) { string lCleanParentMountPoint = StringHelper.CleanString(rParentMountPoint); if (lCleanParentMountPoint == "righthand") { lCombatant.PrimaryWeapon = lWeaponCore; } else if (lCleanParentMountPoint == "lefthand") { lCombatant.SecondaryWeapon = lWeaponCore; } } } } } return(lItem); }
/// <summary> /// Instantiates the specified item and equips it. We return the instantiated item. /// </summary> /// <param name="rSlotID">String representing the name or ID of the slot to clear</param> public virtual void StoreItem(string rSlotID) { int lSlotIndex = -1; for (int i = 0; i < Slots.Count; i++) { if (Slots[i].ID == rSlotID) { lSlotIndex = i; break; } } if (lSlotIndex < 0) { return; } BasicInventorySlot lSlot = Slots[lSlotIndex]; if (lSlot == null) { return; } BasicInventoryItem lItem = null; for (int i = 0; i < Items.Count; i++) { if (Items[i].ID == lSlot.ItemID) { lItem = Items[i]; break; } } // We need to disconnect the item, but we may need to destroy it as well if (lItem != null && lItem.Instance != null) { IItemCore lItemCore = lItem.Instance.GetComponent <IItemCore>(); if (lItemCore != null) { lItemCore.OnStored(); } // If we know about a combatant, disconnect the weapon ICombatant lCombatant = gameObject.GetComponent <ICombatant>(); if (lCombatant != null) { IWeaponCore lWeaponCore = lItem.Instance.GetComponent <IWeaponCore>(); if (lWeaponCore != null) { if (lCombatant.PrimaryWeapon == lWeaponCore) { lCombatant.PrimaryWeapon = null; } if (lCombatant.SecondaryWeapon == lWeaponCore) { lCombatant.SecondaryWeapon = null; } } } #if USE_MOUNT_POINTS com.ootii.Actors.MountPoints lMountPoints = gameObject.GetComponent <com.ootii.Actors.MountPoints>(); if (lMountPoints != null) { MountPoint lParentMountPoint = lMountPoints.GetMountPoint(lSlot.ID); if (lParentMountPoint != null) { lMountPoints.DisconnectMountPoints(lParentMountPoint, lItem.Instance); } } #endif // Without a stored parent, we destroy it if (lItem.StoredParent == null) { GameObject.Destroy(lItem.Instance); lItem.Instance = null; } else { bool lIsAttached = false; #if USE_MOUNT_POINTS // See if we can attach it using a mount point lMountPoints = lItem.StoredParent.GetComponent <com.ootii.Actors.MountPoints>(); if (lMountPoints != null) { MountPoint lParentMountPoint = lMountPoints.GetMountPoint(lItem.StoredParent.name); if (lParentMountPoint == null) { lParentMountPoint = lMountPoints.GetMountPoint(lItem.StoredParent); } if (lParentMountPoint != null) { lIsAttached = lMountPoints.ConnectMountPoints(lParentMountPoint, lItem.Instance, "Handle"); } } #endif if (!lIsAttached) { lItem.Instance.transform.parent = lItem.StoredParent; lItem.Instance.transform.localPosition = lItem.StoredPosition; lItem.Instance.transform.localRotation = lItem.StoredRotation; } } } lSlot.ItemID = ""; }