Beispiel #1
0
        public void RemoveNodeSource(PotentialFieldNodeSource nodeSource)
        {
            for (int i = 0; i < this.layers.Count; i++)
            {
                var layer = this.layers[i];

                if (layer.IsOneOfLayers(nodeSource.Layers))
                {
                    layer.Sources.Remove(nodeSource);
                }
            }
        }
Beispiel #2
0
        public PotentialFieldNodeSource AddNodeSource(object context, string sourceKey, int layers, float potential = 0f)
        {
            var source = new PotentialFieldNodeSource(context, sourceKey, layers)
            {
                Potential = potential,
                Enabled   = true
            };

            this.AddNodeSource(source);

            return(source);
        }
Beispiel #3
0
        private void AddNextStrongest()
        {
            if (this.isWorking)
            {
                return;
            }

            this.isWorking = true;

            if (this.targetNode == null)
            {
                this.targetNode = this.PotentialField.GetClosestNode(this.tx.position);
            }

            // Disable the target node potential first so that it won't affect the choice of the next node. It will remain
            // disabled if no node with a higher potential is found.
            if (this.targetNodePotential.enabled)
            {
                if (this.targetNodeSource == null)
                {
                    this.targetNodeSource            = this.source.AddNodeSource(this.targetNodePotential.sourceKey, this.targetNodePotential.layers.value, this.targetNodePotential.potential);
                    this.targetNodeSource.Calculator = this.targetNodePotential.calculator as IPotentialCalculator;
                }

                this.targetNodeSource.Enabled = false;
            }

            if (this.filter == null)
            {
                var go = this.gameObject;
                this.filter = (source) => (GameObject)source.Context != go || !ignoreSourceKeys.Contains(source.SourceKey);
            }

            var samples = this.PotentialField.SamplePotential(this.potentialSampler, this.targetNode, this.layerMask, this.filter);

            this.OnNextStrongestSearchFinished(samples);
            samples.ReturnToPool();
        }