コード例 #1
0
        protected override IEnumerator CharacterSetup_SetupCharacter()
        {
            yield return(new WaitForSeconds(0f));

            //Immediately Add Event Handler For Easy Access
            spawnedGameObject.AddComponent <AllyEventHandlerWrapper>();
            // Add the Speed Change ability.
            var controller = spawnedGameObject.GetComponent <RigidbodyCharacterController>();

            AddAllAbilities(controller);
            // Add the weapons from array to the default loadout.
            var inventory      = spawnedGameObject.GetComponent <Inventory>();
            var defaultLoadout = inventory.DefaultLoadout;

            if (defaultLoadout == null)
            {
                defaultLoadout = new Inventory.ItemAmount[0];
            }

            var newLoadout = new List <Inventory.ItemAmount>();

            newLoadout.AddRange(defaultLoadout.ToList());

            //Add Firearms To New Loadout
            foreach (var _firearm in FirearmsToAdd)
            {
                //Add The Firearm
                newLoadout.Add(new Inventory.ItemAmount(_firearm.m_ItemType, 1));
                //Add Ammunition
                newLoadout.Add(new Inventory.ItemAmount(_firearm.m_BulletItemType, _firearm.m_BulletCount));
            }
            //Add Melee Weapons To New Loadout
            foreach (var _melee in MeleeWeaponsToAdd)
            {
                //Add The Melee Weapon
                newLoadout.Add(new Inventory.ItemAmount(_melee.m_ItemType, 1));
            }

            inventory.DefaultLoadout = newLoadout.ToArray();
        }
コード例 #2
0
        /// <summary>
        /// Builds or assigns a new Item.
        /// </summary>
        private void BuildOrAssignItem()
        {
            // If assign to is null than don't change the item transform's parent, otherwise assign it as a child to the specified hand Transform.
            if (m_AssignTo == null)
            {
                if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(m_Base)))
                {
                    var name = m_Base.name;
                    m_Base      = GameObject.Instantiate(m_Base) as GameObject;
                    m_Base.name = name;
                }
                ThirdPersonController.ItemBuilder.BuildItem(m_Base, m_ItemType, m_ItemName, m_Type, m_HandAssignment);
                Selection.activeGameObject = m_Base;
                Close();
            }
            else
            {
                Animator animator = null;
                if ((animator = m_AssignTo.GetComponent <Animator>()) == null)
                {
                    EditorUtility.DisplayDialog("Unable to Assign", "Unable to assign the item. Ensure the Assign To GameObject contains an Animator component.", "Okay");
                }
                else
                {
                    if (m_AddToDefaultLoadout)
                    {
                        var inventory = m_AssignTo.transform.GetComponentInParent <Inventory>();
                        if (inventory == null)
                        {
                            EditorUtility.DisplayDialog("Unable to Add to Default Loadout", "Unable to add the ItemType to the Default Loadout. Ensure the Assign To GameObject contains an Inventory component.", "Okay");
                            return;
                        }
                        var defaultLoadout = inventory.DefaultLoadout;
                        if (defaultLoadout == null)
                        {
                            defaultLoadout = new Inventory.ItemAmount[0];
                        }
                        var canAdd = true;
                        for (int i = 0; i < defaultLoadout.Length; ++i)
                        {
                            // Don't duplicate the ItemType within the loadout.
                            if (defaultLoadout[i].ItemType.Equals(m_ItemType))
                            {
                                canAdd = false;
                                break;
                            }
                        }
                        if (canAdd)
                        {
                            var newLoadout = new Inventory.ItemAmount[defaultLoadout.Length + 1];
                            defaultLoadout.CopyTo(newLoadout, 0);
                            newLoadout[newLoadout.Length - 1] = new Inventory.ItemAmount(m_ItemType, 1);
                            inventory.DefaultLoadout          = newLoadout;
                        }
                    }
                    if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(m_Base)))
                    {
                        var name = m_Base.name;
                        m_Base      = GameObject.Instantiate(m_Base) as GameObject;
                        m_Base.name = name;
                    }
                    var handTransform = animator.GetBoneTransform(m_HandAssignment == ThirdPersonController.ItemBuilder.HandAssignment.Left ? HumanBodyBones.LeftHand : HumanBodyBones.RightHand);
                    if (handTransform != null)
                    {
                        if (handTransform.GetComponentInChildren <ItemPlacement>() == null)
                        {
                            EditorUtility.DisplayDialog("Unable to build Item", "The target character doesn't have a ItemPlacement component under the " + handTransform.name + " GameObject. " +
                                                        "Please create this character with the Character Builder.", "Okay");
                            return;
                        }
                        m_Base.transform.parent = handTransform.GetComponentInChildren <ItemPlacement>().transform;
                    }
                    else
                    {
                        m_Base.transform.parent = m_ItemPlacement.transform;
                    }
                    m_Base.transform.localPosition = Vector3.zero;
                    m_Base.transform.localRotation = Quaternion.identity;

                    ThirdPersonController.ItemBuilder.BuildItem(m_Base, m_ItemType, m_ItemName, m_Type, m_HandAssignment);

                    Selection.activeGameObject = m_Base;
                    Close();
                }
            }
        }