Exemplo n.º 1
0
        public IUtilityAi Create(Info.AiInfo info)
        {
            if (!AIs.Contains(info.Id))
            {
                _CreateAiDynamic(info);
            }

            return(AIs.GetAi(info.Id));
        }
Exemplo n.º 2
0
        private void _CreateAiDynamic(Info.AiInfo info)
        {
            var actions = new List <IAction>();

            foreach (var actioninfo in info.Actions)
            {
                var newAction = Actions.Create(actioninfo.RefAction);

                if (newAction == null)
                {
                    throw new NullReferenceException();
                }
                newAction.Initialize(actioninfo);
                actions.Add(newAction);
            }

            var considerations = new List <IConsideration>();

            foreach (var considerationinfo in info.Considerations)
            {
                var newConsideration = Considerations.Create(considerationinfo.RefConsideration);

                if (newConsideration == null)
                {
                    throw new NullReferenceException();
                }
                newConsideration.Initialize(considerationinfo);
                considerations.Add(newConsideration);
            }
            var options = new List <IOption>();

            foreach (var optionInfo in info.Options)
            {
                var action            = actions[optionInfo.ActionInfoIndex];
                var subConsiderations = new List <IConsideration>();
                foreach (var indexConsideration in optionInfo.ConsiderationInfoIndexes)
                {
                    subConsiderations.Add(considerations[indexConsideration]);
                }
                var newOption = new DynamicOption(action, subConsiderations, optionInfo);
                options.Add(newOption);
            }

            var behaviours = new List <IBehaviour>();

            foreach (var behaviourInfo in info.Behaviours)
            {
                var subOptions = new List <IOption>();
                foreach (var indexOption in behaviourInfo.OptionInfoIndexes)
                {
                    subOptions.Add(options[indexOption]);
                }
                var subConsiderations = new List <IConsideration>();
                foreach (var indexConsideration in behaviourInfo.ConsiderationInfoIndexes)
                {
                    subConsiderations.Add(considerations[indexConsideration]);
                }
                var newBehaviour = new DynamicBehaviours(subOptions, subConsiderations, behaviourInfo);
                behaviours.Add(newBehaviour);
            }

            var newAi = new DynamicAi(behaviours);

            AIs.Add(newAi);
        }
Exemplo n.º 3
0
        private void PopulateFakeData()
        {
            var id = new InfoId()
            {
                NamespaceId = "Entity", NameId = "Dear"
            };
            var considerations = new ConsiderationInfo[]
            {
                new ConsiderationInfo()
                {
                    Name             = "Thirst",
                    RefConsideration = new IdInfoIndex(0, 0),
                    ModeCurve        = 0,
                    Invert           = false,
                    ExtraValues      = new float[] { 0f, 0f, 1f, 1f },
                }
            };
            var actions = new ActionInfo[]
            {
                new ActionInfo()
                {
                    Name      = "Idle",
                    RefAction = new IdInfoIndex(0, 0),
                },
                new ActionInfo()
                {
                    Name      = "Drink",
                    RefAction = new IdInfoIndex(0, 1),
                },
            };
            var options = new OptionInfo[]
            {
                new OptionInfo()
                {
                    Name                     = "Drink",
                    ActionInfoIndex          = 1,
                    ConsiderationInfoIndexes = new int[] { 0 },
                    ModeMeasure              = 0,
                },
                new OptionInfo()
                {
                    Name                     = "Idle",
                    ActionInfoIndex          = 0,
                    ConsiderationInfoIndexes = new int[] {},
                    ModeMeasure              = 0,
                },
            };
            var behaviours = new BehaviourInfo[]
            {
                new BehaviourInfo()
                {
                    Name = "Normal",
                    OptionInfoIndexes        = new int[] { 0, 1 },
                    ConsiderationInfoIndexes = new int[] { 0 },
                }
            };

            Data = new AiInfo()
            {
                Id             = id,
                Actions        = actions,
                Considerations = considerations,
                Options        = options,
                Behaviours     = behaviours,
            };

            UnityEditor.EditorUtility.SetDirty(this);
        }