private static Quaternion Rotate(Quaternion q, SpawnRotation rotation) { switch (rotation) { case SpawnRotation.Right: q *= Quaternion.Euler(0, 0, 0); break; case SpawnRotation.Left: q *= Quaternion.Euler(0, 0, 180); break; case SpawnRotation.Up: q *= Quaternion.Euler(0, 0, 90); break; case SpawnRotation.Down: q *= Quaternion.Euler(0, 0, -90); break; default: q *= Quaternion.Euler(0, 0, 0); break; } return(q); }
public void Save() { var path = Path.Combine(Application.RootFolder, "Routes", Name + ".route"); if (!File.Exists(path)) { File.Delete(path); } List <string> lines = new List <string>(); lines.Add(PreviewCameraPosition.ConvertToString()); lines.Add(PreviewCameraDirection.ConvertToString()); lines.Add(""); lines.Add(SpawnPosition.ConvertToString()); lines.Add(SpawnRotation.ConvertToString()); lines.Add(""); Application.Console.WriteLine("[Route.Save]: Saving route " + Name + " with " + Barriers.Count + " barriers"); foreach (var b in Barriers) { Application.Console.WriteLine("[Route.Save]: Writing barrier with midpoint " + b.Midpoint.X + " | " + b.Midpoint.Y); for (int j = 0; j < b.Coordinates.Count; j++) { lines.Add(b.Coordinates[j].ConvertToString()); Application.Console.WriteLine(b.Coordinates[j].ConvertToString()); } lines.Add(""); } File.WriteAllLines(path, lines); }
private void SpawnDiagonal(SpawnRotation rotation, int spawnSize, Vector3 spwnpos) { var flockRotation = (SpawnRotation)Random.Range(0, 4); var spawnRotation = Rotate(transform.rotation, rotation); var defaultRotation = Rotate(transform.rotation, (SpawnRotation)Random.Range(0, 4)); spwnpos.x += flockRotation == SpawnRotation.Left || flockRotation == SpawnRotation.Down ? -(Offset * spawnSize / 2.3f) : Offset * spawnSize / 2.3f; spwnpos.y += (Offset * spawnSize / 2.3f); var randomInt = Random.Range(0, spawnSize - 1); for (var i = 0; i < spawnSize; i++) { if (randomInt == i) { _rightSpawn = ObjectPool.Spawn(SpawnObject, spwnpos, spawnRotation); } else { LastSpawned.Add(ObjectPool.Spawn(SpawnObject, spwnpos, defaultRotation)); } spwnpos.x += flockRotation == SpawnRotation.Left || flockRotation == SpawnRotation.Down ? Offset : -Offset; spwnpos.y -= Offset; } }
private void SpawnCircle(SpawnRotation rotation, int spawnSize, Vector3 spwnpos) { var spawnRotation = Rotate(transform.rotation, rotation); var defaultRotation = Rotate(transform.rotation, (SpawnRotation)Random.Range(0, 4)); var randomInt = Random.Range(0, spawnSize - 1); for (var i = 0; i < spawnSize; i++) { var radius = (spawnSize * Offset) / Mathf.PI; var angle = (360 / spawnSize) * i; var pos = new Vector2( (float)(spwnpos.x + radius * Mathf.Sin(angle * Mathf.Deg2Rad)), (float)(spwnpos.y + radius * Mathf.Cos(angle * Mathf.Deg2Rad)) ); if (randomInt == i) { _rightSpawn = ObjectPool.Spawn(SpawnObject, pos, spawnRotation); } else { LastSpawned.Add(ObjectPool.Spawn(SpawnObject, pos, defaultRotation)); } } }
public void StartGame() { ObjectPool.CreatePool(SpawnObject); //AnimeSpawn(); var spwnpos = Camera.main.ScreenToWorldPoint(new Vector2(_screenSize.x / 2, _screenSize.y / 2)); spwnpos.z = 10; UpdateSpawnArea(); SpawnArrow(SpawnRotation.Right, 1, spwnpos); LastSpawRotation = SpawnRotation.Right; }
public bool SpawnArrows(SpawnType type, SpawnRotation rotation, int spawnSize = 5) { if (spawnSize >= 5) { ScreenOffsetTop = ScreenOffsetBottom = ScreenOffsetRight = ScreenOffsetLeft = 0.7f; } UpdateSpawnArea(); LastSpawRotation = rotation; Vector2 screenOffset = Camera.main.WorldToScreenPoint(new Vector3(Offset, Offset)); var sOffXl = screenOffset.x * ScreenOffsetLeft; var sOffXr = screenOffset.x * ScreenOffsetRight; var sOffYt = screenOffset.y * ScreenOffsetTop; var sOffYb = screenOffset.y * ScreenOffsetBottom; var spwnpos = Camera.main.ScreenToWorldPoint(new Vector3( Random.Range(sOffXl, _screenSize.x - sOffXr), Random.Range(sOffYt, _screenSize.y - sOffYb) )); spwnpos.z = ZIndex; LastPosition = spwnpos; switch (type) { case SpawnType.Arrow: SpawnArrow(rotation, spawnSize, spwnpos); break; case SpawnType.Diagonal: SpawnDiagonal(rotation, spawnSize, spwnpos); break; case SpawnType.Line: SpawnLine(rotation, spawnSize, spwnpos); break; case SpawnType.Circle: SpawnCircle(rotation, spawnSize, spwnpos); break; } return(true); }
private void SpawnArrow(SpawnRotation rotation, int spawnSize, Vector3 spwnpos) { var flockRotation = (SpawnRotation)Random.Range(0, 4); var spawnRotation = Rotate(transform.rotation, rotation); var defaultRotation = Rotate(transform.rotation, (SpawnRotation)Random.Range(0, 4)); switch (flockRotation) { case SpawnRotation.Right: spwnpos.x -= Offset / 2 * spawnSize / 4; spwnpos.y += (Offset * spawnSize / 2.3f); break; case SpawnRotation.Left: spwnpos.x += Offset / 2 * spawnSize / 4; spwnpos.y += (Offset * spawnSize / 2.3f); break; case SpawnRotation.Down: spwnpos.x += (Offset * spawnSize / 2.3f); spwnpos.y += Offset / 2 * spawnSize / 4; break; case SpawnRotation.Up: spwnpos.x += (Offset * spawnSize / 2.3f); spwnpos.y -= Offset / 2 * spawnSize / 4; break; } var randomInt = Random.Range(0, spawnSize - 1); for (var i = 0; i < spawnSize; i++) { if (randomInt == i) { _rightSpawn = ObjectPool.Spawn(SpawnObject, spwnpos, spawnRotation); } else { LastSpawned.Add(ObjectPool.Spawn(SpawnObject, spwnpos, defaultRotation)); } switch (flockRotation) { case SpawnRotation.Right: spwnpos.x += i < (spawnSize / 2) ? Offset : -Offset; spwnpos.y -= Offset; break; case SpawnRotation.Left: spwnpos.x += i < (spawnSize / 2) ? -Offset : Offset; spwnpos.y -= Offset; break; case SpawnRotation.Down: spwnpos.y += i < (spawnSize / 2) ? -Offset : Offset; spwnpos.x -= Offset; break; case SpawnRotation.Up: spwnpos.y += i < (spawnSize / 2) ? Offset : -Offset; spwnpos.x -= Offset; break; } } }