private void PlaceDownBuilding() { if (overlappingBuildingCounter == 0) { FollowMousePosition(); // Place at current mouse position InPlacement = false; // Stop local placement flag CameraRTS.useMouseRotation = originalMouseRotationStatus; // Reset the original camera rotation option ApplyColorMultiplierToBuilding(new Color(1, 1, 1)); // Reset original color // Activate display on minimap since the building will not exist on the terrain GetComponent <BuildingManager>().MiniMapVisibility = true; // Desactivate trigger events // Since the building is placed down, it will not move anymore. No need to detect future trigger // event (enter/exit). Future collisions will be managed by following buildings that need placement. GetComponent <BoxCollider>().isTrigger = false; // Reset global building placement flag CameraRTS.GetComponent <SelectorManager>().AnyInPlacementFlag = false; // Verify if the BoxCollider(s) can be found within the containing GameObject if (UnwalkableColliders == null) { return; } var colliders = UnwalkableColliders.GetComponents <BoxCollider>(); if (colliders == null || colliders.Length <= 0) { return; } // Update the unwalkable node grid with the newly placed building area now obstructing the terrain var corners = new Vector3[colliders.Length * 2]; for (var i = 0; i < colliders.Length; i++) { // Find the BoxCollider's minimum and maximum boundaries to // specify as a localized region to search for obstructions corners[2 * i] = colliders[i].bounds.min; corners[2 * i + 1] = colliders[i].bounds.max; } GridRequestManager.RequestGridAreaUpdate(corners); #if OUTPUT_DEBUG #region DEBUG Debug.Log(string.Format("PLACE BUILDING DOWN, Camera Rotation: {0}", RTSCamera.useMouseRotation)); #endregion #endif } }
private void UpdatePositionOnGrid() { // Find the BoxCollider's minimum and maximum boundaries to // specify as a localized region to search for obstructions var corners = new Vector3[2]; var colliderBounds = GetComponent <BoxCollider>().bounds; // Extend the bounds to make sure to capture the unit's current, previous and next positions to // properly update the grid object values for all surrounding nodes affected the unit at any time colliderBounds.extents = new Vector3(colliderBounds.extents.x * 2, 0, colliderBounds.extents.z * 2); corners[0] = colliderBounds.min; corners[1] = colliderBounds.max; // Request the update of grid obstruction by the unit, or reset the area when the unit is destroyed GridRequestManager.RequestGridAreaUpdate(corners, UnitID, Health <= 0); }