private void Awake() { if (s_instance != null) { Debug.LogError(DebugUtilities.AddTimestampPrefix("Multiple instances of " + typeof(Environment) + " detected! Destroying additional instance '" + name + "' in favor of the existing one"), s_instance); Destroy(gameObject); return; } // Create containers m_audioRoot = new GameObject("AudioSources").transform; m_entityRoot = new GameObject("Entities").transform; s_instance = this; Debug.Log(DebugUtilities.AddTimestampPrefix("Environment.Awake()"), this); if (!GameManager.IsLoaded) { GameObject gameManagerPrefab = Resources.Load("GameManager", typeof(GameObject)) as GameObject; if (gameManagerPrefab != null) { Debug.Log(DebugUtilities.AddTimestampPrefix("Loading in GameManager resource...")); GameObject go = Instantiate <GameObject>(gameManagerPrefab); go.name = gameManagerPrefab.name; } else { Debug.LogError(DebugUtilities.AddTimestampPrefix("Unable to load GameManager resource!")); } } }
public void SetStateInternal(GameState state) { if (m_state == state) { return; } Debug.Log(DebugUtilities.AddTimestampPrefix("Game state changing from " + m_state + " to " + state)); m_state = state; if (state == GameState.Demo) { SetVolume(-80f); ScenarioManager.InitializeScenario(m_scenario); ScenarioManager.StartRound(0); UserInterface.StartDemoRoutine(); } if (state == GameState.Game) { SetVolume(0f); ScenarioManager.InitializeScenario(m_scenario); ScenarioManager.StartRound(0); } }
public IEnumerator PenaltyRoutine(int playerShotsFired) { // It's fine if a few penalty points take a "long" time to process, but it needs to be fast when there's a lot of them float penaltyCycleInterval = m_penaltyPointInterval; if (playerShotsFired * m_penaltyPointInterval > m_penaltySpeedUpTimeLimit) { penaltyCycleInterval = Mathf.Clamp(m_penaltySpeedUpTimeLimit / playerShotsFired, m_penaltyPointIntervalMin, m_penaltyPointInterval); } //Debug.Log(DebugUtilities.AddTimestampPrefix("Shots penalty being applied! Cycle interval: " + penaltyCycleInterval)); int penaltyAmount = 0; while (playerShotsFired > 0) { playerShotsFired--; ScenarioManager.SetShotsFired(playerShotsFired); ScenarioManager.ModifyScore(-5); penaltyAmount += 5; SetPenaltyAmount(-penaltyAmount); if (m_penaltyPointSFX != null) { Debug.Log(DebugUtilities.AddTimestampPrefix("Chuck!")); m_penaltyPointSFX.PlayOnSource(m_uiAudio); } yield return(new WaitForSecondsRealtime(penaltyCycleInterval)); } }
private void StopRoundRoutine() { if (m_roundRoutineIEnumerator != null) { Debug.LogWarning(DebugUtilities.AddTimestampPrefix("UserInterface stopping previous round routine!")); StopCoroutine(m_roundRoutineIEnumerator); } }
public void SetCanFire(bool canFire) { if (m_canFire != canFire) { Debug.Log(DebugUtilities.AddTimestampPrefix(GetType() + ".SetCanFire(" + canFire + ")"), this); } m_canFire = canFire; }
/// <summary> /// Only one round routine can be active at any given time, this makes sure that holds true /// </summary> /// <param name="routine">IEnumerator to run</param> /// <returns>Started Coroutine</returns> private Coroutine StartRoundRoutine(System.Collections.IEnumerator routine) { if (m_roundRoutineIEnumerator != null) { Debug.LogWarning(DebugUtilities.AddTimestampPrefix("ScenarioManager stopping previous round routine!")); StopCoroutine(m_roundRoutineIEnumerator); } m_roundRoutineIEnumerator = routine; return(StartCoroutine(routine)); }
public static void SetVolume(float volume) { if (s_instance == null) { return; } if (s_instance.m_audioMixer != null) { Debug.Log(DebugUtilities.AddTimestampPrefix("Master volume being set to " + volume.ToString("F2") + "dB")); s_instance.m_audioMixer.SetFloat("VolumeMaster", volume); } }
private void Awake() { if (s_instance != null) { Debug.LogError(DebugUtilities.AddTimestampPrefix("Multiple instances of " + typeof(ScenarioManager) + " detected! Destroying additional instance '" + name + "' in favor of the existing one"), s_instance); Destroy(gameObject); return; } s_instance = this; Debug.Log(DebugUtilities.AddTimestampPrefix("ScenarioManager.Awake()"), this); }
public void EndRoundInternal(bool success) { Debug.Log(DebugUtilities.AddTimestampPrefix("Round is ending...")); m_currentRound.End(); if (OnRoundEndedCallback != null) { OnRoundEndedCallback.Invoke(success); } StartRoundRoutine(RoundEndRoutine(success)); }
public void SetCanControl(bool canControl) { if (m_canControl != canControl) { Debug.Log(DebugUtilities.AddTimestampPrefix(GetType() + ".SetCanControl(" + canControl + ")"), this); } m_canControl = canControl; if (m_cursorTargetObject != null) { m_cursorTargetObject.SetActive(canControl); } }
public virtual void SetActive(bool isActive) { if (enabled != isActive) { Debug.Log(DebugUtilities.AddTimestampPrefix(GetType() + ".SetActive(" + isActive + ")"), this); } enabled = isActive; if (m_cursorTargetObject != null) { m_cursorTargetObject.SetActive(isActive); } }
protected virtual void Awake() { if (m_turret == null) { enabled = false; Debug.LogError(DebugUtilities.AddTimestampPrefix("No Turret for TurretController of type " + GetType() + "!"), this); } if (m_cursorTargetPrefab != null) { m_cursorTargetObject = Instantiate <GameObject>(m_cursorTargetPrefab, Vector3.zero, Quaternion.identity); } ScenarioManager.OnRoundStartedCallback += OnRoundStarted; ScenarioManager.OnRoundEndedCallback += OnRoundEnded; }
private void Awake() { if (s_instance != null) { Debug.LogError(DebugUtilities.AddTimestampPrefix("Multiple instances of " + typeof(GameManager) + " detected! Destroying additional instance '" + name + "' in favor of the existing one"), s_instance); Destroy(gameObject); return; } Cursor.visible = false; m_state = GameState.Init; s_instance = this; Debug.Log(DebugUtilities.AddTimestampPrefix("GameManager.Awake()"), this); }
private void Start() { Debug.Log(DebugUtilities.AddTimestampPrefix("GameManager.Start()"), this); SetVolume(-80f); if (!UserInterface.IsLoaded) { Debug.Log(DebugUtilities.AddTimestampPrefix("Loading in UserInterface scene...")); SceneManager.LoadScene("UserInterface", LoadSceneMode.Additive); } else { Debug.Log(DebugUtilities.AddTimestampPrefix("UserInterface scene was already loaded!")); InitGame(); } }
private void InitGame() { if (m_scenario != null) { if (!ScenarioManager.IsLoaded) { GameObject go = new GameObject("ScenarioManager"); go.AddComponent <ScenarioManager>(); } ScenarioManager.InitializeScenario(m_scenario); SetState(GameState.Demo); } else { Debug.LogError(DebugUtilities.AddTimestampPrefix("No Scenario provided!")); } }
private void OnEntitySpawned(Entity entity) { if (entity.m_team == m_turret.m_team) { return; } if (!m_enemies.ContainsKey(entity.ID)) { //Debug.Log(DebugUtilities.AddTimestampPrefix(GetType() + ": New contact[" + entity.ID + "]: " + entity.name + ")"), entity); // Add to pending contacts since the entity might not have been properly initialized yet m_pendingContacts.Add(entity); } else { Debug.LogWarning(DebugUtilities.AddTimestampPrefix("AIController: Entity spawned with an ID(" + entity.ID + ") that was already registered!"), entity); } }
public IEnumerator AlertRoutine() { if (m_roundStartSFX != null) { int repeats = m_alertSoundCount; while (repeats-- > 0) { Debug.Log(DebugUtilities.AddTimestampPrefix("Beep!")); m_roundStartSFX.PlayOnSource(m_uiAudio); yield return(new WaitForSecondsRealtime(m_alertInterval)); } yield return(new WaitForSecondsRealtime(m_roundStartTimeLimit - m_alertSoundCount * m_alertInterval)); } else { yield return(new WaitForSecondsRealtime(m_roundStartTimeLimit)); } }
private void Update() { if (m_currentRound != null && m_currentRound.HasStarted) { m_currentRound.Update(Time.deltaTime); } if (Input.GetKeyDown(KeyCode.R)) { if (Input.GetKey(KeyCode.LeftShift)) { m_nextRoundIndex += 10; } else { m_nextRoundIndex++; } Debug.Log(DebugUtilities.AddTimestampPrefix("Debug increase next round index to " + m_nextRoundIndex)); } }
public void OnFireCommand(bool canFire) { if (canFire && m_projectilePrefab != null) { Vector3 position = m_muzzleTransform.position; position.z = 0f; Quaternion rotation = Quaternion.LookRotation(m_targetPosition - position, Vector3.back); Entity entity = ScenarioManager.OnSpawnEntity(m_projectilePrefab, position, rotation); if (entity != null) { entity.name = m_projectilePrefab.name + "_" + ScenarioManager.ShotsFired; Projectile projectile = entity as Projectile; if (projectile != null) { float speed = m_projectileSpeed * (ScenarioManager.Scenario != null ? ScenarioManager.Scenario.m_globalSpeedMultiplier : 1f); projectile.Initialize(projectile.ID, m_muzzleTransform.position, m_targetPosition, speed, m_projectileModelPrefab); } else { Debug.LogError(DebugUtilities.AddTimestampPrefix("Couldn't find FuseProjectile component in player missile prefab instance!"), entity); } } if (m_fireSFX != null) { m_fireSFX.PlayAt(m_muzzleTransform.position, Environment.AudioRoot); } ScenarioManager.ModifyShotsFired(1); //Debug.Log(DebugUtilities.AddTimestampPrefix("Turret fired shot " + ScenarioManager.ShotsFired + "!"), entity); } else { m_canNotFireSFX.PlayAt(Camera.main.transform.position, Environment.AudioRoot); } }
private void Awake() { if (s_instance != null) { Debug.LogError(DebugUtilities.AddTimestampPrefix("Multiple instances of " + typeof(UserInterface) + " detected! Destroying additional instance '" + name + "' in favor of the existing one"), s_instance); Destroy(gameObject); return; } s_instance = this; m_demoPromptWidget.SetActive(false); HideRoundStartWidget(); HideRoundEndWidget(); GameObject go = new GameObject("AudioSource_UserInterface"); go.transform.position = Camera.main.transform.position; go.transform.parent = Environment.AudioRoot; m_uiAudio = go.AddComponent <AudioSource>(); Debug.Log(DebugUtilities.AddTimestampPrefix("UserInterface.Awake()"), this); }
public static void SetActiveTurretController(TurretController turretController, bool inheritControlStates) { if (s_instance == null) { return; } if (s_instance.m_activeTurretController != null) { if (inheritControlStates && turretController != null) { turretController.SetCanControl(s_instance.m_activeTurretController.CanControl); turretController.SetCanFire(s_instance.m_activeTurretController.CanFire); } foreach (TurretController tc in s_instance.m_activeTurretController.GetComponents <TurretController>()) { tc.SetActive(false); } } s_instance.m_activeTurretController = turretController; if (turretController != null) { Debug.Log(DebugUtilities.AddTimestampPrefix("Active TurretController is now " + turretController.GetType())); foreach (TurretController tc in turretController.gameObject.GetComponents <TurretController>()) { tc.SetActive(tc == turretController); } } else { Debug.Log(DebugUtilities.AddTimestampPrefix("Active TurretController was cleared")); } }
public void InitializeScenarioInternal(ScenarioPreset preset) { if (preset == null) { return; } if (m_preset != null) { if (GameManager.ActivePlayerController != null) { Destroy(GameManager.ActivePlayerController.gameObject); } } m_preset = preset; m_currentRound = null; SetupGameArea(); if (m_entities == null) { m_entities = new Dictionary <int, Entity>(); } else { // TODO: Cache entities instead of outright destroying them foreach (Entity e in m_entities.Values) { Destroy(e.gameObject); } m_entities.Clear(); } m_playerScore = 0; m_playerShotsFired = 0; UserInterface.SetScore(m_playerScore); SetHighScore(LoadHighScore()); if (m_preset.m_playerPrefab != null) { Vector3 position = Environment.PlayerSpawn != null ? Environment.PlayerSpawn.position : Vector3.zero; Quaternion rotation = Environment.PlayerSpawn != null ? Environment.PlayerSpawn.rotation : Quaternion.identity; GameObject go = Instantiate <GameObject>(m_preset.m_playerPrefab, position, rotation, Environment.EntityRoot); go.name = m_preset.m_playerPrefab.name; TurretController tc; if (GameManager.State == GameState.Game) { tc = go.GetComponent <PlayerController>(); } else { tc = go.GetComponent <AIController>(); } GameManager.SetActiveTurretController(tc, false); tc.SetCanControl(false); } else { Debug.LogError(DebugUtilities.AddTimestampPrefix("ScenarioPreset doesn't define a player prefab!"), m_preset); } }
public static ScenarioWave[] GenerateWaves(int roundIndex, ScenarioPreset preset) { float t = preset.m_waveCountCurve.Evaluate(roundIndex / (preset.m_waveCountRoundMax - 1f)); int waveCount = t < 1f ? Mathf.FloorToInt(Mathf.Lerp(preset.m_waveCountMin, preset.m_waveCountMax, t)) : preset.m_waveCountMax; ScenarioWave wave; ScenarioWave[] waves = new ScenarioWave[waveCount]; float[] wavePickRolls = new float[waveCount]; float[] waveEnemyCountRolls = new float[waveCount]; t = preset.m_waveIntervalCurve.Evaluate(roundIndex / (preset.m_waveIntervalRoundMax - 1f)); float waveInterval = Mathf.Lerp(preset.m_waveIntervalMin, preset.m_waveIntervalMax, t); Debug.Log(DebugUtilities.AddTimestampPrefix("Round " + (roundIndex + 1) + " will have " + waveCount + " waves in it, interval=" + waveInterval)); float enemyWaveCountWeightTotal, enemySpeed; int i, p, waveCountToSpawnEnemyIn, enemyCountTotal, remainingEnemyCount; List <int> pickedWaveIndices; int[] pickedWaveEnemyCounts; ScenarioPreset.Enemy enemyPreset; ScenarioWave.Enemy[] waveEnemies; // TODO: Optimize this, it's stupid now for (int e = 0; e < preset.m_enemyPresets.Length; e++) { enemyPreset = preset.m_enemyPresets[e]; if (roundIndex < enemyPreset.m_firstRoundToSpawn - 1) { continue; } // Determine how many enemies to spawn in total if (roundIndex == enemyPreset.m_firstRoundToSpawn - 1) { enemyCountTotal = enemyPreset.m_spawnCountMin; } else { t = enemyPreset.m_spawnCountCurve.Evaluate((roundIndex - (enemyPreset.m_firstRoundToSpawn - 1f)) / (enemyPreset.m_spawnCountRoundMax - enemyPreset.m_firstRoundToSpawn)); enemyCountTotal = t < 1f ? Mathf.FloorToInt(Mathf.Lerp(enemyPreset.m_spawnCountMin, enemyPreset.m_spawnCountMax, t)) : enemyPreset.m_spawnCountMax; } Debug.Log(DebugUtilities.AddTimestampPrefix("Round " + (roundIndex + 1) + " will spawn a total of " + enemyCountTotal + " instances of enemy " + enemyPreset.m_enemyPrefab.name)); // Roll for each wave after first to determine which ones to pick and the weight value for the enemy count for (i = 0; i < waveCount; i++) { // First wave is always picked wavePickRolls[i] = i == 0 ? 2f : Random.value * enemyPreset.m_waveProbabilityCurve.Evaluate((float)i / waveCount); waveEnemyCountRolls[i] = Random.value; //Debug.Log(DebugUtilities.AddTimestampPrefix("Round " + (roundIndex + 1) + " Wave[" + i + "] pick roll: " + wavePickRolls[i] + ", enemy count roll: " + waveEnemyCountRolls[i])); } waveCountToSpawnEnemyIn = Mathf.FloorToInt(enemyPreset.m_waveCountMultiplier * waveCount); pickedWaveIndices = new List <int>(waveCountToSpawnEnemyIn); pickedWaveEnemyCounts = new int[waveCountToSpawnEnemyIn]; enemyWaveCountWeightTotal = 0f; // Gather the highest rolled indices of the picked waves for (i = 0; i < waveCountToSpawnEnemyIn; i++) { pickedWaveIndices.Add(0); t = 0f; for (p = 0; p < waveCount; p++) { if (wavePickRolls[p] > t) { t = wavePickRolls[p]; pickedWaveIndices[i] = p; } } //Debug.Log(DebugUtilities.AddTimestampPrefix("Wave[" + pickedWaveIndices[i] + "] picked, roll: " + wavePickRolls[pickedWaveIndices[i]])); // Add to enemy count weight total so the amount can be distributed properly enemyWaveCountWeightTotal += waveEnemyCountRolls[pickedWaveIndices[i]]; // Strike down the best pick from the rolls so it won't be considered again wavePickRolls[pickedWaveIndices[i]] = -1f; } pickedWaveIndices.Sort(SortWaves); remainingEnemyCount = enemyCountTotal; Debug.Log(DebugUtilities.AddTimestampPrefix("Round " + (roundIndex + 1) + " will spawn these enemies in " + waveCountToSpawnEnemyIn + " waves")); // Calculate how many enemies to spawn in each chosen wave for (i = 0; i < waveCountToSpawnEnemyIn; i++) { p = pickedWaveIndices[i]; // Get the wave in question or create it if (waves[p] == null) { wave = new ScenarioWave(i, p * waveInterval); waves[p] = wave; } else { wave = waves[p]; } // Last wave should have all the remaining enemies, otherwise floor to int from roll values if (i == waveCountToSpawnEnemyIn - 1) { pickedWaveEnemyCounts[i] = remainingEnemyCount; } else { pickedWaveEnemyCounts[i] = Mathf.Max(Mathf.FloorToInt(enemyCountTotal * waveEnemyCountRolls[p] / enemyWaveCountWeightTotal), 1); remainingEnemyCount -= pickedWaveEnemyCounts[i]; } t = Mathf.Pow(enemyPreset.m_speedMultiplierGain, roundIndex); if (enemyPreset.m_speedMultiplierMax > 1f) { t = Mathf.Clamp(t, 1f, enemyPreset.m_speedMultiplierMax); } Debug.Log(DebugUtilities.AddTimestampPrefix("Wave[" + p + "] will spawn " + pickedWaveEnemyCounts[i] + " enemies of type " + enemyPreset.m_enemyPrefab.name + " with speed multiplier of " + t + " at time " + wave.WaveTime)); // Generate the enemies in this wave waveEnemies = new ScenarioWave.Enemy[pickedWaveEnemyCounts[i]]; for (p = 0; p < pickedWaveEnemyCounts[i]; p++) { // Calculate the speed for each enemy individually enemySpeed = t * Mathf.Lerp(enemyPreset.m_speedMin, enemyPreset.m_speedMax, enemyPreset.m_speedCurve.Evaluate(Random.value)); waveEnemies[p] = new ScenarioWave.Enemy(enemyPreset.m_enemyPrefab, enemyPreset.m_modelPrefab, enemySpeed); } wave.AddEnemies(waveEnemies); } } return(waves); }