Пример #1
0
        private void AbilityTerminated(AbilityHolder abilityHolder, bool didExecutionCompleted)
        {
            abilityHolder.Ability.OnAbilityTerminated -= OnAbilityTerminated;

            OnAbilityTerminated?.Invoke(abilityHolder.Ability, didExecutionCompleted);

            /*if(abilityHolder != null)
             *  Destroy(abilityHolder.gameObject);*/
        }
Пример #2
0
        public bool TryDeattachAbility(int abilityIndex)
        {
            AbilityHolder abilityHolder = GetAbilityHolder(abilityIndex);

            if (abilityHolder == null)
            {
                return(false);
            }

            AbilityHolders.Remove(abilityHolder);

            UnityEngine.Object.Destroy(abilityHolder);

            return(true);
        }
Пример #3
0
        public bool TryAttachAbility(
            AbilityHolder abilityHolder,
            int abilityIndex)
        {
            if (GetAbilityHolder(abilityIndex) != null)
            {
                return(false);
            }

            abilityHolder.AbilityIndex = abilityIndex;

            AbilityHolders.Add(abilityHolder);

            return(true);
        }
Пример #4
0
        private bool TryCreateAbility(int abilityIndex, out AbilityHolder abilityHolder)
        {
            abilityHolder = null;

            AbilityCreator ac = GetAbilityHolder(abilityIndex);

            if (ac == null)
            {
                return(false);
            }

            abilityHolder = ac.SelfAbilityHolder;

            return(true);
        }
Пример #5
0
        public bool TryCastAbility(
            int abilityIndex,
            out Ability ability,
            AbilityMessage message = null,
            IAbilityActionMessage triggeringMessage     = null,
            Action <Ability> onCastingCallback          = null,
            Action <Ability, bool> onTerminatedCallback = null)
        {
            AbilityHolder abilityHolder = null;

            ability = null;

            if (!TryCreateAbility(abilityIndex, out abilityHolder))
            {
                return(false);
            }

            ability = abilityHolder.Ability;
            ability.ResetResetable();

            ability.OnAbilityTerminated += onAbilityTerminated;

            onCastingCallback?.Invoke(ability);

            ability.Cast(this, message, triggeringMessage);

            void onAbilityTerminated(Ability terminatedAbility, bool didExecutionCompleted)
            {
                terminatedAbility.OnAbilityTerminated -= onAbilityTerminated;

                onTerminatedCallback?.Invoke(terminatedAbility, didExecutionCompleted);
                AbilityTerminated(abilityHolder, didExecutionCompleted);
            }

            OnAbilityCasted?.Invoke(ability);

            return(true);
        }