Example #1
0
        /// <summary>Makes an copy of an already existing AbilityEffectRunAction component.</summary>
        /// <param name="detach">You only need to detach once per copy, this this might be unnecessary.</param>
        /// <returns></returns>
        public static AbilityEffectRunAction CloneAbilityActionList(this BlueprintAbility ability, bool detach = true)
        {
            //this might do something similar, I couldn't figure out what it does: ability.ReplaceComponent<AbilityEffectRunAction>( a => { } );
            var orig = ability.GetComponent <AbilityEffectRunAction>();

            var result = new AbilityEffectRunAction();

            result.SavingThrowType = orig.SavingThrowType;
            result.Actions         = new ActionList();
            result.Actions.Actions = new GameAction[orig.Actions.Actions.Length];

            for (int i = 0; i < orig.Actions.Actions.Length; i++)
            {
                result.Actions.Actions[i] = UnityEngine.Object.Instantiate(orig.Actions.Actions[i]);
            }

            if (detach)
            {
                ability.DetachComponents();
            }
            ability.ReplaceDirty(result);
            return(result);
        }