Exemple #1
0
        void OnClickAddQualifier(Vector2 mousePosition, Type type)
        {
            var qualifier = (Qualifier)Activator.CreateInstance(type);

            qualifier.name = type.FullName;

            AssetDatabase.AddObjectToAsset(qualifier, brain);

            var node = new QualifierNode(qualifier, context);

            nodes.Add(node);

            GUI.changed = true;
        }
Exemple #2
0
        void Rebuild(Brain brain)
        {
            Clear();

            brainNode = new BrainNode(brain, context);
            nodes.Add(brainNode);

            var selectorNodes = new List <SelectorNode>();
            var assets        = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(brain));

            foreach (var asset in assets)
            {
                var selector = asset as Selector;
                if (selector != null)
                {
                    var sn = new SelectorNode(selector, context);
                    nodes.Add(sn);
                    selectorNodes.Add(sn);

                    if (brain.root == selector)
                    {
                        var c = new Connection(brainNode.rootIn, sn.selectorOut, OnClickRemoveConnection);
                        connections.Add(c);
                    }
                }
            }

            var qualifierNodes = new List <QualifierNode>();

            foreach (var asset in assets)
            {
                var qualifier = asset as Qualifier;
                if (qualifier != null)
                {
                    var qn = new QualifierNode(qualifier, context);
                    nodes.Add(qn);
                    qualifierNodes.Add(qn);



                    foreach (var sn in selectorNodes)
                    {
                        if (qualifier.selector == sn.selector)
                        {
                            var c = new Connection(sn.selectorOut, qn.actionOrSelectorIn, OnClickRemoveConnection);
                            connections.Add(c);
                        }

                        if (sn.selector.qualifiers != null && sn.selector.qualifiers.Contains(qualifier))
                        {
                            var c = new Connection(sn.qualifiersIn, qn.qualifierOut, OnClickRemoveConnection);
                            connections.Add(c);
                        }
                    }
                }
            }

            var actionNodes = new List <ActionWithInputsNode>();

            foreach (var asset in assets)
            {
                var actionWithInputs = asset as ActionWithInputsBase;
                if (actionWithInputs != null)
                {
                    var an = new ActionWithInputsNode(actionWithInputs, context);
                    nodes.Add(an);
                    actionNodes.Add(an);

                    foreach (var qn in qualifierNodes)
                    {
                        if (qn.qualifier.action == actionWithInputs)
                        {
                            var c = new Connection(qn.actionOrSelectorIn, an.actionOut, OnClickRemoveConnection);
                            connections.Add(c);
                        }
                    }

                    continue;
                }

                var action = asset as ActionBase;
                if (action != null)
                {
                    var an = new ActionNode(action, context);
                    nodes.Add(an);

                    foreach (var qn in qualifierNodes)
                    {
                        if (qn.qualifier.action == action)
                        {
                            var c = new Connection(qn.actionOrSelectorIn, an.actionOut, OnClickRemoveConnection);
                            connections.Add(c);
                        }
                    }
                }
            }

            foreach (var asset in assets)
            {
                var scorer = asset as ContextualScorerBase;
                if (scorer != null)
                {
                    var an = new ContextualScorerNode(scorer, context);
                    nodes.Add(an);

                    foreach (var qn in qualifierNodes)
                    {
                        if (qn.qualifier.scorers.Contains(scorer))
                        {
                            var c = new Connection(qn.scorersIn, an.scorerOut, OnClickRemoveConnection);
                            connections.Add(c);
                        }
                    }
                }
            }

            foreach (var asset in assets)
            {
                var scorer = asset as InputScorerBase;
                if (scorer != null)
                {
                    var sn = new InputScorerNode(scorer, context);
                    nodes.Add(sn);

                    foreach (var an in actionNodes)
                    {
                        var action = an.actionWithInputs as ActionWithInputsBase;
                        if (action != null && action.scorers.Contains(scorer))
                        {
                            var c = new Connection(an.inputScorersIn, sn.scorerOut, OnClickRemoveConnection);
                            connections.Add(c);
                        }
                    }
                }
            }
        }