|
|
@ -1,6 +1,7 @@ |
|
|
|
using System; |
|
|
|
using System; |
|
|
|
using System.Collections; |
|
|
|
using System.Collections; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Generic; |
|
|
|
|
|
|
|
using System.Linq; |
|
|
|
using Unity.Netcode; |
|
|
|
using Unity.Netcode; |
|
|
|
using Unity.VisualScripting; |
|
|
|
using Unity.VisualScripting; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine; |
|
|
@ -10,6 +11,19 @@ using Random = UnityEngine.Random; |
|
|
|
namespace Game { |
|
|
|
namespace Game { |
|
|
|
public class GameManager : NetworkBehaviour { |
|
|
|
public class GameManager : NetworkBehaviour { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Serializable] |
|
|
|
|
|
|
|
public struct SpawnRatesValue { |
|
|
|
|
|
|
|
public SpawnRate spawnRate; |
|
|
|
|
|
|
|
public float baseSeconds; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
[Serializable] |
|
|
|
|
|
|
|
public struct SpawnableSpawnRates { |
|
|
|
|
|
|
|
public Spawnable spawnable; |
|
|
|
|
|
|
|
public SpawnRatesValue[] values; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public SpawnableSpawnRates[] spawnRates; |
|
|
|
|
|
|
|
|
|
|
|
public Object ballPrefab; |
|
|
|
public Object ballPrefab; |
|
|
|
public Object playerPrefab; |
|
|
|
public Object playerPrefab; |
|
|
|
public Object borderZonePrefab; |
|
|
|
public Object borderZonePrefab; |
|
|
@ -28,7 +42,6 @@ namespace Game { |
|
|
|
|
|
|
|
|
|
|
|
private void Awake() { |
|
|
|
private void Awake() { |
|
|
|
SetupPlayers(); |
|
|
|
SetupPlayers(); |
|
|
|
SpawnBall(Player1, true); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void OnEnable() { |
|
|
|
private void OnEnable() { |
|
|
@ -39,17 +52,38 @@ namespace Game { |
|
|
|
QualitySettings.vSyncCount = 0; |
|
|
|
QualitySettings.vSyncCount = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private IEnumerator Start() { |
|
|
|
private IEnumerator SpawnLoop(Spawnable spawnable) { |
|
|
|
|
|
|
|
SpawnRate required = SpawnRate.Normal; //Settings.SpawnRates[spawnable]; |
|
|
|
|
|
|
|
if (required == SpawnRate.Never) |
|
|
|
|
|
|
|
yield break; |
|
|
|
|
|
|
|
float baseSeconds = spawnRates.First(s => s.spawnable == spawnable).values.First(v => v.spawnRate == required).baseSeconds; |
|
|
|
while (Application.isPlaying) { |
|
|
|
while (Application.isPlaying) { |
|
|
|
yield return new WaitForSeconds(1); |
|
|
|
yield return new WaitForSeconds(baseSeconds); |
|
|
|
SpawnModification(); |
|
|
|
switch (spawnable) { |
|
|
|
yield return new WaitForSeconds(2); |
|
|
|
case Spawnable.NewBallTemporary: |
|
|
|
SpawnWormhole(); |
|
|
|
SpawnNewBall(false); |
|
|
|
yield return new WaitForSeconds(1); |
|
|
|
break; |
|
|
|
SpawnNewBall(); |
|
|
|
case Spawnable.NewBallPermanent: |
|
|
|
|
|
|
|
SpawnNewBall(true); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case Spawnable.Modification: |
|
|
|
|
|
|
|
SpawnModification(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case Spawnable.Wormhole: |
|
|
|
|
|
|
|
SpawnWormhole(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void Start() { |
|
|
|
|
|
|
|
SpawnBall(Player1, true); |
|
|
|
|
|
|
|
StartCoroutine(SpawnLoop(Spawnable.NewBallTemporary)); |
|
|
|
|
|
|
|
StartCoroutine(SpawnLoop(Spawnable.NewBallPermanent)); |
|
|
|
|
|
|
|
StartCoroutine(SpawnLoop(Spawnable.Modification)); |
|
|
|
|
|
|
|
StartCoroutine(SpawnLoop(Spawnable.Wormhole)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void SetupPlayers() { |
|
|
|
private void SetupPlayers() { |
|
|
|
Settings.Type = Type.Hybrid; |
|
|
|
Settings.Type = Type.Hybrid; |
|
|
|
Settings.AIDifficulty = Difficulty.VeryHard; |
|
|
|
Settings.AIDifficulty = Difficulty.VeryHard; |
|
|
@ -95,9 +129,9 @@ namespace Game { |
|
|
|
p1.borderZonePrefab = p2.borderZonePrefab = borderZonePrefab; |
|
|
|
p1.borderZonePrefab = p2.borderZonePrefab = borderZonePrefab; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void SpawnNewBall() { |
|
|
|
private void SpawnNewBall(bool permanent) { |
|
|
|
var pos = new Vector2(Random.Range(0, Dimensions.Singleton.PlaySize.x) - Dimensions.Singleton.PlaySize.x / 2, Random.Range(-5, 5)); |
|
|
|
var pos = new Vector2(Random.Range(0, Dimensions.Singleton.PlaySize.x) - Dimensions.Singleton.PlaySize.x / 2, Random.Range(-5, 5)); |
|
|
|
Instantiate(newBallPrefab, pos, Quaternion.identity).GetComponent<NewBall>().IsPermanent = Random.value > 0.8f; |
|
|
|
Instantiate(newBallPrefab, pos, Quaternion.identity).GetComponent<NewBall>().IsPermanent = permanent; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void SpawnWormhole() { |
|
|
|
private void SpawnWormhole() { |
|
|
|