コード例 #1
0
    // Swaps a weapon with a new weapon
    public void SwapWeapon(int weaponID, WeaponData newWeaponData)
    {
        if (weaponID < 0 || weaponID >= lWeapons.Count)
        {
            return;
        }

        lWeapons[weaponID].RemoveWeapon();
        Destroy(lWeapons[weaponID].gameObject);

        // Weapon Game Object
        GameObject weaponObject = newWeaponData.GOInstantiateWeapon(transform);

        // Weapon Behaviour to be added to the list
        WeaponBehaviour weaponBehaviour = weaponObject.GetComponent <WeaponBehaviour>();

        weaponBehaviour.SetPlayerController(this);
        lWeapons[weaponID] = weaponBehaviour;

        // Weapon Parent Bone
        string parentBone;

        if (iCurrentWeaponIndex != weaponID)
        {
            // Holster Transform
            parentBone = weaponBehaviour.HoldType == eWeaponHoldType.Secondary ?
                         sSecondaryWeaponHolsterBone : sPrimaryWeaponHolsterBone;
            weaponBehaviour.bHolstered = true;
        }
        else
        {
            // Aiming Hand Transform
            parentBone = bFacingLeft ? sWeaponRearHandBone : sWeaponFrontHandBone;
            weaponBehaviour.bHolstered = false;

            if (aOnWeaponEquip != null) // Otherwise trigger Equip Action
            {
                aOnWeaponEquip();
            }
        }

        // Set Parent, Position and Rotation
        BoneFollower follower = weaponObject.GetComponent <BoneFollower>();

        follower.skeletonRenderer = animator.skeleton;
        follower.boneName         = parentBone;
    }
コード例 #2
0
    // Adds a new weapon to the weapon list via Weapon ID
    public void AddWeapon(WeaponData weaponData)
    {
        // If no room for new weapon, return
        if (lWeapons.Count >= iMaxWeaponCount)
        {
            return;
        }

        // Weapon Game Object
        GameObject weaponObject = weaponData.GOInstantiateWeapon(transform);

        // Weapon Behaviour to be added to the list
        WeaponBehaviour weaponBehaviour = weaponObject.GetComponent <WeaponBehaviour>();

        weaponBehaviour.SetPlayerController(this);
        lWeapons.Add(weaponBehaviour);

        // Weapon Parent Bone
        string parentBone;

        if (iCurrentWeaponIndex != lWeapons.Count - 1)
        {
            // Holster Transform
            parentBone = weaponBehaviour.HoldType == eWeaponHoldType.Secondary ?
                         sSecondaryWeaponHolsterBone : sPrimaryWeaponHolsterBone;
            weaponBehaviour.bHolstered = true;
        }
        else
        {
            // Aiming Hand Transform
            parentBone = bFacingLeft ? sWeaponRearHandBone : sWeaponFrontHandBone;
            weaponBehaviour.bHolstered = false;

            if (aOnWeaponEquip != null) // Otherwise trigger Equip Action
            {
                aOnWeaponEquip();
            }
        }

        // Set Parent, Position and Rotation
        BoneFollower follower = weaponObject.GetComponent <BoneFollower>();

        follower.skeletonRenderer = animator.skeleton;
        follower.boneName         = parentBone;
    }