void Start() { agent = GetComponent<NavMeshAgent>(); PF = GetComponent<PathFind>(); PF.OVRDest = true; agent.SetDestination(Points[0].position); }
/// <summary> /// /// </summary> /// <param name="_from"></param> /// <param name="_to"></param> public void DrawPath(Vector3Int _from, Vector3Int _to) { ClearPath(); // get path // path will either be a list of Points (x, y), or an empty list if no path is found. m_Paths = PathFind.FindPath( m_Grid, _from, _to, ePathFindDistanceType.Manhattan); Dictionary <Vector3Int, float> costs = new Dictionary <Vector3Int, float>(); foreach (Vector3Int point in m_Paths) { TileBase tile = GetTileAt(point); if (tile.m_Unit != null) { costs.Add(point, 0f); continue; } tile.m_Property.m_IsPath = true; tile.SetColor(eTileType.Movable); costs.Add(point, 1f); } m_Grid.UpdateGrid(costs); }
public void PathFindTest30by30() { int row = 30; int col = 30; GameObject obj = new GameObject(); createBoardManager(obj, row, col); Graph gra = addGraphObject(obj); gra.CreateGraph(); Assert.NotNull(gra.graph); Node[,] graph = gra.graph; PathFind pf = new PathFind(); pf.CreatePaths(gra, graph[0, 0]); int cost; for (int x = 0; x < row; x++) { for (int y = 0; y < col; y++) { cost = x + y; // Debug.Log("x " + x + " y " + y + " Cost:" + pf.NodeCost(graph[x, y]) + " other cost: " + cost); Assert.IsTrue(pf.NodeCost(graph[x, y]) == cost); } } Debug.Log("Testing finished"); }
//prevents trucks from using train tracks. That issue happens because this mod adds Ferry to vehicleTypes //only trucks/post vans request CargoVehicle lane type so we can easily identify them private static bool TreatSpecially(PathFind pathFind, ref NetNode node) { var vehicleTypes = (VehicleInfo.VehicleType)vehicleTypesField.GetValue(pathFind); var laneTypes = (NetInfo.LaneType)laneTypesField.GetValue(pathFind); return(((laneTypes & NetInfo.LaneType.CargoVehicle) == NetInfo.LaneType.None || BelongsToFerryNetwork(ref node)) && DoVanillaCheck(vehicleTypes));
void Awake() { kf = GetComponent <KeyboardFunctions>(); grid = GetComponent <Grid>(); bhandler = GetComponent <BuildHandler> (); bank = GetComponent <Bank>(); pathfind = GetComponent <PathFind>(); pn = GetComponent <PlayerNetworking> (); wallGhostLoaded = (GameObject)(Resources.Load("Walls/WallGhost")); wallIcon = Resources.Load <Sprite> ("Sprites/WallIcon"); orbIcon = Resources.Load <Sprite> ("Sprites/OrbIcon"); cannonIcon = Resources.Load <Sprite> ("Sprites/CannonIcon"); laserIcon = Resources.Load <Sprite> ("Sprites/LaserIcon"); iceIcon = Resources.Load <Sprite> ("Sprites/IceIcon"); lightIcon = Resources.Load <Sprite> ("Sprites/LightIcon"); magicIcon = Resources.Load <Sprite> ("Sprites/MagicIcon"); rangeIndicator = (GameObject)(Resources.Load("UI/RangeIndicator")); highlightCastleMaterial = (Material)(Resources.Load("Materials/Outlined_Object")); BuildFX = (AudioClip)(Resources.Load("Sounds/BuildingPlacement", typeof(AudioClip))); needMoneySound = (AudioClip)(Resources.Load("Sounds/needMoney", typeof(AudioClip))); cannotBuildSound = (AudioClip)(Resources.Load("Sounds/CannotBuild", typeof(AudioClip))); selectSound = Resources.Load <AudioClip> ("Sounds/CarDoorClose"); sourceSFX = Camera.main.GetComponent <AudioSource>(); }
void Start() { Destroyed = false; EntityIndex = LastEntIndex; LastEntIndex++; PathFindObj = new PathFind(); }
public void PathFindTestInfinity() { int row = 15; int col = 15; GameObject obj = new GameObject(); createBoardManager(obj, row, col); Graph gra = addGraphObject(obj); gra.CreateGraph(); Assert.NotNull(gra.graph); Node[,] graph = gra.graph; PathFind pf = new PathFind(); pf.CreatePaths(gra, graph[0, 0]); for (int x = 0; x < row; x++) { for (int y = 0; y < col; y++) { // Debug.Log("x " + x + " y " + y + " Cost:" + pf.NodeCost(graph[x, y])); Assert.IsFalse(pf.NodeCost(graph[x, y]) == Mathf.Infinity); } } Debug.Log("Testing finished"); }
public void FiveSquareDebug() { int row = 5; int col = 5; GameObject obj = new GameObject(); createBoardManager(obj, row, col); Graph gra = addGraphObject(obj); gra.CreateGraph(); Assert.NotNull(gra.graph); Node[,] graph = gra.graph; PathFind pf = new PathFind(); pf.CreatePaths(gra, graph[4, 0]); Debug.Log("Length (4,0)" + pf.NodeCost(graph[4, 0])); Debug.Log("Length (3,0)" + pf.NodeCost(graph[3, 0])); Debug.Log("Length (2,0)" + pf.NodeCost(graph[2, 0])); Debug.Log("Length (1,0)" + pf.NodeCost(graph[1, 0])); Debug.Log("Length (0,0)" + pf.NodeCost(graph[0, 0])); Debug.Log("Length (2,1)" + pf.NodeCost(graph[2, 1])); Debug.Log("Length (1,1)" + pf.NodeCost(graph[1, 1])); Assert.IsTrue(pf.NodeCost(graph[0, 0]) == 4.0f); }
public GoldRadar(GameLoop gameLoop, PathFind pathFind, PathMap pathMap) { _gameLoop = gameLoop; _pathFind = pathFind; _pathMap = pathMap; _gameLoop.OnTick += Tick; }
public DangerRadar(GameLoop gameLoop, PathFind pathFind, int distanceRadar) { _pathFind = pathFind; _gameLoop = gameLoop; _distanceRadar = distanceRadar; _gameLoop.OnTick += Tick; }
public EnviromentsRadar(GameLoop gameLoop, PathFind pathFind, int distanceRadar) { _pathFind = pathFind; _gameLoop = gameLoop; _distanceRadar = distanceRadar; _gameLoop.OnTick += Tick; }
public void Gen() { Grid = new BitGrid(); Grid.Init(Width, Height, Scale); Grid.MeteoriteFill(Seed, MeteoriteRadius, MeteoriteCount); Finder = new PathFind(Grid); TestPath(); }
public static ZedTarget FindClosestTarget(Creature zed) { int distance; List <ZedTarget> targetList = new List <ZedTarget>(); foreach (var human in EntityLists.HumanList) { distance = PathFind.PythagThatMofo(human.CurrentPoint, zed.CurrentPoint); if (distance <= zed.AlertRange) { targetList.Add(new ZedTarget { Distance = distance, Destination = human.CurrentPoint }); } } foreach (var building in EntityLists.BuildingList) { distance = PathFind.PythagThatMofo(building.Position, zed.CurrentPoint); { //If no humans, aim for closest building if (targetList.Count == 0) { targetList.Add(new ZedTarget { Distance = distance, Destination = new Vector2(building.Position.X + (1.0f * building.Texture.Width / 2), building.Position.Y + (1.0f * building.Texture.Height / 2)) }); } /* * if (distance <= zed.AlertRange) * { * targetList.Add(new ZedTarget { Distance = distance, Destination = building.Position }); * } */ } } if (targetList.Count > 0) { var currentBest = targetList[0]; for (var i = 0; i < targetList.Count; i++) { if (targetList[i].Distance < currentBest.Distance) { currentBest = targetList[i]; } } return(currentBest); } return(null); }
public EasyPathFind(GameLoop gameLoop, PathFind pathFind, int distance) { _pathFind = pathFind; _gameLoop = gameLoop; _distance = distance; _random = new Random(); _gameLoop.OnTick += Tick; }
public void Update() { /*if (Input.GetKeyDown (KeyCode.Space)) { * anime.SetBool ("Attack", !anime.GetBool("Attack")); * }*/ Profiler.BeginSample("JobSeeking"); if (AntJob == null && lookForJob) { if (World.w.jobsQueued.Count > 0) { int index = 0; float priority = -1; for (int i = 0; i < World.w.jobsQueued.Count; i++) { Job j = World.w.jobsQueued[i]; if (j.priority - Vector2.Distance(position, j.location + Vector2.up / 10) / 10 > priority && !j.unreachable) { priority = j.priority - Vector2.Distance(position, j.location + Vector2.up / 10) / 10; index = i; } } if (!World.w.jobsQueued[index].unreachable) { AntJob = World.w.jobsQueued[index]; World.w.jobsQueued.RemoveAt(index); World.w.jobsInProgress.Add(AntJob); AntJob.onDuty = this; path = PathFind.getPathToNeighbors(World.w.GetBlockNegCoor(position).navNode, AntJob.location); if (path == null) { AntJob.unreachable = true; AntJob.onDuty = null; World.w.jobsInProgress.Remove(AntJob); World.w.jobsQueued.Add(AntJob); AntJob = null; } else { startWalking();//calling the coroutine in startwalking, necessary so i can stop it //StartCoroutine(walkPath()); } } } } else { if (moveRoutine == null) { Debug.LogError("moveRoutine is null"); startWalking(); } } Profiler.EndSample(); }
private void FindingPath() { switch (E_PF) { case E_PathFind.DFS: pf = new DFS(Map, start, end); break; case E_PathFind.DFS_Stack: pf = new DFS_Stack(Map, start, end); break; case E_PathFind.BFS: pf = new BFS_Queue(Map, start, end); break; case E_PathFind.AStar_Stack: pf = new AStar_Stack(Map, start, end); break; case E_PathFind.AStar: pf = new AStar(Map, start, end); break; case E_PathFind.BStar: break; case E_PathFind.Dijkstra: break; default: break; } if (E_FT == E_FindingType.Gradually) { pf.mono = this; pf.FindDeltT = FindDeltT; pf.IE_Finding(); } else if (E_FT == E_FindingType.Instant) { if (pf.Finding()) { Debug.Log("<color=red>Find path success.</color>"); pf.ShowPath(ShowPath); } else { Debug.Log("<color=red>Find path faile.</color>"); } } }
float speed = 0.5f; // second/unit(cellSize) void Start() { // Init map path = map.PATH; //string map_data = JsonConvert.SerializeObject(map); //Debug.Log(map_data); find = new PathFind(path); startpoint = map.start.position; character.position = startpoint; }
//deposits item into current room //methods //deposits item into current room public void depositItem() { if (toCarry.GetType() == typeof(Foods)) { StorageElement toStore = new StorageElement((Foods)toCarry, position); if (World.w.GetBlock(position).navNode.room.GetType() == typeof(FoodStorage)) { path = PathFind.getPathToNeighbors(World.w.GetBlock(position).navNode, AntJob.location); } } }
public void Awake() { instance = this; // 生成地图。 m_map = new Map(); m_map.Init_RumTimeMode(data); Vector3 scale = new Vector3(m_map.TileXnum * 0.1f, 1, m_map.TileYnum * 0.1f); transform.localScale = scale; }
void Start() { pf = GetComponent <PathFind>(); st = GetComponent <Stat>(); attackSpeed = 2; InvokeRepeating("HowFarThePlayer", 0f, 1f); plStat = GameObject.FindGameObjectWithTag("Player").GetComponent <Stat>(); Player = GameObject.FindGameObjectWithTag("Player").GetComponent <Transform>(); anim = GetComponent <Animator>(); setStat(); }
public void moveOffScreen() { stopWalking(); path = new List <NavNode>(); //Debug.Log(position); //Debug.Log(World.w.GetBlockNegCoor(new Vector2(20.5f, 0))); path = PathFind.getPath(World.w.GetBlockNegCoor(position).navNode, World.w.GetBlockNegCoor(new Vector2(20, 0)).navNode); finishedFirst = true; startWalking(); StartCoroutine(moveOffScreenCoroutine()); }
public void FiveSquareGraphPathFind() { int row = 5; int col = 5; GameObject obj = new GameObject(); createBoardManager(obj, row, col); Graph gra = addGraphObject(obj); gra.CreateGraph(); Assert.NotNull(gra.graph); PathFind pf = new PathFind(); Node[,] graph = gra.graph; Node startingNode = graph[row - 1, col - 1]; pf.CreatePaths(gra, startingNode); Node targetNode = graph[0, 3]; Assert.IsTrue(pf.NodeCost(targetNode) == 5.0f); Debug.Log("Passed testing path 1"); Node secondNode = graph[0, 0]; pf.CreatePaths(gra, targetNode); Assert.IsTrue(pf.NodeCost(secondNode) == 3.0f); Debug.Log("Passed testing Path 2"); pf.CreatePaths(gra, graph[0, 0]); Assert.IsTrue(pf.NodeCost(graph[0, 4]) == 4.0f); Debug.Log("Passed testing path 3"); pf.CreatePaths(gra, graph[0, 4]); Assert.IsTrue(pf.NodeCost(graph[4, 4]) == 4.0f); Debug.Log("Passed testing path 4"); pf.CreatePaths(gra, graph[4, 4]); Assert.IsTrue(pf.NodeCost(graph[4, 0]) == 4.0f); Debug.Log("Passed Testing path 5"); pf.CreatePaths(gra, graph[4, 0]); Debug.Log("Length " + pf.NodeCost(graph[4, 0])); Debug.Log("Length " + pf.NodeCost(graph[3, 0])); Debug.Log("Length " + pf.NodeCost(graph[2, 0])); Debug.Log("Length " + pf.NodeCost(graph[1, 0])); Debug.Log("Length " + pf.NodeCost(graph[0, 0])); Assert.IsTrue(pf.NodeCost(graph[0, 0]) == 4.0f); Debug.Log("Passed Testing path 6"); }
void Start() { st = GetComponent <Stat>(); plyStat = GameObject.Find("Player").GetComponent <Stat>(); canMove = true; SetStat(); oneTime2 = false; pf = GetComponent <PathFind>(); plyr = GameObject.Find("Player").GetComponent <Transform>(); anim = GetComponent <Animator>(); pf.enabled = true; InvokeRepeating("HowFarThePlayer", 0f, 1f); }
private void CheckPath() { var start = _game.AllTiles.SingleOrDefault(o => o.X == _currentCreature.Piece.X && o.Y == _currentCreature.Piece.Y); _movementRange = PathFind.MovementRange(start, _currentCreature.Attributes.Speed); var movementTiles = _movementRange.SelectMany(t => t); var avaibleTiles = _tiles.Where(t => t.TileHex.CanPass && movementTiles.Any(tile => tile == t.TileHex && tile.CanPass)); foreach (var tile in avaibleTiles) { tile.TileHex.CanSelect = true; tile.ChangeColor(Color.red); } _tiles.SingleOrDefault(x => x.TileHex == start).ChangeColor(Color.cyan); }
public static void DrawFindTestGrid(PathFind finder) { float scale = finder.Grid.Scale; Vector3 size = new Vector3(scale, 0.2f, scale); for (int i = 0; i < finder.Grid.Width; ++i) { for (int j = 0; j < finder.Grid.Height; ++j) { if (finder.Grid.Get(i, j) && finder.HasTest(finder.Grid.ToIndex(i, j))) { Gizmos.DrawCube(new Vector3(scale * (i + 0.5f), 0.2f, scale * (j + 0.5f)), size); } } } }
public static bool Prefix(PathFind __instance, ref bool __result, uint unit, bool skipQueue) { Log.Warning($"PathFind.CalculatePath() called outside of TM:PE! Unit: {unit}"); if (__instance is CustomPathFind pf) { __result = pf.CalculatePath(unit, skipQueue); } else { __result = false; } return(false); }
public void TestGraphCreation() { int row = 5; int col = 5; GameObject obj = new GameObject(); createBoardManager(obj, row, col); Graph gra = addGraphObject(obj); gra.CreateGraph(); Assert.NotNull(gra.graph); PathFind pf = new PathFind(); pf.CreatePaths(gra, gra.graph[0, 0]); Assert.IsTrue(pf.NodeCost(gra.graph[3, 0]) == 3.0f); Debug.Log("Finished Testing"); }
public BotBrain(GameLoop gameLoop) { _gameLoop = gameLoop; _pathMap = new PathMap(_gameLoop, BotConfiguration.DeepPathFind); _pathFind = new PathFind(_gameLoop, _pathMap, BotConfiguration.MaxLenghtPath); _goldRadar = new GoldRadar(_gameLoop, _pathFind, _pathMap); _enviromentsRadar = new EnviromentsRadar(_gameLoop, _pathFind, BotConfiguration.DistanceEnviroments); _dangerRadar = new DangerRadar(_gameLoop, _pathFind, BotConfiguration.DistanceDangerous); _easyPathFind = new EasyPathFind(_gameLoop, _pathFind, BotConfiguration.DistanceEasyPathFind); _botActions = new QueueBotActions(); _actionProfiders.Add(_goldRadar); _actionProfiders.Add(_enviromentsRadar); _actionProfiders.Add(_dangerRadar); _actionProfiders.Add(_easyPathFind); _actionProfiders.Sort((item1, item2) => item1.Priority.CompareTo(item2.Priority)); _actionProfiders.Reverse(); }
public void PathFindTestingFifteenByFifteen() { int row = 15; int col = 15; GameObject obj = new GameObject(); createBoardManager(obj, row, col); Graph gra = addGraphObject(obj); gra.CreateGraph(); Assert.NotNull(gra.graph); Node[,] graph = gra.graph; PathFind pf = new PathFind(); pf.CreatePaths(gra, graph[14, 0]); Assert.IsTrue(pf.NodeCost(graph[0, 0]) == 14.0f); pf.CreatePaths(gra, graph[0, 0]); Assert.IsTrue(pf.NodeCost(graph[14, 1]) == 15.0f); pf.CreatePaths(gra, graph[0, 0]); Assert.IsTrue(pf.NodeCost(graph[14, 14]) == 28.0f); Debug.Log("Testing is finished"); }
public SteerFabulaClip(JSONNode json, TimelineAsset p_timeline, PlayableDirector p_director) : base(json, p_timeline, p_director) { ending_location = GameObject.Find(json["end_pos_name"].Value); // Quantize to find start and finish nodes startNode = QuantizeLocalize.Quantize(starting_location.transform.position, TrackAttributes.TG); goalNode = QuantizeLocalize.Quantize(ending_location.transform.position, TrackAttributes.TG); // Calculate path Path = PathFind.Dijkstra(TrackAttributes.TG, startNode, goalNode); // create Lerp for each edge in path var eachSeg = duration / Path.Count; int n = 0; var lastNode = startNode; foreach (Node p in Path) { ClipInfo CI = new ClipInfo(p_director, start + n * eachSeg, eachSeg, Name); CI.SimpleLerpClip(agent, lastNode.transform, p.transform); lastNode = p; n++; } // run animation across whole thing if not null if (json["animation_name"] != null) { control_track_clip = ctrack.CreateDefaultClip(); control_track_clip.start = start + 0.06f; control_track_clip.duration = duration - 0.06f; control_track_clip.displayName = Name; controlAnim = control_track_clip.asset as ControlPlayableAsset; AnimateBind(controlAnim, animTimelineObject); } }
public void UpdateOldPathManagerValues(PathManager stockPathManager) { stockPathManager.m_drawCallData = m_drawCallData; stockPathManager.m_pathUnitCount = m_pathUnitCount; stockPathManager.m_renderPathGizmo = m_renderPathGizmo; int n = _replacementPathFinds.Length; Log._Debug("Creating " + n + " stock PathFind objects."); PathFind[] stockPathFinds = new PathFind[n]; FieldInfo f_pathfinds = typeof(PathManager).GetField( "m_pathfinds", BindingFlags.NonPublic | BindingFlags.Instance) ?? throw new Exception("f_pathFinds is null"); // both stcok and custom PathMangers use the same lock object lock (m_bufferLock) { for (int i = 0; i < n; i++) { Log._Debug($"PF {i}: {_replacementPathFinds[i].m_queuedPathFindCount} queued path-finds"); // would cause deadlock since we have a lock on m_bufferLock // customPathFinds[i].WaitForAllPaths(); Destroy(_replacementPathFinds[i]); } // revert to vanilla number of threads n = Mathf.Clamp(SystemInfo.processorCount / 2, 1, 4); for (int i = 0; i < n; i++) { stockPathFinds[i] = gameObject.AddComponent <PathFind>(); } f_pathfinds?.SetValue(stockPathManager, stockPathFinds); } }