void Update() { if (potentialSys == null) { return; } currentNode = potentialSys.GetClosestNode(transform.position, currentNode); for (int i = 0; i < entries.Length; i++) { var req = new SampleRequest { nodes = new List <IFieldNodeRef> { currentNode }, potentialLayerMask = entries[i].layers }; var potentials = potentialSys.SamplePotential(req); if (Evaluate(potentials[0], entries[i].comparison, entries[i].value)) { signal.DispatchFlag(gameObject, entries[i].flag); } } }
public IList <IFieldNodeRef> GetNeighbours(IFieldNodeRef node) { var graphNode = (SimpleGraphFieldNodeRef)node; var numArcs = this.graph.NumArcsForNode(graphNode.Node); var results = ListPool <IFieldNodeRef> .Take(); for (int i = 0; i < numArcs; i++) { var neighbour = this.graph.GetNodeArc(graphNode.Node, i); results.Add(this.nodes[neighbour]); } return(results); }
public IFieldNodeRef GetClosestNode(Vector3 position, IFieldNodeRef startNode = null) { int index; if (startNode == null) { index = this.GetClosestNodeIndex(position); } else { index = this.GetNodeIndexOfClosestNeighbourOrSelf(position, ((SimpleGraphFieldNodeRef)startNode).Node); } return(this.nodes[index]); }
private Vector3 SteerForPotential() { this.currentNode = this.potentialField.GetClosestNode(this.tx.position, this.currentNode); var samples = this.potentialField.SamplePotential(this.potentialSampler, this.currentNode, this.potentialLayerMask, null); var steer = Vector3.zero; if (samples.Count > 0) { this.nextNode = samples[0].Node; steer = (nextNode.Position - this.currentNode.Position).normalized; } else { this.nextNode = null; } samples.ReturnToPool(); return(steer); }
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(); }
public IList <NodeSample> SampleNodes(IPotentialFieldSystem potentialField, IFieldNodeRef startNode, int layerMask, PotentialFilter filter) { var neighbours = potentialField.GetNeighbours(startNode); neighbours.Insert(0, startNode); var sampleRequest = new SampleRequest(); sampleRequest.potentialLayerMask = layerMask; sampleRequest.filter = filter; sampleRequest.nodes = neighbours; var potentials = potentialField.SamplePotential(sampleRequest); var maxP = potentials[0]; var maxN = 0; for (int i = 1; i < potentials.Count; i++) { var p2 = potentials[i]; if (p2 > maxP) { maxN = i; maxP = p2; } } potentials.ReturnToPool(); var results = ListPool <NodeSample> .Take(); results.Add(new NodeSample(neighbours[maxN], maxP)); neighbours.ReturnToPool(); return(results); }
private void OnNextStrongestSearchFinished(IList <NodeSample> samples) { if (samples.Count == 0) { this.isMoving = false; } else { this.nextNode = samples[0].Node; this.mover.Driver.MoveTo(nextNode.Position); this.isMoving = true; if (this.targetNodePotential.enabled) { this.targetNodeSource.Node = nextNode; this.targetNodeSource.Enabled = true; } this.targetNode = nextNode; this.nextNode = null; } this.isWorking = false; }
public NodeSample(IFieldNodeRef node, float potential) { this.Node = node; this.Potential = potential; }
public void ScheduleSamplePotential(IPotentialSampleStrategy strategy, IFieldNodeRef startNode, int layerMask, PotentialFilter filter, NodeSamplerDelegate callback) { throw new System.NotImplementedException(); }
public IList <NodeSample> SamplePotential(IPotentialSampleStrategy strategy, IFieldNodeRef startNode, int layerMask, PotentialFilter filter) { return(strategy.SampleNodes(this, startNode, layerMask, filter)); }
void Recycled() { this.currentNode = null; this.nextNode = null; }