/// <summary>
        /// Generates the <see cref="MoreMountains.Tools.AIBrain"/> system components (Brain, Actions and Decisions)
        /// as defined in the brain graph asset.
        /// </summary>
        public void Generate()
        {
            // The brain graph is mandatory
            if (aiBrainGraph == null)
            {
                Debug.LogError(C.ERROR_NO_AI_BRAIN);
                return;
            }

            // Starts the generation process
            _generatorUtils = new GeneratorUtils(aiBrainGraph, gameObject);
            _generatorUtils.Generate(brainActive, actionsFrequency, decisionFrequency, generateDebugBrain);
        }
Exemple #2
0
        /// <summary>
        /// Returns the label for the transition False state.
        /// </summary>
        /// <returns>The transition False state label</returns>
        public string GetFalseStateLabel()
        {
            var connection = GetOutputPort(C.PORT_FALSE_STATE).Connection;

            if (connection == null)
            {
                return("");
            }
            if (!(GetOutputPort(C.PORT_FALSE_STATE).Connection.node is AIBrainSubgraphNode))
            {
                return(connection.node.name);
            }
            var label = GeneratorUtils.GetSubgraphStateName(connection.node.name, connection.fieldName.Split('-')[0]);

            return(label);
        }
Exemple #3
0
        /// <summary>
        /// On awake we set our brain for all states
        /// </summary>
        protected override void Awake()
        {
            // The brain graph is mandatory
            if (aiBrainGraphs.Count == 0)
            {
                Debug.LogError(C.ERROR_NO_AI_BRAIN);
                return;
            }

            // Starts the generation process
            var graph = aiBrainGraphs[Random.Range(0, aiBrainGraphs.Count)];

            GraphName = graph.name;
            var generator = new GeneratorUtils(graph, gameObject);

            generator.GeneratePluggable(this);

            base.Awake();
        }
        public override void OnBodyGUI()
        {
            _statesIn = serializedObject.FindProperty("statesIn");

            if (Selection.activeObject == _node)
            {
                var optionsList = new List <string>();
                foreach (var node in _node.graph.nodes.OfType <AIBrainStateNode>())
                {
                    optionsList.Add(node.name);
                }
                foreach (var node in _node.graph.nodes.OfType <AIBrainSubgraphNode>())
                {
                    foreach (var stateName in node.inputStates.Select(inputState => GeneratorUtils.GetSubgraphStateName(node.name, inputState.fieldName)))
                    {
                        optionsList.Add(stateName);
                    }
                }

                if (optionsList.Count > 0)
                {
                    var options = optionsList.ToArray();
                    _stateIndex = EditorGUILayout.Popup(_stateIndex, options);
                    EditorGUILayout.Space();
                    _node.stateName = options[_stateIndex];
                }
                else
                {
                    EditorGUILayout.LabelField(C.LABEL_NO_STATE_AVAILABLE);
                    EditorGUILayout.Space();
                }
            }

            serializedObject.Update();
            NodeEditorGUILayout.PropertyField(_statesIn);
            serializedObject.ApplyModifiedProperties();
        }
 public void Cleanup()
 {
     GeneratorUtils.Cleanup(gameObject);
 }