Esempio n. 1
0
        /// <summary>
        /// Adds the ability with the specified type.
        /// </summary>
        /// <param name="characterLocomotion">The character to add the ability to.</param>
        /// <param name="abilityType">The type of ability to add.</param>
        /// <returns>The added ability.</returns>
        public static Ability AddAbility(UltimateCharacterLocomotion characterLocomotion, Type abilityType)
        {
            if (typeof(ItemAbility).IsAssignableFrom(abilityType))
            {
                return(AddItemAbility(characterLocomotion, abilityType));
            }

            var abilities = characterLocomotion.GetSerializedAbilities();
            var index     = abilities == null ? 0 : abilities.Length;

            return(AddAbility(characterLocomotion, abilityType, index));
        }
Esempio n. 2
0
        /// <summary>
        /// Adds the ability with the specified type.
        /// </summary>
        /// <param name="characterLocomotion">The character to add the ability to.</param>
        /// <param name="abilityType">The type of ability to add.</param>
        /// <param name="index">The index to add the ability to.</param>
        /// <returns>The added ability.</returns>
        public static Ability AddAbility(UltimateCharacterLocomotion characterLocomotion, Type abilityType, int index)
        {
            var abilities = characterLocomotion.GetSerializedAbilities();

            if (abilities == null)
            {
                abilities = new Ability[1];
            }
            else
            {
                Array.Resize(ref abilities, abilities.Length + 1);
            }
            var ability = Activator.CreateInstance(abilityType) as Ability;

            // Assign the default values specified by any added attribtes.
            SetAbilityDefaultValues(ability);

            for (int i = abilities.Length - 1; i > index; --i)
            {
                abilities[i] = abilities[i - 1];
            }
            abilities[index] = ability;
            characterLocomotion.Abilities = abilities;
            SerializeAbilities(characterLocomotion);

            // The ability may require other components in order to operate.
            var requiredComponents = GetRequiredComponents(abilityType);

            if (requiredComponents != null && requiredComponents.Length > 0)
            {
                for (int i = 0; i < requiredComponents.Length; ++i)
                {
                    characterLocomotion.gameObject.AddComponent(requiredComponents[i].m_Type0);
                }
            }

            return(ability);
        }