示例#1
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 void MountItem(GameObject rParent, GameObject rItem, Vector3 rLocalPosition, Quaternion rLocalRotation, string rParentMountPoint, string rItemMountPoint = "Handle")
        {
            if (rParent == null || rItem == null)
            {
                return;
            }

            bool lIsConnected = false;

#if USE_MOUNT_POINTS
            if (mMountPoints != null)
            {
                lIsConnected = mMountPoints.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;

                    if (rLocalPosition.sqrMagnitude == 0f && QuaternionExt.IsIdentity(rLocalRotation))
                    {
                        rItem.transform.localPosition = (lItemCore != null ? lItemCore.LocalPosition : Vector3.zero);
                        rItem.transform.localRotation = (lItemCore != null ? lItemCore.LocalRotation : Quaternion.identity);
                    }
                    else
                    {
                        rItem.transform.localPosition = rLocalPosition;
                        rItem.transform.localRotation = rLocalRotation;
                    }
                }
                else
                {
                    rItem.transform.localPosition = rLocalPosition;
                    rItem.transform.localRotation = rLocalRotation;
                }
            }

            // 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" || lCleanParentMountPoint == "leftlowerarm")
                        {
                            lCombatant.SecondaryWeapon = lWeaponCore;
                        }
                    }
                }
            }
        }
示例#2
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;
                    }
                }
            }
        }