// Use this for initialization void Start() { selfCollider = transform.GetComponent<BoxCollider2D>(); colliderx = selfCollider.size.x / 2f; collidery = selfCollider.size.y / 2f; pathfindingMNG = GameObject.FindGameObjectWithTag("Manager").GetComponent<PathfindingManager>(); }
public void SetNewTarget(Vector3 new_target, bool modify = true) { if (modify) { int i = 0; do { Vector2 offsetXY = UnityEngine.Random.insideUnitCircle * offset; target = Map.Clamp(new Vector3(new_target.x + offsetXY[0], 1f, new_target.z + offsetXY[1])); i++; } while (!Map.NodeFromPosition(target).isWalkable() && i < 20); if (!Map.NodeFromPosition(target).isWalkable()) { Debug.LogError("GoTo target not walkable " + new_target); //error finished = true; return; } } processing = true; if (defensive) { PathfindingManager.RequestPath(agent, target, agent.faction, ProcessPath); } else { PathfindingManager.RequestPath(agent, target, Faction.C, ProcessPath); } finished = false; }
void OnEnable() { tf = GetComponent <Transform>(); main = GetComponent <Camera>(); pathfindingManager = FindObjectOfType <PathfindingManager>(); }
private void OnDestroy() { probeData.Dispose(); directionData.Dispose(); lightingManager.OnLightingProbesMoved -= HandleProbesMoved; Instance = null; }
void Start() { if (Instance != null) { Destroy(this); Debug.LogError("Two Pathfinding managers exist in the scene. Deleting one"); return; } Instance = this; lightingManager = GetComponent <LightingManager>(); probeData = new NativeArray <TilePathfindingData>(lightingManager.totalProbes, Allocator.Persistent); for (int i = 0; i < lightingManager.totalProbes; i++) { probeData[i] = new TilePathfindingData { distance = 99999, closestSeen = 99999, occupied = true }; } directionData = new NativeArray <float2>(lightingManager.totalProbes, Allocator.Persistent); lightingManager.OnLightingProbesMoved += HandleProbesMoved; }
void Awake() { m_cam = Camera.main; m_pfm = GameObject.FindGameObjectWithTag("GameManager").GetComponent <PathfindingManager>(); movesLeft = 3; }
// Use this for initialization void Start() { selfCollider = transform.GetComponent <BoxCollider2D>(); colliderx = selfCollider.size.x / 2f; collidery = selfCollider.size.y / 2f; pathfindingMNG = GameObject.FindGameObjectWithTag("Manager").GetComponent <PathfindingManager>(); }
private IEnumerator MoveToInteraction(Interactable interactable, string interaction) { Collider2D c = GetComponent <Collider2D>(); Debug.LogWarning("Moving to interaction " + interactable.ToString()); while (interactable) { if (!c.IsTouching(interactable.GetComponent <Collider2D>())) { PathfindingManager.RequestPath(new PathRequest(transform.position, interactable.transform.position, uc.OnPathFound)); yield return(new WaitForSeconds(.2f)); //might be able to extend this here? no need to be as precise? } else { uc.StopMoving(); break; } } //if the interactable is still there when we get there if (interactable != null) { interactable.Interaction(interaction); } yield break; }
private void CreateTestUniverse() { _game = new Game(new NewGameSettings { GameName = "Pathfinding Test Game", StartDateTime = DateTime.Now, MaxSystems = 10 }); _pathfindingManager = new PathfindingManager(_game); _testPlayer = _game.AddPlayer("TestPlayer"); _authToken = new AuthenticationToken(_testPlayer.ID); _humanFaction = DefaultStartFactory.DefaultHumans(_game, _testPlayer, "TestHumanFaction"); List <StarSystem> systems = _game.GetSystems(new AuthenticationToken(_game.SpaceMaster.ID)); var factionInfoDB = _humanFaction.GetDataBlob <FactionInfoDB>(); List <StarSystem> testPlayerSystems = _game.GetSystems(_authToken); StarSystem starSystem; StarSystem sol = testPlayerSystems[0]; Random RNG = new Random(); do { starSystem = systems[RNG.Next(systems.Count - 1)]; } while (starSystem == sol); factionInfoDB.KnownSystems.Add(starSystem.Guid); }
IEnumerator FindPath() { //while (true) { yield return(new WaitForSeconds(1F)); PathfindingManager.RequestPath(transform.position, target.position, OnPathFound); //} }
private void SpawnMonster() { Monster monster = Instantiate(monsterPrefab, start, Quaternion.identity).GetComponent <Monster>(); PathfindingManager randomManager = pfManagers[Random.Range(0, pfManagers.Length)]; monster.pm = randomManager; monster.target = target; }
// void Awake() { if (_instance == null) { _instance = this; } _gridSystem = GetComponent <GridSystem>(); }
void Awake() { if (instance == null) { instance = this; } else { Destroy (this.gameObject); } }
public PathfindingThread(PathfindingManager m, int number) { this.ThreadNumber = number; this.manager = m; this.Pathfinder = new Pathfinding(); this.watch = new System.Diagnostics.Stopwatch(); this.secondWatch = new System.Diagnostics.Stopwatch(); }
// public static PathfindingManager GetInstance() { // Uses lazy initialization. if (_instance == null) { _instance = new PathfindingManager(); } return(_instance); }
public void Update() { float deltaTime = Time.unscaledDeltaTime; PathfindingManager.Update(); UpdateTimer(deltaTime); UpdateStats(deltaTime); }
AStar astar; // Calculation of path on graph // Use this for initialization void Start () { if (Instance == null){ Instance = this; } else { Debug.LogError("Only one instance of PathfindingManager can be created"); } graph = new PathfindingGraph(); }
void Awake() { m_pfm = GetComponent <PathfindingManager>(); m_cam = Camera.main; m_party = new List <GameObject>(); m_enemies = new List <GameObject>(); m_previousTile = m_pfm.GetTile(0, 0); currGameState = GameState.PlayerSelectTile; }
private IEnumerator UpdatePath(PathTarget pathTarget) { while (true) { if (pathTarget != null) { PathfindingManager.getInstance().RequestPath(transform.position, pathTarget.GetTarget(), GameManager.instance.GetCurrentGrid(), OnPathFound); } yield return(new WaitForSeconds(0.25f)); } }
//Listeners void Awake() { //Singleton if (_instance == null) { _instance = this; } else { Destroy(this.gameObject); } }
private IEnumerator Flee() { Vector3 closestExit = GetClosestExit(); float z = transform.position.z; PathfindingManager.RequestPath(new PathRequest(transform.position, closestExit, usm.unitController.OnPathFound)); while (Vector3.Distance(transform.position, closestExit) > 0.5f) { yield return(null); } usm.RequestChangeState(StateMachine.States.Routed); }
private void Awake() { if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } DontDestroyOnLoad(gameObject); }
private IEnumerator Wander() { while (true) { Vector3 lastPos = transform.position; PathfindingManager.RequestPath(new PathRequest(transform.position, RandomWanderSpot(), usm.unitController.OnPathFound)); //Debug.Log(gameObject + " is wandering"); yield return(new WaitForSeconds(Random.Range(3.0f, 7.0f))); PathfindingManager.RequestPath(new PathRequest(transform.position, lastPos, usm.unitController.OnPathFound)); yield return(new WaitForSeconds(Random.Range(3.0f, 7.0f))); } }
public void Awake() { // Singleton setup if (instance == null) { instance = this; } else if (instance != this) { Destroy(this); } grid = GetComponent <Grid>(); }
public void GetPath_ManagerNotStarted_ThrowsException() { using var gate = new AutoResetEvent(false); var callback = new PathfindingCallback(gate); IPathfindingManager manager = new PathfindingManager(); try { Assert.That(() => { manager.GetPath(_map, ref _map.GetCell(0, 0), ref _map.GetCell(_map.Columns - 1, _map.Rows - 1), Locomotion.Walk, callback, 0); }, Throws.InvalidOperationException); } finally { manager.Stop(); } }
public void Start_NotStarted_ThreadStarted() { using var gate = new AutoResetEvent(false); IPathfindingManager manager = new PathfindingManager(); int startCount = 0; manager.Started += (_, __) => { startCount += 1; gate.Set(); }; manager.Start(); gate.WaitOne(DELAY_MS); manager.Stop(); Assert.That(startCount, Is.EqualTo(1)); }
public void Test() { var nodeA = new PathNode(); var nodeB = new PathNode(); var nodeC = new PathNode(); var nodeD = new PathNode(); nodeA.ConnectAsymmetrically(nodeB); nodeB.ConnectAsymmetrically(nodeC); nodeC.ConnectAsymmetrically(nodeD); // A -> B -> C -> D var pathfinder1 = new Pathfinder(new PathRequest(nodeA, nodeB)); var pathfinder2 = new Pathfinder(new PathRequest(nodeA, nodeC)); var pathfinder3 = new Pathfinder(new PathRequest(nodeA, nodeD)); var pathfinder4 = new Pathfinder(new PathRequest(nodeC, nodeA)); var pathfindingManager = new PathfindingManager(); pathfindingManager.Pathfinders.AddRange(new[] { pathfinder1, pathfinder2, pathfinder3, pathfinder4 }); for (var i = 0; i < 10; i++) { pathfindingManager.Update(); if (pathfindingManager.Pathfinders.Count >= 4) { Assert.Contains(pathfinder1, pathfindingManager.Pathfinders); } if (pathfindingManager.Pathfinders.Count >= 3) { Assert.Contains(pathfinder2, pathfindingManager.Pathfinders); } if (pathfindingManager.Pathfinders.Count >= 2) { Assert.Contains(pathfinder3, pathfindingManager.Pathfinders); } } Assert.Zero(pathfindingManager.Pathfinders.Count); Assert.IsTrue(new[] { pathfinder1, pathfinder2, pathfinder3 }.All(pf => pf.State == PathfindingState.Successful)); Assert.IsTrue(pathfinder4.State == PathfindingState.Failed); }
public override string Execute(object[] args) { string arg = ((string)(args[0])).Trim().ToLower(); if (arg == "stats") { CommandProcessing.Log("Max open nodes: " + Pathfinding.MAX); CommandProcessing.Log("Max pending requests: " + PathfindingManager.MAX_PENDING); CommandProcessing.Log(PathfindingManager.GetPendingIDs()); return(null); } if (arg == "wipe") { CommandProcessing.Log("Wiping: " + PathfindingManager.GetPending().Count + " pending requests."); PathfindingManager.DissolveAllPending(); return(null); } return("Error: Unknown pathing sub-command '" + arg + "'. Valid commands are 'stats' and 'wipe'"); }
void Awake() { map = FindObjectOfType <Map> (); pathfinding = FindObjectOfType <PathfindingManager> (); gameOverOverlay.SetActive(false); if (!map) { Debug.LogWarning("Map not found"); } if (!levelChooser) { Debug.LogWarning("Level dropdown not found"); } if (!pathfinding) { Debug.LogWarning("Pathfinding manager not found"); } if (players.Length < 2) { Debug.LogWarning("Not enough players to play the game"); } if (!gameOverOverlay) { Debug.LogWarning("No game over screen"); } if (!levelsOverlay) { Debug.LogWarning("No level choosing screen"); } levelChooser.options.Clear(); levelChooser.options.AddRange(System.IO.Directory.GetFiles("./levels").Select(x => new Dropdown.OptionData(x)).ToArray()); }
public void WaypointSystemChangedCallback() { WaypointManager wg = GameObject.Find("WaypointManager").GetComponent <WaypointManager>(); var sources = wg.pathNodes; int startIndex = -1; int endIndex = -1; if (actualStartNode == null || !actualStartNode.nodeValid) { startIndex = PathfindingManager.Closest(sources, startNodePosition); actualStartNode = sources[startIndex]; } if (actualTargetNode == null || !actualTargetNode.nodeValid) { endIndex = PathfindingManager.Closest(sources, endNodePosition); actualTargetNode = sources[endIndex]; } bool found = false; if (path != null) { //foreach (PathNode pn in path) for (int i = 0; i < path.Count; i++) { PathNode pn = path[i]; if (pn == null || !pn.nodeEnabled || !pn.nodeValid) { found = true; break; } } if (found) { path.Clear(); } } }
public void Awake() { // Get a reference to the pathfinding manager... PathfindingManager manager = PathfindingManager.Instance; // Give the manager our custom tile provider. That's it! manager.Provider = new CustomTileProvider(this); // Camera work, to center the camera on the world. Demo purposes only. Camera.main.transform.position = new Vector3(Width / 2, Height / 2, -10f); Camera.main.orthographicSize = Height / 2f + 1; // Position the background sprite. Vector3 center = new Vector3(Width / 2 - 0.5f, Height / 2 - 0.5f); Background.transform.position = center; Background2.transform.position = center; Background.size = new Vector2(Width + 1, Height + 1); Background2.size = new Vector2(Width + 0, Height + 0); // Initialize tile array. Tiles = new bool[Width, Height]; }
private IEnumerator Engage(Transform _targetTransform) { //Debug.LogError(gameObject.name + " is engaging " + _targetTransform.name); bool inRange; targetTransform = _targetTransform; targetBody = targetTransform.GetComponent <BodyPartController>(); attack1Parts = usm.attack1Parts; attack2Parts = usm.attack2Parts; UnitController uc = usm.unitController; BodyPartController opponent = targetTransform.GetComponent <BodyPartController>(); Collider2D col = GetComponent <Collider2D>(); usm.unitAnim.FaceDirection(transform.position, targetTransform.position); while (!opponent.Incapacitated()) { //eventually this will be a function that will check if ranged or melee, then decide if in range or not //for ranged we can use a raycast of some sort to check for obstabcles inRange = col.IsTouching(targetTransform.GetComponent <Collider2D>()); if (!inRange) { PathfindingManager.RequestPath(new PathRequest(transform.position, targetTransform.position, uc.OnPathFound)); yield return(new WaitForSeconds(.1f)); } else if (!usm.attackTimer.coolingDown) { Attack(); } yield return(null); } usm.RequestChangeState(StateMachine.States.Idle); yield break; }
void Awake() { instance = this; pathfinding = GetComponent <Pathfinding>(); }