GameJam Progress Day 2

This commit is contained in:
2020-07-13 09:19:57 +02:00
parent 05867d287b
commit 00b63ee77a
52 changed files with 8786 additions and 23 deletions

View File

@@ -32,6 +32,9 @@ public class GameManager : MonoBehaviour
public Vector3[] initialPositions;
public Quaternion[] initialRotations;
public GameObject camera;
public AudioClip tensionTrack;
public AudioClip finalTrack;
public AudioClip finishedTrack;
[Header("Effects")]
public int effectStage = 0;
@@ -55,6 +58,8 @@ public class GameManager : MonoBehaviour
public ColorGrading colorGadingLayer;
private AudioSource audioSource;
private GameSettings settings;
private MusicManager musicManager;
// Start is called before the first frame update
void Awake()
{
@@ -83,6 +88,25 @@ public class GameManager : MonoBehaviour
winLabel.transform.gameObject.SetActive(false);
this.postProcess.TryGetSettings(out this.colorGadingLayer);
//apply global settings
try
{
this.settings = GameObject.Find("/settings").GetComponent<GameSettings>();
this.musicManager = GameObject.Find("/BackgroundMusic").GetComponent<MusicManager>();
if (this.settings.playerMode == 1)
{
this.player2.GetComponent<PlayerController>().aiControlled = true;
}
}
catch (System.Exception)
{
Debug.LogWarning("No settings or music manager object available!");
}
}
// Update is called once per frame
@@ -91,7 +115,7 @@ public class GameManager : MonoBehaviour
if (this.stageNameCountdown <= this.stageSmall)
{
this.stageNameT += 4.0f * Time.deltaTime;
this.stageName.GetComponent<Text>().fontSize = (int)Mathf.Lerp(155, 100, this.stageNameT);
this.stageName.GetComponent<Text>().fontSize = (int)Mathf.Lerp(170, 100, this.stageNameT);
}
if (this.stageNameCountdown <= 0)
@@ -203,17 +227,37 @@ public class GameManager : MonoBehaviour
winLabel.transform.gameObject.SetActive(true);
Time.timeScale = 0.0f;
}
int currentMaxScore = Mathf.Max(this.scorePlayer1, this.scorePlayer2);
if (currentMaxScore == 3)
{
this.musicManager.CrossfadeToTrack(this.tensionTrack, 0.2f);
}
if (currentMaxScore == 4)
{
this.musicManager.CrossfadeToTrack(this.finalTrack);
}
if (this.scorePlayer2 >= maxGoals || this.scorePlayer1 >= maxGoals)
{
this.stageName.GetComponent<Text>().text = "Press R to restart";
this.stageName.GetComponent<Text>().fontSize = 100;
this.musicManager.CrossfadeToTrack(this.finishedTrack, 1.5f);
this.stageName.GetComponent<Text>().text = "Press R to restart \n Esc for main menu";
this.stageName.GetComponent<Text>().fontSize = 80;
if (Input.GetKeyDown(KeyCode.R))
{
Time.timeScale = 1;
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
this.colorGadingLayer.temperature.value = 0.0f;
}
if (Input.GetKeyDown(KeyCode.Escape))
{
Cursor.visible = true;
Time.timeScale = 1;
SceneManager.LoadScene("menu");
this.colorGadingLayer.temperature.value = 0.0f; //Do this persist on scene unload?
}
}
}

View File

@@ -0,0 +1,26 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameSettings : MonoBehaviour
{
public bool backgroundMusic = true;
public int playerMode = 1;
private void Awake()
{
DontDestroyOnLoad(this);
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 774da92ac5ecc93419f73b147bf51fda
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,97 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
[System.Serializable]
public struct MusicMapping
{
public string sceneName;
public AudioClip track;
}
public class MusicManager : MonoBehaviour
{
public bool musicEnabled = true;
public MusicMapping[] musicMap;
public float crossfadeSpeed = 1;
public AudioSource[] audioSources;
public int activeAudioSource = 0;
[Range(0,1)]
public float crossfadeT = 1;
private void Awake()
{
if (GameObject.FindObjectsOfType<MusicManager>().Length != 1)
{
Destroy(this);
}
}
// Start is called before the first frame update
void Start()
{
DontDestroyOnLoad(this);
SceneManager.sceneLoaded += this.OnSceneLoaded;
this.LoadMeppedTrack(SceneManager.GetActiveScene().name);
}
private void Update()
{
this.crossfadeT = Mathf.Clamp( this.crossfadeT += this.activeAudioSource == 0 ? .1f * this.crossfadeSpeed : -.1f * this.crossfadeSpeed, 0, 1);
float val = Mathf.Lerp(0, 1, this.crossfadeT);
this.audioSources[0].volume = val;
this.audioSources[1].volume = 1 - val;
if (this.musicEnabled == false)
{
this.audioSources[0].volume = 0;
this.audioSources[1].volume = 0;
}
}
private void LoadMeppedTrack(string sceneName)
{
foreach (MusicMapping mapping in this.musicMap)
{
if (mapping.sceneName == sceneName)
{
this.CrossfadeToTrack(mapping.track);
Debug.Log("MusicManager: Fading to track " + mapping.track.name);
}
}
}
public bool ToggleMusic()
{
this.musicEnabled = !this.musicEnabled;
return this.musicEnabled;
}
void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
this.LoadMeppedTrack(scene.name);
}
public void CrossfadeToTrack(AudioClip audioClip, float speed)
{
this.crossfadeSpeed = speed;
if (this.audioSources[this.activeAudioSource].clip == audioClip) { return; } //Don't fade if it's the same clip
if (this.activeAudioSource == 0)
{
this.audioSources[1].clip = audioClip;
this.audioSources[1].Play();
this.activeAudioSource = 1;
}
else
{
this.audioSources[0].clip = audioClip;
this.audioSources[0].Play();
this.activeAudioSource = 0;
}
}
public void CrossfadeToTrack(AudioClip audioClip)
{
this.CrossfadeToTrack(audioClip, 1f);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 733cf274021b38242aeb323c102b1e37
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,27 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DebugAudio : MonoBehaviour
{
// Start is called before the first frame update
public MusicManager musicManager;
public AudioClip[] audioClips;
public bool current = true;
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnMouseDown()
{
this.musicManager.CrossfadeToTrack(this.current ? this.audioClips[0] : this.audioClips[1]);
this.current = !this.current;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0f14db97d0c91f44c91ec10eb10bf03c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LoadSceneOnClick : MonoBehaviour
{
public string sceneName;
void OnMouseDown()
{
Debug.Log("Load scene: " + this.sceneName);
SceneManager.LoadScene(this.sceneName, LoadSceneMode.Single);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7a67f998c91f21a4c8f9b7ae2e3f7465
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,22 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class SetPlayerMode : MonoBehaviour
{
public int playerMode;
private GameSettings settings;
// Start is called before the first frame update
void Start()
{
this.settings = GameObject.Find("/settings").GetComponent<GameSettings>();
}
void OnMouseDown()
{
this.settings.playerMode = this.playerMode;
SceneManager.LoadScene("main", LoadSceneMode.Single);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6da432edf830e4a40be944b99c24096b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,32 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ToggleMusic : MonoBehaviour
{
private MusicManager musicManager;
private AudioSource audioSource;
public Material greenMat, redMat;
public Renderer buttonVisuals;
public AudioClip clickSound;
// Start is called before the first frame update
void Start()
{
this.audioSource = GetComponent<AudioSource>();
this.musicManager = GameObject.Find("/BackgroundMusic").GetComponent<MusicManager>();
bool audioState = this.musicManager.musicEnabled;
this.buttonVisuals.material = audioState ? this.greenMat : this.redMat;
}
void OnMouseDown()
{
bool newState = this.musicManager.ToggleMusic();
this.buttonVisuals.material = newState ? this.greenMat : this.redMat;
this.audioSource.pitch = newState ? 1.5f : .75f;
this.audioSource.PlayOneShot(this.clickSound);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 71e919d26e0f05840a23051a286dae56
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: