void FixedUpdate() { if (Input.GetKey(KeyCode.Keypad0)) { bCull = !bCull; } Transform playerTransform = checkpoint.FollowCamera.target.transform; //Debug.Log(checkpoint.RoadMapRoot.GetComponentsInChildren<RoadGenerator>().Length + " 35:" + checkpoint.RoadMapRoot.GetComponentsInChildren<RoadGenerator>()[35].gameObject.name); if (checkpoint.RoadMapRoot.GetComponentsInChildren <RoadGenerator>().Length > 100 /*usually around 140, prevent checking until the map is up to size*/ && EmergencyFieldRemover == null && checkpoint.RoadMapRoot.GetComponentsInChildren <RoadGenerator>()[35] as DisabledRoadGenerator != null /*35 is around a quarter, meaning grass at this position indicates a map with three quarters grass*/) { int i = RoadGenerator.Wrap0to7(Mathf.RoundToInt(playerTransform.rotation.eulerAngles.y / 45.0f)); Vector3 player = RoundDownToGrid(playerTransform.position); hitTest.x = Mathf.FloorToInt(player.x / WorldTileManager.TILE_SIZE) + RoadGenerator.Xoffset(i) * 8; hitTest.z = Mathf.FloorToInt(player.z / WorldTileManager.TILE_SIZE) + RoadGenerator.Zoffset(i) * 8; //Debug.Log("Testing for a hit at grid "+hitTest.x+","+hitTest.z+"; World location "+hitTest.GetWorldPosition()); WorldTile Hit = WorldTileManager.instance.GetTile(hitTest); if (!Hit) { //Debug.Log("F****N FIELD, heading " + playerTransform.rotation.eulerAngles.y + "≈" + (RoadGenerator.Direction)i); EmergencyFieldRemover = Instantiate(FourWay, hitTest.GetWorldPosition() + new Vector3(0, FourWay.GetComponent <RoadGenerator>().YOffset, 0), Quaternion.identity, checkpoint.RoadMapRoot.transform); //Debug.Log("EFR: "+EmergencyFieldRemover.gameObject.name + " at " + (hitTest.GetWorldPosition() + new Vector3(0, FourWay.GetComponent<RoadGenerator>().YOffset, 0))); WorldTileManager.instance.AddTile(EmergencyFieldRemover.GetComponent <WorldTile>()); EmergencyFieldRemover.transform.SetAsFirstSibling(); RoadGenerator newRG = EmergencyFieldRemover.GetComponent <RoadGenerator>(); newRG.CullingExempt = true; newRG.RefreshExits(); //newRG.Extend(true); //checkpoint.RoadMapRoot.BroadcastMessage("Extend", true); } } else if // Emergency Field Remover has come within the invisible boundary lines (σ回ω・)σ ((EmergencyFieldRemover != null && Vector3.Distance(playerTransform.position, EmergencyFieldRemover.transform.position) < checkpoint.FollowCamera.CullDistance) || // Emergency Field Remover is no longer in front of the player (EmergencyFieldRemover != null && Vector3.Dot(playerTransform.position - EmergencyFieldRemover.transform.position, playerTransform.forward) > 90)) { EmergencyFieldRemover.GetComponent <RoadGenerator>().CullingExempt = false; EmergencyFieldRemover = null; } }
public void SetTilePosition(TilePosition pos) { transform.position = pos.GetWorldPosition(); }
public override void Extend(bool bForceOOBExtension = false) { if (!ShouldExtend()) { return; } for (int i = 0; i < hit.Length; i += 2) { if (!hit[i]) { bProbablyHole = true; for (int j = 0; j < hitPlus.Length; j += 2) { hitPlus[j] = null; int k = 1; tp.x = k * Xoffset(j) + Xoffset(i); tp.z = k * Zoffset(j) + Zoffset(i); TilePosition RayLoc = GetTilePosition() + tp; while (!hitPlus[j]) { hitPlus[j] = WorldTileManager.instance.GetTile(RayLoc); k++; tp.x = k * Xoffset(j) + Xoffset(i); tp.z = k * Zoffset(j) + Zoffset(i); RayLoc = GetTilePosition() + tp; if (Vector3.Distance(RayLoc.GetWorldPosition(), gameObject.transform.position) > RoadTileManager.checkpoint.FollowCamera.CullDistance + 100) { break; } } if (hitPlus[j] && hitPlus[j].GetComponent <RoadGenerator>().Exit.Length < 8) { hitPlus[j].GetComponent <RoadGenerator>().RefreshExits(); } if (RoadTileManager.bDebugEnv) { MySpecificDebug += Time.fixedTime + " hitPlus " + (Direction)j + " concluded with " + (hitPlus[j] ? hitPlus[j].gameObject.name + " (" + hitPlus[j].gameObject.transform.position + ")" : "boundary") + "\n"; } if (hitPlus[j] && !hitPlus[j].GetComponent <DisabledRoadGenerator>()) { bProbablyHole = false; } } if (bProbablyHole && bProbablyHoleLastFrame) { GameObject newTileClass = RoadTileManager.Grass; v3.x = Xoffset(i) * WorldTileManager.TILE_SIZE; v3.y = newTileClass.GetComponent <RoadGenerator>().YOffset - transform.position.y; v3.z = Zoffset(i) * WorldTileManager.TILE_SIZE; GameObject newTile = Instantiate(newTileClass, transform.position + v3, Quaternion.identity, RoadTileManager.checkpoint.RoadMapRoot); WorldTileManager.instance.AddTile(newTile.GetComponent <WorldTile>()); if (RoadTileManager.bDebugEnv) { MySpecificDebug += "Placing " + newTile.name + " to the " + (Direction)i + " because of probable hole\n"; } } bProbablyHoleLastFrame = bProbablyHole; } else if (RoadTileManager.bDebugEnv) { MySpecificDebug += Time.fixedTime + " hit " + (Direction)i + " concluded immediately with " + hit[i].gameObject.name + " (" + hit[i].gameObject.transform.position + ")\n"; } } }