Ejemplo n.º 1
0
        /// <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;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Instantiates the specified item and equips it. We return the instantiated item.
        /// </summary>
        /// <param name="rItemID">String representing the name or ID of the item to equip</param>
        /// <param name="rSlotID">String representing the name or ID of the slot to equip</param>
        /// <param name="rResourcePath">Alternate resource path to override the ItemID's</param>
        /// <returns>GameObject that is the instance or null if it could not be created</returns>
        public virtual GameObject EquipItem(string rItemID, string rSlotID, string rResourcePath = "")
        {
            BasicInventoryItem lItem = GetInventoryItem(rItemID);

            if (lItem == null)
            {
                return(null);
            }

            string lResourcePath = rResourcePath;

            if (lResourcePath.Length == 0)
            {
                lResourcePath = lItem.ResourcePath;
            }

            if (lItem.Instance == null)
            {
                GameObject lGameObject = CreateAndMountItem(gameObject, lResourcePath, lItem.LocalPosition, lItem.LocalRotation, rSlotID);
                if (lGameObject != null)
                {
                    lItem.Instance = lGameObject;
                }
            }
            else
            {
                MountItem(gameObject, lItem.Instance, lItem.LocalPosition, lItem.LocalRotation, rSlotID);
            }

            if (lItem.Instance != null)
            {
                IItemCore lItemCore = lItem.Instance.GetComponent <IItemCore>();
                if (lItemCore != null)
                {
                    lItemCore.OnEquipped();
                }

                BasicInventorySlot lSlot = GetInventorySlot(rSlotID);
                if (lSlot != null)
                {
                    lSlot.ItemID = rItemID;
                }
            }

            return(lItem.Instance);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Instantiates the specified item and equips it. We return the instantiated item.
        /// </summary>
        /// <param name="rItemID">String representing the name or ID of the item to equip</param>
        /// <param name="rSlotID">String representing the name or ID of the slot to equip</param>
        /// <param name="rResourcePath">Alternate resource path to override the ItemID's</param>
        /// <returns>GameObject that is the instance or null if it could not be created</returns>
        public virtual GameObject EquipItem(string rItemID, string rSlotID, string rResourcePath = "")
        {
            string lResourcePath = rResourcePath;

            Vector3    lLocalPosition = Vector3.zero;
            Quaternion lLocalRotation = Quaternion.identity;

            GameObject lGameObject = CreateAndMountItem(mMotionController.gameObject, lResourcePath, lLocalPosition, lLocalRotation, rSlotID);

            if (lGameObject != null)
            {
                IItemCore lItemCore = lGameObject.GetComponent <IItemCore>();
                if (lItemCore != null)
                {
                    lItemCore.OnEquipped();
                }
            }

            return(lGameObject);
        }
Ejemplo n.º 4
0
        /// <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
                if (mMountPoints != null)
                {
                    MountPoint lParentMountPoint = mMountPoints.GetMountPoint(lSlot.ID);
                    if (lParentMountPoint != null)
                    {
                        mMountPoints.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
                    if (mMountPoints != null)
                    {
                        MountPoint lParentMountPoint = mMountPoints.GetMountPoint(lItem.StoredParent.name);
                        if (lParentMountPoint == null)
                        {
                            lParentMountPoint = mMountPoints.GetMountPoint(lItem.StoredParent);
                        }
                        if (lParentMountPoint != null)
                        {
                            lIsAttached = mMountPoints.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 = "";
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Mounts the item to the specified position based on the ItemCore
        /// </summary>
        /// <param name="rParent">Parent GameObject</param>
        /// <param name="rItem">Child GameObject that is this item</param>
        /// <param name="rLocalPosition">Vector3 that is the local position to set when the item is parented.</param>
        /// <param name="rLocalRotation">Quaternion that is the local rotation to set when the item is parented.</param>
        /// <param name="rParentMountPoint">Name of the parent mount point we're tying the item to</param>
        /// <param name="rItemMountPoint">Name of the child mount point we're tying the item to</param>
        protected virtual void MountItem(GameObject rParent, GameObject rItem, Vector3 rLocalPosition, Quaternion rLocalRotation, string rParentMountPoint, string rItemMountPoint = "Handle")
        {
            if (rParent == null || rItem == null)
            {
                return;
            }

            bool lIsConnected = false;

            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 = mMotionController.gameObject;

                if (rLocalPosition.sqrMagnitude == 0f && QuaternionExt.IsIdentity(rLocalRotation))
                {
                    rItem.transform.localPosition = (lItemCore.LocalPosition);
                    rItem.transform.localRotation = (lItemCore.LocalRotation);
                }
                else
                {
                    rItem.transform.localPosition = rLocalPosition;
                    rItem.transform.localRotation = rLocalRotation;
                }
            }
            else
            {
                rItem.transform.localPosition = rLocalPosition;
                rItem.transform.localRotation = rLocalRotation;
            }

            // Reenable the item as needed
            rItem.SetActive(true);
            rItem.hideFlags = HideFlags.None;

            // Inform the combatant of the change
            ICombatant lCombatant = mMotionController.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" || lCleanParentMountPoint == "leftlowerarm")
                    {
                        lCombatant.SecondaryWeapon = lWeaponCore;
                    }
                }
            }
        }