示例#1
0
        public static AIActionGroup SyncActions(ActionGroupType type, AIActionGroup group, IEnumerable <IAIAction> actions, ParallelPassOptions parPassOptions = 0)
        {
            var repeat = (group != null) ? group.Repeat : RepeatMode.Never;
            var always = (group != null) ? group.AlwaysSucceed : false;

            switch (type)
            {
            case ActionGroupType.Sequential:
            {
                if (group is SequenceAction)
                {
                    group.SetActions(actions);
                }
                else
                {
                    group = new SequenceAction(actions);
                }
                break;
            }

            case ActionGroupType.Selector:
            {
                if (group is SelectorAction)
                {
                    group.SetActions(actions);
                }
                else
                {
                    group = new SelectorAction(actions);
                }
                break;
            }

            case ActionGroupType.Parrallel:
            {
                if (group is ParallelAction)
                {
                    group.SetActions(actions);
                    (group as ParallelAction).PassOptions = parPassOptions;
                }
                else
                {
                    group = new ParallelAction(actions)
                    {
                        PassOptions = parPassOptions
                    }
                };
                break;
            }

            case ActionGroupType.Random:
            {
                if (group is RandomAction)
                {
                    group.SetActions(actions);
                }
                else
                {
                    group = new RandomAction(actions);
                }
                break;
            }

            default:
                throw new System.ArgumentException("Unknown ActionGroupType.");
            }

            group.Repeat        = repeat;
            group.AlwaysSucceed = always;
            return(group);
        }
示例#2
0
        public static AIActionGroup SyncActions(ActionGroupType type, AIActionGroup group, GameObject source, bool findWeightSupplier, ParallelPassOptions parPassOptions = 0)
        {
            var repeat = (group != null) ? group.Repeat : RepeatMode.Never;
            var always = (group != null) ? group.AlwaysSucceed : false;

            //var actions = source.GetComponentsAlt<IAIAction>();
            using (var actions = com.spacepuppy.Collections.TempCollection.GetList <IAIAction>())
            {
                source.GetComponents <IAIAction>(actions, (c) =>
                {
                    if (c is IAIAction)
                    {
                        return(c as IAIAction);
                    }
                    else if (c is com.spacepuppy.Scenario.ITriggerableMechanism)
                    {
                        return(new TriggerableMechanismAsAIActionWrapper(c as com.spacepuppy.Scenario.ITriggerableMechanism));
                    }
                    else
                    {
                        return(null);
                    }
                });

                switch (type)
                {
                case ActionGroupType.Sequential:
                {
                    if (group is SequenceAction)
                    {
                        group.SetActions(actions);
                    }
                    else
                    {
                        group = new SequenceAction(actions);
                    }
                    break;
                }

                case ActionGroupType.Selector:
                {
                    if (group is SelectorAction)
                    {
                        group.SetActions(actions);
                    }
                    else
                    {
                        group = new SelectorAction(actions);
                    }
                    break;
                }

                case ActionGroupType.Parrallel:
                {
                    if (group is ParallelAction)
                    {
                        group.SetActions(actions);
                        (group as ParallelAction).PassOptions = parPassOptions;
                    }
                    else
                    {
                        group = new ParallelAction(actions)
                        {
                            PassOptions = parPassOptions
                        }
                    };
                    break;
                }

                case ActionGroupType.Random:
                {
                    if (group is RandomAction)
                    {
                        group.SetActions(actions);
                    }
                    else
                    {
                        group = new RandomAction(actions);
                    }

                    if (findWeightSupplier)
                    {
                        IAIActionWeightSupplier supplier;
                        if (source.GetComponent <IAIActionWeightSupplier>(out supplier))
                        {
                            (group as RandomAction).WeightSupplier = supplier;
                        }
                    }
                    break;
                }

                default:
                    throw new System.ArgumentException("Unknown ActionGroupType.");
                }
            }

            group.Repeat        = repeat;
            group.AlwaysSucceed = always;
            return(group);
        }
        private void Resync()
        {
            var actions = (_loop != null) ? _loop : Enumerable.Empty <IAIAction>();

            _loop = AIActionGroup.SyncActions(_loopMode, _loop, actions, _passOptions);
        }
 public void SyncActions(GameObject source, bool findWeightSupplier)
 {
     _loop = AIActionGroup.SyncActions(_loopMode, _loop, source, findWeightSupplier, _passOptions);
 }
 public void SyncActions(IEnumerable <IAIAction> actions)
 {
     _loop = AIActionGroup.SyncActions(_loopMode, _loop, actions, _passOptions);
 }
 public void SetEmpty()
 {
     _loop = AIActionGroup.SyncActions(_loopMode, _loop, Enumerable.Empty <IAIAction>(), _passOptions);
 }