Ejemplo n.º 1
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.º 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 = "")
        {
            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);
        }