public void StreamTypeMismatch() { string randomPath = RandomPath.GetRandomPath(); using (var writeStream = new FileStream(randomPath, FileMode.Create, FileAccess.Write)) { Assert.Throws <CompressionException>(delegate { // ReSharper disable once AccessToDisposedClosure using (new BlockGZipStream(writeStream, CompressionMode.Decompress)) { } }); } using (var readStream = FileUtilities.GetReadStream(randomPath)) { Assert.Throws <CompressionException>(delegate { // ReSharper disable once AccessToDisposedClosure using (new BlockGZipStream(readStream, CompressionMode.Compress)) { } }); } }
public void CleanOutput_AsExpected() { var tempDir = RandomPath.GetRandomPath(); Directory.CreateDirectory(tempDir); File.Create(Path.Combine(tempDir, "json1" + NirvanaHelper.JsonSuffix)).Close(); File.Create(Path.Combine(tempDir, "json2" + NirvanaHelper.JsonSuffix)).Close(); File.Create(Path.Combine(tempDir, "jsonIndex1" + NirvanaHelper.JsonIndexSuffix)).Close(); File.Create(Path.Combine(tempDir, "jsonIndex2" + NirvanaHelper.JsonIndexSuffix)).Close(); var otherFiles = new[] { "other1.31415926", "other2" }.Select(x => Path.Combine(tempDir, x)).ToArray(); Array.Sort(otherFiles); File.Create(otherFiles[0]).Close(); File.Create(otherFiles[1]).Close(); NirvanaHelper.CleanOutput(tempDir); var remainFiles = Directory.GetFiles(tempDir).ToArray(); Array.Sort(remainFiles); Assert.Equal(otherFiles.Length, remainFiles.Length); for (var i = 0; i < otherFiles.Length; i++) { Assert.Equal(otherFiles[i], remainFiles[i]); } }
/** Starts a path specified by PathTypesDemo.activeDemo */ public void DemoPath() { Path p = null; if (activeDemo == 0) { p = ABPath.Construct(start.position, end.position, OnPathComplete); } else if (activeDemo == 1) { MultiTargetPath mp = MultiTargetPath.Construct(multipoints.ToArray(), end.position, null, OnPathComplete); p = mp; } else if (activeDemo == 2) { RandomPath rp = RandomPath.Construct(start.position, searchLength, OnPathComplete); rp.spread = spread; rp.aimStrength = aimStrength; rp.aim = end.position; rp.replaceChance = replaceChance; p = rp; } else if (activeDemo == 3) { FleePath fp = FleePath.Construct(start.position, end.position, searchLength, OnPathComplete); fp.aimStrength = aimStrength; fp.replaceChance = replaceChance; fp.spread = spread; p = fp; } else if (activeDemo == 4) { ConstantPath constPath = ConstantPath.Construct(end.position, searchLength, OnPathComplete); p = constPath; } else if (activeDemo == 5) { FloodPath fp = FloodPath.Construct(end.position, null); lastFlood = fp; p = fp; } else if (activeDemo == 6 && lastFlood != null) { FloodPathTracer fp = FloodPathTracer.Construct(end.position, lastFlood, OnPathComplete); p = fp; } if (p != null) { AstarPath.StartPath(p); lastPath = p; } }
// Start is called before the first frame update void Awake() { Instance = this; canBeUsedPath = new List <int>(); // if some ghost picked 1 path, delete it from the list for (int i = 0; i < transform.childCount; i++) { canBeUsedPath.Add(i); } }
void Awake() { Instance = this; canBeUsedPath = new List <int>(); // if some ghost picked 1 path, delete it from the list for (int i = 0; i < transform.childCount; i++) { canBeUsedPath.Add(i); // when initiation setup, put all path into the list } }
private IEnumerator GenSuperDot() { yield return(new WaitForSecond(Super_Dot_Time)); Pacdot[] allDots = GameObject.FindObjectsOfType <Pacdot>(); Pacdot superDot = allDots[RandomPath.Range(0, allDots.Length)]; superDot.MakeDotSuper(); }
public static AGAstarPath CreateRandom(Vector3 start, int length, System.Action <RandomPath> config) { var path = RandomPath.Construct(start, length, null); if (config != null) { config(path); } return(new AGAstarPath(path)); }
/// <summary>Starts a path specified by PathTypesDemo.activeDemo</summary> void DemoPath() { Path p = null; switch (activeDemo) { case DemoMode.ABPath: p = ABPath.Construct(start.position, end.position, OnPathComplete); break; case DemoMode.MultiTargetPath: StartCoroutine(DemoMultiTargetPath()); break; case DemoMode.ConstantPath: StartCoroutine(DemoConstantPath()); break; case DemoMode.RandomPath: RandomPath rp = RandomPath.Construct(start.position, searchLength, OnPathComplete); rp.spread = spread; rp.aimStrength = aimStrength; rp.aim = end.position; p = rp; break; case DemoMode.FleePath: FleePath fp = FleePath.Construct(start.position, end.position, searchLength, OnPathComplete); fp.aimStrength = aimStrength; fp.spread = spread; p = fp; break; case DemoMode.FloodPath: p = lastFloodPath = FloodPath.Construct(end.position, null); break; case DemoMode.FloodPathTracer: if (lastFloodPath != null) { FloodPathTracer fpt = FloodPathTracer.Construct(end.position, lastFloodPath, OnPathComplete); p = fpt; } break; } if (p != null) { AstarPath.StartPath(p); lastPath = p; } }
// Token: 0x060029EC RID: 10732 RVA: 0x001C21BC File Offset: 0x001C03BC private void DemoPath() { Path path = null; switch (this.activeDemo) { case PathTypesDemo.DemoMode.ABPath: path = ABPath.Construct(this.start.position, this.end.position, new OnPathDelegate(this.OnPathComplete)); break; case PathTypesDemo.DemoMode.MultiTargetPath: base.StartCoroutine(this.DemoMultiTargetPath()); break; case PathTypesDemo.DemoMode.RandomPath: { RandomPath randomPath = RandomPath.Construct(this.start.position, this.searchLength, new OnPathDelegate(this.OnPathComplete)); randomPath.spread = this.spread; randomPath.aimStrength = this.aimStrength; randomPath.aim = this.end.position; path = randomPath; break; } case PathTypesDemo.DemoMode.FleePath: { FleePath fleePath = FleePath.Construct(this.start.position, this.end.position, this.searchLength, new OnPathDelegate(this.OnPathComplete)); fleePath.aimStrength = this.aimStrength; fleePath.spread = this.spread; path = fleePath; break; } case PathTypesDemo.DemoMode.ConstantPath: base.StartCoroutine(this.DemoConstantPath()); break; case PathTypesDemo.DemoMode.FloodPath: path = (this.lastFloodPath = FloodPath.Construct(this.end.position, null)); break; case PathTypesDemo.DemoMode.FloodPathTracer: if (this.lastFloodPath != null) { path = FloodPathTracer.Construct(this.end.position, this.lastFloodPath, new OnPathDelegate(this.OnPathComplete)); } break; } if (path != null) { AstarPath.StartPath(path, false); this.lastPath = path; } }
public void CalculatePath() { if (moveMode != MoveMode.follow && moveMode != MoveMode.followTo && moveMode != MoveMode.fleeContinuously) { path = null; } // do this to avoid instant finishing if the action had been called before and if the actor didn't move Vector3 targetPos; if (target.Value != null) { targetPos = target.Value.transform.position + targetPosition.Value; } else { targetPos = targetPosition.Value; } if (path != null && path.vectorPath.Count > 0 && (moveMode == MoveMode.follow || moveMode == MoveMode.followTo)) { p = ABPath.Construct(nextPos, targetPos, OnPathComplete); } // create path from next waypoint (to avoid jitter due to sudden direction change on path update) to closest/first node else if (moveMode != MoveMode.fleeContinuously && moveMode != MoveMode.flee && moveMode != MoveMode.randomPath) { p = ABPath.Construct(go.transform.position, targetPos, OnPathComplete); } // create path from current position to closest/first node else if (moveMode == MoveMode.fleeContinuously || moveMode == MoveMode.flee) { if (AstarPath.HasPro) { p = FleePath.Construct(go.transform.position, targetPos, (int)(length.Value * 1000f), OnPathComplete); } // create path from current position to closest/first node else { p = ABPath.Construct(go.transform.position, go.transform.position + (go.transform.position - targetPos).normalized * length.Value, OnPathComplete); } } else if (moveMode == MoveMode.randomPath) { if (AstarPath.HasPro) { p = RandomPath.Construct(go.transform.position, (int)(length.Value * 1000f), OnPathComplete); } // create path from current position to closest/first node else // random direction! This is just a cheap immitation of the real randompath! { p = ABPath.Construct(go.transform.position, go.transform.position + new Vector3(UnityEngine.Random.Range(-1f, 1f), 0f, UnityEngine.Random.Range(-1f, 1f)).normalized *length.Value, OnPathComplete); } } AstarPath.StartPath(p); //make the actual vector3 path which we'll use lateron. time = Time.time; return; }
public void CanReadWriteSeek() { string randomPath = RandomPath.GetRandomPath(); using (var writeStream = new FileStream(randomPath, FileMode.Create, FileAccess.Write)) using (var blockStream = new BlockStream(Zstd, writeStream, CompressionMode.Compress)) { Assert.False(blockStream.CanRead); Assert.True(blockStream.CanWrite); Assert.True(blockStream.CanSeek); } }
public RandomPath GetRandomPath(int targetPathLength) { RandomPath randomPath = new RandomPath(); List <PathEdge> pathEdges = new List <PathEdge>(); List <PathNeuronNode> allNodes = new List <PathNeuronNode>(nodeToEdge.Keys); PathNeuronNode startNode = allNodes[Random.Range(0, allNodes.Count)]; HashSet <PathNeuronNode> closedNodeSet = new HashSet <PathNeuronNode> { startNode }; Dictionary <PathNeuronNode, HashSet <PathEdge> > closedEdgeSet = new Dictionary <PathNeuronNode, HashSet <PathEdge> >(); PathNeuronNode currentNode = startNode; while (pathEdges.Count < targetPathLength) { if (!closedEdgeSet.Keys.Contains(currentNode)) { closedEdgeSet.Add(currentNode, new HashSet <PathEdge>()); } HashSet <PathEdge> availableEdges = new HashSet <PathEdge>( nodeToEdge[currentNode].Where(x => !closedEdgeSet[currentNode].Contains(x) && !closedNodeSet.Contains(GetOtherNode(currentNode, x)) && !pathEdges.Contains(x)).ToList()); // Back-track if we've reached a dead end if (availableEdges.Count == 0) { if (currentNode == startNode) { Debug.LogError("Random Path could not be found for start node: " + startNode.gameObject.name + " with target path length: " + targetPathLength.ToString()); } PathEdge previousPath = pathEdges[pathEdges.Count - 1]; PathNeuronNode previousNode = GetOtherNode(currentNode, previousPath); closedEdgeSet[previousNode].Add(previousPath); pathEdges.Remove(previousPath); currentNode = previousNode; continue; } PathEdge nextEdge = availableEdges.ToList <PathEdge>()[Random.Range(0, availableEdges.Count)]; pathEdges.Add(nextEdge); closedNodeSet.Add(currentNode); currentNode = GetOtherNode(currentNode, nextEdge); } randomPath.startNode = startNode; randomPath.finishNode = currentNode; randomPath.pathEdges = pathEdges; return(randomPath); }
private Node[] DistributePath(RandomPath RandomizablePathData) { Node[] distributedNodeArray = (Node[])RandomizablePathData.nodes.Clone(); foreach (RandomNode rn in RandomizablePathData.randomNode) { float random = Util.RandomRange(rn.randomRange.min, rn.randomRange.max); distributedNodeArray[rn.randomNodeIndex].position[(int)rn.randomAxis] += random; distributedNodeArray[rn.randomNodeIndex].handleOut[(int)rn.randomAxis] += random; } return(distributedNodeArray); }
private StemLocalData DistributeMainStemLocalData(RandomPath sproutRandomPath, RandomPath stemRandomPath, ColorData colorData, bool isBranch = false) { StemLocalData data = new StemLocalData(); data.isBranch = isBranch; data.Nodes = DistributePath(stemRandomPath); data.SproutNodes = Util.MatchNodeCount(DistributePath(sproutRandomPath), data.Nodes); data.SproutThickness = new Vector2(sproutRandomPath.pathMeshProperties.Thickness.min, sproutRandomPath.pathMeshProperties.Thickness.max); data.StemThickness = new Vector2(stemRandomPath.pathMeshProperties.Thickness.min, stemRandomPath.pathMeshProperties.Thickness.max); data.Color = !colorData.isRandom ? colorData.Color : Util.GetColorFromRange(colorData.ColorRange1, colorData.ColorRange2); return(data); }
public void SetWander() { if (Wandering || (_stuckNode != null && _stuckNode == CurrentGraphNode)) { return; } Wandering = true; _waitingForPathCalculation = true; var rp = RandomPath.Construct(Tr.position, 7000); rp.traversalProvider = _traversal; _seeker.StartPath(rp); }
/// <summary> /// Generates a random path of the required length that does not intersect with itself. /// Accepts an optional set of Nodes which should be ignored, or a dictionary of Edges to ignore /// from a given node. Generates an error if required length cannot be met. /// </summary> /// <param name="requiredPathLength"></param> /// <param name="closedNodeSet"></param> /// <param name="closedEdgeSet"></param> /// <returns></returns> public RandomPath GetRandomPath(int requiredPathLength, HashSet <Node> closedNodeSet = null, Dictionary <Node, HashSet <Edge> > closedEdgeSet = null) { List <Edge> pathEdges = new List <Edge>(); Node startNode = edgesFromNode.GetNodes().ToList()[Random.Range(0, nodes.Count)]; closedNodeSet = closedNodeSet == null ? new HashSet <Node> { startNode } : closedNodeSet; closedEdgeSet = closedEdgeSet == null ? new Dictionary <Node, HashSet <Edge> >() : closedEdgeSet; Node currentNode = startNode; while (pathEdges.Count < requiredPathLength) { if (!closedEdgeSet.Keys.Contains(currentNode)) { closedEdgeSet.Add(currentNode, new HashSet <Edge>()); } HashSet <Edge> availableEdges = new HashSet <Edge>( edgesFromNode.GetEdges(currentNode).Where(x => !closedEdgeSet[currentNode].Contains(x) && !closedNodeSet.Contains(x.GetOtherNode(currentNode)) && !pathEdges.Contains(x)).ToList()); // Back-track if we've reached a dead end if (availableEdges.Count == 0) { if (currentNode == startNode) { Debug.LogError("Random Path could not be found for start node: " + startNode + " with target path length: " + requiredPathLength); } Edge previousPath = pathEdges[pathEdges.Count - 1]; Node previousNode = previousPath.GetOtherNode(currentNode); closedEdgeSet[previousNode].Add(previousPath); pathEdges.Remove(previousPath); currentNode = previousNode; continue; } Edge nextEdge = availableEdges.ToList <Edge>()[Random.Range(0, availableEdges.Count)]; pathEdges.Add(nextEdge); closedNodeSet.Add(currentNode); currentNode = nextEdge.GetOtherNode(currentNode); } RandomPath randomPath = new RandomPath(); randomPath.startNode = startNode; randomPath.finishNode = currentNode; randomPath.pathEdges = pathEdges; return(randomPath); }
public void CheckInputFilenameExists_MissingFiles_FileNotFoundExitCode() { string randomPath = RandomPath.GetRandomPath() + ".anavrin"; var ops = new OptionSet { { "id=", "id", v => { } } }; var exitCode = Execute(new ConsoleAppBuilder(new[] { "--if", randomPath }, ops) .Parse() .CheckInputFilenameExists(randomPath, "test", "--if")); Assert.Equal(ExitCodes.FileNotFound, exitCode); }
public void CheckInputFilenameExists_FileExists_SuccessExitCode() { string randomPath = RandomPath.GetRandomPath(); File.Create(randomPath); var ops = new OptionSet { { "if=", "if", v => { } } }; var exitCode = Execute(new ConsoleAppBuilder(new[] { "--if", randomPath }, ops) .Parse() .CheckInputFilenameExists(randomPath, "test", "--if")); Assert.Equal(ExitCodes.Success, exitCode); }
private void findNewRandomPoint() { // Call a RandomPath call like this, assumes that a Seeker is attached to the GameObject // The path will be returned when the path is over a specified length (or more accurately when the traversal cost is greater than a specified value). // A score of 1000 is approximately equal to the cost of moving one world unit. int theGScoreToStopAt = (int)seekingDistance * 1000; // Create a path object RandomPath path = RandomPath.Construct(transform.position, theGScoreToStopAt); // Determines the variation in path length that is allowed path.spread = 15000; // Start the path and return the result to MyCompleteFunction (which is a function you have to define, the name can of course be changed) seeker.StartPath(path, OnPathComplete); }
public void FileIO() { var observedDecompressedBuffer = new byte[_expectedDecompressedBuffer.Length]; string randomPath = RandomPath.GetRandomPath(); // compress the data long observedPosition; using (var writer = new BlockGZipStream(FileUtilities.GetCreateStream(randomPath), CompressionMode.Compress)) { writer.Write(_expectedDecompressedBuffer, 0, _expectedDecompressedBuffer.Length); observedPosition = writer.Position; var exception = Record.Exception(() => { var buffer = new byte[10]; // ReSharper disable once AccessToDisposedClosure writer.Read(buffer, 0, 1); }); Assert.NotNull(exception); Assert.IsType <CompressionException>(exception); } const long expectedPosition = 979042574; Assert.Equal(expectedPosition, observedPosition); // decompress the data using (var reader = new BlockGZipStream(FileUtilities.GetReadStream(randomPath), CompressionMode.Decompress)) { reader.Read(observedDecompressedBuffer, 0, _expectedDecompressedBuffer.Length); var exception = Record.Exception(() => { var buffer = new byte[10]; // ReSharper disable once AccessToDisposedClosure reader.Write(buffer, 0, 1); }); Assert.NotNull(exception); Assert.IsType <CompressionException>(exception); } Assert.Equal(_expectedDecompressedBuffer, observedDecompressedBuffer); }
public void GetAppropriateReadStream_Handle_GZipFile() { string randomPath = RandomPath.GetRandomPath(); using (var writer = new StreamWriter(new GZipStream(FileUtilities.GetCreateStream(randomPath), CompressionMode.Compress))) { writer.WriteLine(ExpectedString); } string observedString; using (var reader = GZipUtilities.GetAppropriateStreamReader(randomPath)) { observedString = reader.ReadLine(); } Assert.Equal(ExpectedString, observedString); }
public void GetAppropriateReadStream_Handle_BlockGZipFile() { string randomPath = RandomPath.GetRandomPath(); using (var writer = GZipUtilities.GetStreamWriter(randomPath)) { writer.WriteLine(ExpectedString); } string observedString; using (var reader = GZipUtilities.GetAppropriateStreamReader(randomPath)) { observedString = reader.ReadLine(); } Assert.Equal(ExpectedString, observedString); }
/** Starts a path specified by PathTypesDemo::activeDemo */ public void DemoPath() { Path p = null; if (activeDemo == 0) { p = new Path(start.position, end.position, OnPathComplete); } else if (activeDemo == 1) { MultiTargetPath mp = new MultiTargetPath(multipoints.ToArray(), end.position, null, OnPathComplete); p = mp; } else if (activeDemo == 2) { RandomPath rp = new RandomPath(start.position, searchLength, OnPathComplete); rp.spread = spread; rp.aimStrength = aimStrength; rp.aim = end.position; rp.replaceChance = replaceChance; p = rp; } else if (activeDemo == 3) { FleePath fp = new FleePath(start.position, end.position, searchLength, OnPathComplete); fp.fleeStrength = aimStrength; fp.replaceChance = replaceChance; fp.spread = spread; p = fp; } else if (activeDemo == 4) { ConstantPath constPath = new ConstantPath(start.position, searchLength, OnPathComplete); p = constPath; } if (p != null) { AstarPath.StartPath(p); } }
public void GetReadStream_GetCreateStream_Loopback() { string random = RandomPath.GetRandomPath(); const string expectedString = "charlie"; using (var writer = new StreamWriter(FileUtilities.GetCreateStream(random))) { writer.WriteLine(expectedString); } string observedString; using (var reader = FileUtilities.GetStreamReader(FileUtilities.GetReadStream(random))) { observedString = reader.ReadLine(); } Assert.Equal(expectedString, observedString); }
public void CreateRandomPath() { currentRandomPath = RandomPath.CreateInstance(typeof(RandomPath)) as RandomPath; currentRandomPath.CreatePath(transform, target, steps, startColor, environmentCheck, debugRayDuration); }
public static AGAstarPath CreateRandom(Vector3 start, int length) { return(new AGAstarPath(RandomPath.Construct(start, length, null))); }
public void StartRandomPathCreationCoroutine() { currentRandomPath = RandomPath.CreateInstance(typeof(RandomPath)) as RandomPath; StartCoroutine(currentRandomPath.CreatePathCoroutine(this, transform, target, steps, startColor, environmentCheck, debugRayDuration)); }
/** Starts a path specified by PathTypesDemo.activeDemo */ void DemoPath() { Path p = null; if (activeDemo == DemoMode.ABPath) { p = ABPath.Construct(start.position, end.position, OnPathComplete); if (agents != null && agents.Length > 0) { List <Vector3> pts = Pathfinding.Util.ListPool <Vector3> .Claim(agents.Length); Vector3 avg = Vector3.zero; for (int i = 0; i < agents.Length; i++) { pts.Add(agents[i].transform.position); avg += pts[i]; } avg /= pts.Count; for (int i = 0; i < agents.Length; i++) { pts[i] -= avg; } Pathfinding.PathUtilities.GetPointsAroundPoint(end.position, AstarPath.active.graphs[0] as IRaycastableGraph, pts, 0, 0.2f); for (int i = 0; i < agents.Length; i++) { if (agents[i] == null) { continue; } agents[i].target.position = pts[i]; agents[i].UpdatePath(); } } } else if (activeDemo == DemoMode.MultiTargetPath) { MultiTargetPath mp = MultiTargetPath.Construct(multipoints.ToArray(), end.position, null, OnPathComplete); p = mp; } else if (activeDemo == DemoMode.RandomPath) { RandomPath rp = RandomPath.Construct(start.position, searchLength, OnPathComplete); rp.spread = spread; rp.aimStrength = aimStrength; rp.aim = end.position; p = rp; } else if (activeDemo == DemoMode.FleePath) { FleePath fp = FleePath.Construct(start.position, end.position, searchLength, OnPathComplete); fp.aimStrength = aimStrength; fp.spread = spread; p = fp; } else if (activeDemo == DemoMode.ConstantPath) { StartCoroutine(CalculateConstantPath()); p = null; } else if (activeDemo == DemoMode.FloodPath) { FloodPath fp = FloodPath.Construct(end.position, null); lastFlood = fp; p = fp; } else if (activeDemo == DemoMode.FloodPathTracer && lastFlood != null) { FloodPathTracer fp = FloodPathTracer.Construct(end.position, lastFlood, OnPathComplete); p = fp; } if (p != null) { AstarPath.StartPath(p); lastPath = p; } }
public void DemoPath() { Path path = null; if (this.activeDemo == 0) { path = ABPath.Construct(this.start.position, this.end.position, new OnPathDelegate(this.OnPathComplete)); if (this.agents != null && this.agents.Length > 0) { List <Vector3> list = ListPool <Vector3> .Claim(this.agents.Length); Vector3 vector = Vector3.zero; for (int i = 0; i < this.agents.Length; i++) { list.Add(this.agents[i].transform.position); vector += list[i]; } vector /= (float)list.Count; for (int j = 0; j < this.agents.Length; j++) { List <Vector3> list2; int index; (list2 = list)[index = j] = list2[index] - vector; } PathUtilities.GetPointsAroundPoint(this.end.position, AstarPath.active.graphs[0] as IRaycastableGraph, list, 0f, 0.2f); for (int k = 0; k < this.agents.Length; k++) { if (!(this.agents[k] == null)) { this.agents[k].target.position = list[k]; this.agents[k].UpdatePath(); } } } } else if (this.activeDemo == 1) { MultiTargetPath multiTargetPath = MultiTargetPath.Construct(this.multipoints.ToArray(), this.end.position, null, new OnPathDelegate(this.OnPathComplete)); path = multiTargetPath; } else if (this.activeDemo == 2) { RandomPath randomPath = RandomPath.Construct(this.start.position, this.searchLength, new OnPathDelegate(this.OnPathComplete)); randomPath.spread = this.spread; randomPath.aimStrength = this.aimStrength; randomPath.aim = this.end.position; path = randomPath; } else if (this.activeDemo == 3) { FleePath fleePath = FleePath.Construct(this.start.position, this.end.position, this.searchLength, new OnPathDelegate(this.OnPathComplete)); fleePath.aimStrength = this.aimStrength; fleePath.spread = this.spread; path = fleePath; } else if (this.activeDemo == 4) { base.StartCoroutine(this.Constant()); path = null; } else if (this.activeDemo == 5) { FloodPath floodPath = FloodPath.Construct(this.end.position, null); this.lastFlood = floodPath; path = floodPath; } else if (this.activeDemo == 6 && this.lastFlood != null) { FloodPathTracer floodPathTracer = FloodPathTracer.Construct(this.end.position, this.lastFlood, new OnPathDelegate(this.OnPathComplete)); path = floodPathTracer; } if (path != null) { AstarPath.StartPath(path, false); this.lastPath = path; } }
IEnumerator UpdatePath() { while (true) { if (curState == State.Searching) { ai.isStopped = false; //this.GetComponent<RichAI>().enabled = false; if (target != null) { if (enemyMode == Mode.Assault) { if (hasDetectedPlayer == false) { if (LastPlayerSighting.position != previousSighting) { personalLastSighting = LastPlayerSighting.position; } Collider[] colliders = Physics.OverlapSphere(this.transform.position, detectionRadius); foreach (Collider collider in colliders) { RunDetection(collider); } previousSighting = LastPlayerSighting.position; if (Time.time > nextSearchTime && (ai.reachedEndOfPath || !ai.hasPath)) { trueTarget = null; RandomPath path = RandomPath.Construct(this.transform.position, 20); path.spread = 5; this.GetComponent <Seeker>().StartPath(path); } } else { trueTarget = target; } } else if (enemyMode == Mode.Avoid) { { if (Time.time > nextRunawayTime && Vector3.Distance(this.transform.position, target.transform.position) < 20f) { //Debug.Log("STAY AWAY FROM ME!"); Vector3 targetPosition = target.position; int stopGScore = 1000; FleePath path = FleePath.Construct(this.transform.position, targetPosition, stopGScore); path.spread = 4000; path.aimStrength = 1; Seeker seeker = this.GetComponent <Seeker>(); seeker.StartPath(path, GetEscapePath); nextRunawayTime = Time.time * 1.01f; } } } } } if (curState == State.Attacking) { ai.isStopped = true; //var targetRotation = Quaternion.LookRotation(target.position - this.transform.position, Vector3.up); //this.transform.rotation = Quaternion.Slerp(this.transform.rotation, targetRotation, Time.deltaTime * 2.0f); this.GetComponent <EnemyAI>().enabled = true; } yield return(new WaitForEndOfFrame()); } }