private static bool TryFindActionVisualizer(IAction source, IAction target, out ActionVisualizer result)
        {
            result = null;
            ActionVisualizer actionVisualizer = source as ActionVisualizer;

            if (actionVisualizer == null)
            {
                return(false);
            }
            if (actionVisualizer.action == target)
            {
                result = actionVisualizer;
                return(true);
            }
            ICompositeVisualizer compositeVisualizer = actionVisualizer as ICompositeVisualizer;

            if (compositeVisualizer == null)
            {
                return(false);
            }
            int count = compositeVisualizer.children.Count;

            for (int i = 0; i < count; i++)
            {
                if (UtilityAIVisualizer.TryFindActionVisualizer(compositeVisualizer.children[i] as IAction, target, out result))
                {
                    return(true);
                }
            }
            return(false);
        }
Example #2
0
        internal override void Init()
        {
            IUtilityAI utilityAI = ((AILinkAction)base.action).linkedAI;

            if (utilityAI != null)
            {
                List <UtilityAIVisualizer> utilityAIVisualizers = base.parent.parent.parent.linkedAIs;
                this._linkedAI = utilityAIVisualizers.FirstOrDefault <UtilityAIVisualizer>((UtilityAIVisualizer lai) => lai.id == utilityAI.id);
                if (this._linkedAI == null)
                {
                    this._linkedAI = new UtilityAIVisualizer(utilityAI);
                    utilityAIVisualizers.Add(this._linkedAI);
                }
            }
        }
        internal override void Init()
        {
            var ai = ((AILinkAction)this.action).linkedAI;

            if (ai != null)
            {
                //We only want a single representation of a linked AI, otherwise multiple connections to the same linked AI in the same AI will not work as intended.
                var existingLinked = parent.parent.parent.linkedAIs;
                _linkedAI = existingLinked.FirstOrDefault(lai => lai.id == ai.id);
                if (_linkedAI == null)
                {
                    _linkedAI = new UtilityAIVisualizer(ai);
                    existingLinked.Add(_linkedAI);
                }
            }
        }
Example #4
0
        internal SelectorVisualizer(Selector s, UtilityAIVisualizer parent)
        {
            this._selector = s;
            this._parent   = parent;
            List <IQualifier> qualifiers = this._selector.qualifiers;
            int count = qualifiers.Count;

            for (int i = 0; i < count; i++)
            {
                IQualifier item = qualifiers[i];
                if (!(item is ICompositeScorer))
                {
                    base.qualifiers.Add(new QualifierVisualizer(item, this));
                }
                else
                {
                    base.qualifiers.Add(new CompositeQualifierVisualizer((ICompositeScorer)item, this));
                }
            }
            base.defaultQualifier = new DefaultQualifierVisualizer(this._selector.defaultQualifier, this);
        }
        internal SelectorVisualizer(Selector s, UtilityAIVisualizer parent)
        {
            _selector = s;
            _parent   = parent;

            var sourceQualifiers = _selector.qualifiers;
            var qualifierCount   = sourceQualifiers.Count;

            for (int i = 0; i < qualifierCount; i++)
            {
                var q = sourceQualifiers[i];
                if (q is ICompositeScorer)
                {
                    this.qualifiers.Add(new CompositeQualifierVisualizer((ICompositeScorer)q, this));
                }
                else
                {
                    this.qualifiers.Add(new QualifierVisualizer(q, this));
                }
            }

            this.defaultQualifier = new DefaultQualifierVisualizer(_selector.defaultQualifier, this);
        }
        internal ActionVisualizer FindActionVisualizer(IAction target)
        {
            ActionVisualizer actionVisualizer = null;
            int count = this._selectorVisualizers.Count;

            for (int i = 0; i < count; i++)
            {
                SelectorVisualizer item = this._selectorVisualizers[i];
                int num = item.qualifiers.Count;
                for (int j = 0; j < num; j++)
                {
                    if (UtilityAIVisualizer.TryFindActionVisualizer(((IQualifierVisualizer)item.qualifiers[j]).action, target, out actionVisualizer))
                    {
                        return(actionVisualizer);
                    }
                }
                if (UtilityAIVisualizer.TryFindActionVisualizer(item.defaultQualifier.action, target, out actionVisualizer))
                {
                    return(actionVisualizer);
                }
            }
            return(null);
        }