void UpdatePath() { if (seeker.IsDone()) { seeker.StartPath(transform.position, target.position, OnPathComplete, GraphMask.FromGraphName("Grid Graph")); } }
public void RequestPath(PathRequest request) { if (!graphs.ContainsKey(request.unitSize)) { CreateGraph(request.unitSize); } request.seeker.StartPath(request.start, request.goal, request.callback, GraphMask.FromGraph(graphs[request.unitSize])); }
protected override int OnUpgradeSerializedData(int version, bool unityThread) { if (graphMaskCompatibility != -1) { Debug.Log("Loaded " + graphMaskCompatibility + " " + graphMask.value); graphMask = graphMaskCompatibility; graphMaskCompatibility = -1; } return base.OnUpgradeSerializedData(version, unityThread); }
void Update() { if (Vector3.SqrMagnitude(transform.position - playerTransformSceneReference.Value.position) < sqrRadius) { seeker.graphMask = GraphMask.FromGraph(highResGraph); } else { seeker.graphMask = GraphMask.FromGraph(lowResGraph); } }
private void Start() { soundController = FindObjectOfType <SoundController>(); GetComponent <Seeker>().graphMask = GraphMask.FromGraphName("Enemy Graph"); aiPath = GetComponent <AIPath>(); animator = GetComponent <Animator>(); mode = Mode.Walking; gfxScale = enemyGFX.transform.localScale; curHealth = enemySettings.health; spriteRenderer = enemyGFX.GetComponent <SpriteRenderer>(); defaultMaterial = spriteRenderer.material; // dieMaterialEdge = dieMaterial.GetFloat("edge"); dieMaterial = new Material(dieShader); bulletCollider = GetComponent <BoxCollider2D>(); enemyCollider = transform.GetChild(0).GetComponent <Collider2D>(); CyclesManager.Instance.NightSettings.OnCycleEnd.Register(gameObject, o => Die()); rb = GetComponent <Rigidbody2D>(); originalConstraints = rb.constraints; }
void ToggleMinerMode(bool isActive) { float waypointMinerMode = 0; if (targetQueue.Count > 0) { waypointMinerMode = targetQueue[0].z; } if (isActive && waypointMinerMode != 1) { seeker.graphMask = GraphMask.FromGraphName("Cleared Paths"); minerMode = false; GetComponentInChildren <ShipDrilling>().drillCollider.enabled = false; FindObjectOfType <PlayerController>().recentMinerToggle = true; } else if (!isActive || waypointMinerMode == 1) { seeker.graphMask = GraphMask.FromGraphName("Mining Paths"); GetComponentInChildren <ShipDrilling>().drillCollider.enabled = true; minerMode = true; } }
/// <summary> /// Call this function to start calculating a path. /// /// The callback will be called when the path has been calculated (which may be several frames into the future). /// The callback will not be called if a new path request is started before this path request has been calculated. /// /// Version: Since 3.8.3 this method works properly if a MultiTargetPath is used. /// It now behaves identically to the StartMultiTargetPath(MultiTargetPath) method. /// </summary> /// <param name="p">The path to start calculating</param> /// <param name="callback">The function to call when the path has been calculated</param> /// <param name="graphMask">Mask used to specify which graphs should be searched for close nodes. See #Pathfinding.GraphMask. This will override #graphMask for this path request.</param> public Path StartPath(Path p, OnPathDelegate callback, GraphMask graphMask) { p.nnConstraint.graphMask = graphMask; StartPathInternal(p, callback); return(p); }
/// <summary> /// Call this function to start calculating a path. /// /// callback will be called when the path has completed. /// Callback will not be called if the path is canceled (e.g when a new path is requested before the previous one has completed) /// </summary> /// <param name="start">The start point of the path</param> /// <param name="end">The end point of the path</param> /// <param name="callback">The function to call when the path has been calculated</param> /// <param name="graphMask">Mask used to specify which graphs should be searched for close nodes. See #Pathfinding.NNConstraint.graphMask. This will override #graphMask for this path request.</param> public Path StartPath(Vector3 start, Vector3 end, OnPathDelegate callback, GraphMask graphMask) { return(StartPath(ABPath.Construct(start, end, null), callback, graphMask)); }
public void Move(Vector3 destination, GraphMask graphMask) { seeker.StartPath(transform.position, destination, OnPathComplete, graphMask); }
protected override IEnumerator CharacterSetup_UpdateCharacterSetup() { spawnedGameObject.layer = gamemode.SingleAllyLayer; spawnedGameObject.tag = gamemode.AllyTag; if (AllySpecificComponentsToSetUp.bBuildCharacterCompletely) { spawnedGameObject.AddComponent <AllyStatControllerRPG>(); //spawnedGameObject.AddComponent<AllyActionQueueController>(); //Spawn Child Objects if (AllAllyComponentFields.bBuildLOSChildObject) { var _losObject = new GameObject("LOSObject"); _losObject.transform.parent = spawnedGameObject.transform; _losObject.transform.localPosition = AllAllyComponentFields.LOSChildObjectPosition; _losObject.transform.localEulerAngles = AllAllyComponentFields.LOSChildObjectRotation; AllySpecificComponentsToSetUp.LOSChildObjectTransform = _losObject.transform; } if (AllySpecificComponentsToSetUp.bBuildEnemyHealthBar && AllAllyComponentFields.EnemyHealthBarPrefab != null) { var _enemyHealthBar = GameObject.Instantiate(AllAllyComponentFields.EnemyHealthBarPrefab, spawnedGameObject.transform, false); var _rect = _enemyHealthBar.GetComponent <RectTransform>(); _rect.localPosition = AllAllyComponentFields.EnemyHealthBarPosition; _rect.localEulerAngles = AllAllyComponentFields.EnemyHealthBarRotation; _rect.sizeDelta = AllAllyComponentFields.EnemyHealthSizeDelta; _rect.anchorMin = new Vector2(0.5f, 0.5f); _rect.anchorMax = new Vector2(0.5f, 0.5f); _rect.pivot = new Vector2(0.5f, 0.5f); _rect.localScale = AllAllyComponentFields.EnemyHealthLocalScale; //Attempt To Set Health and ActiveBar Images By Looking For Them in Code foreach (var _image in _enemyHealthBar.transform.GetComponentsInChildren <Image>(true)) { if (_image.name.ToLower().Contains("health")) { AllySpecificComponentsToSetUp.EnemyHealthBarImage = _image; } else if (_image.name.ToLower().Contains("active")) { AllySpecificComponentsToSetUp.EnemyActiveBarImage = _image; } } } if (AllAllyComponentFields.bBuildAllyIndicatorSpotlight && AllAllyComponentFields.AllyIndicatorSpotlightPrefab != null) { var _spotlight = GameObject.Instantiate(AllAllyComponentFields.AllyIndicatorSpotlightPrefab, spawnedGameObject.transform, false); _spotlight.transform.localPosition = AllAllyComponentFields.AllyIndicatorSpotlightPosition; _spotlight.transform.localEulerAngles = AllAllyComponentFields.AllyIndicatorSpotlightRotation; AllySpecificComponentsToSetUp.AllyIndicatorSpotlightInstance = _spotlight; _spotlight.GetComponent <Light>().enabled = false; } } // Wait For 0.05 Seconds yield return(new WaitForSeconds(0.05f)); //Delay Adding These Components //Added Redundant Check For Now For Organization if (AllySpecificComponentsToSetUp.bBuildCharacterCompletely) { spawnedGameObject.AddComponent <AllyMemberRPG>(); spawnedGameObject.AddComponent <AIControllerRPG>(); spawnedGameObject.AddComponent <RPGCharacter>(); spawnedGameObject.AddComponent <RPGSpecialAbilities>(); spawnedGameObject.AddComponent <RPGWeaponSystem>(); spawnedGameObject.AddComponent <AllyVisualsRPG>(); //spawnedGameObject.AddComponent<AllyTacticsRPG>(); } #if RTSAStarPathfinding if (AllySpecificComponentsToSetUp.bBuildCharacterCompletely && AllAllyComponentFields.bUseAStarPath && spawnedGameObject.GetComponent <Seeker>() == null && spawnedGameObject.GetComponent <AIPath>() == null) { var _aiStarSeeker = spawnedGameObject.AddComponent <Seeker>(); var _aiStarAIPath = spawnedGameObject.AddComponent <AIPath>(); _aiStarSeeker.graphMask = GraphMask.FromGraphName(AllAllyComponentFields.aStar_traversableGraphs); _aiStarAIPath.radius = AllAllyComponentFields.aStar_Radius; _aiStarAIPath.height = AllAllyComponentFields.aStar_Height; _aiStarAIPath.canSearch = AllAllyComponentFields.aStar_CanSearch; _aiStarAIPath.repathRate = AllAllyComponentFields.aStar_RepathRate; _aiStarAIPath.canMove = AllAllyComponentFields.aStar_CanMove; _aiStarAIPath.maxSpeed = AllAllyComponentFields.aStar_MaxSpeed; _aiStarAIPath.orientation = AllAllyComponentFields.aStar_Orientation; _aiStarAIPath.enableRotation = AllAllyComponentFields.aStar_EnableRotation; _aiStarAIPath.pickNextWaypointDist = AllAllyComponentFields.aStar_PickNextWaypointDistance; _aiStarAIPath.slowdownDistance = AllAllyComponentFields.aStar_SlowdownDistance; _aiStarAIPath.endReachedDistance = AllAllyComponentFields.aStar_EndReachedDistance; _aiStarAIPath.alwaysDrawGizmos = AllAllyComponentFields.aStar_AlwaysDrawGizmos; _aiStarAIPath.whenCloseToDestination = AllAllyComponentFields.aStar_CloseToDestination; _aiStarAIPath.constrainInsideGraph = AllAllyComponentFields.aStar_ConstrainInsideGraph; } #endif //Call Ally Init Comps Event var _eventHandler = spawnedGameObject.GetComponent <AllyEventHandler>(); _eventHandler.CallInitializeAllyComponents(AllySpecificComponentsToSetUp, AllAllyComponentFields); }
/// <summary>Prepares the path. Searches for start and end nodes and does some simple checking if a path is at all possible</summary> //!!!!!IMPORTANT: HACKY MODIFICATION IN THIS FUNCTION TO IGNORE POINT GRAPH NODES WHICH WAS CAUSING WONKY //BEHAVIORS, SHOULD CHANGE AND FIGURE OUT ROOT ISSUE!!!! protected override void Prepare() { AstarProfiler.StartProfile("Get Nearest"); //Initialize the NNConstraint nnConstraint.tags = enabledTags; NNConstraint newConstraint = NNConstraint.Default; newConstraint.graphMask = GraphMask.FromGraph(AstarPath.active.data.gridGraph); var startNNInfo = AstarPath.active.GetNearest(startPoint, newConstraint); //var startNNInfo = AstarPath.active.GetNearest(startPoint, nnConstraint); //Tell the NNConstraint which node was found as the start node if it is a PathNNConstraint and not a normal NNConstraint var pathNNConstraint = nnConstraint as PathNNConstraint; if (pathNNConstraint != null) { pathNNConstraint.SetStart(startNNInfo.node); } startPoint = startNNInfo.position; startIntPoint = (Int3)startPoint; startNode = startNNInfo.node; if (startNode == null) { FailWithError("Couldn't find a node close to the start point"); return; } if (!CanTraverse(startNode)) { FailWithError("The node closest to the start point could not be traversed"); return; } // If it is declared that this path type has an end point // Some path types might want to use most of the ABPath code, but will not have an explicit end point at this stage if (hasEndPoint) { // var endNNInfo = AstarPath.active.GetNearest(endPoint, nnConstraint); var endNNInfo = AstarPath.active.GetNearest(endPoint, newConstraint); endPoint = endNNInfo.position; endNode = endNNInfo.node; if (endNode == null) { FailWithError("Couldn't find a node close to the end point"); return; } // This should not trigger unless the user has modified the NNConstraint if (!CanTraverse(endNode)) { FailWithError("The node closest to the end point could not be traversed"); return; } // This should not trigger unless the user has modified the NNConstraint if (startNode.Area != endNode.Area) { FailWithError("There is no valid path to the target"); return; } #if !ASTAR_NO_GRID_GRAPH // Potentially we want to special case grid graphs a bit // to better support some kinds of games // If this returns true it will overwrite the // endNode, endPoint, hTarget and hTargetNode fields if (!EndPointGridGraphSpecialCase(endNNInfo.node)) #endif { // Note, other methods assume hTarget is (Int3)endPoint hTarget = (Int3)endPoint; hTargetNode = endNode; // Mark end node with flag1 to mark it as a target point pathHandler.GetPathNode(endNode).flag1 = true; } } AstarProfiler.EndProfile(); }