Open-sourced some code

This commit is contained in:
2019-03-08 09:54:14 +11:00
commit 645272872c
142 changed files with 3028 additions and 0 deletions
+73
View File
@@ -0,0 +1,73 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using SpriterDotNetUnity;
//DOCS: this is intended for Ember's foot step sounds
public class PlayerAudio : MonoBehaviour {
//public members
public AudioClip[] leftFootsteps;
public AudioClip[] rightFootsteps;
public AudioClip jumpSound;
public AudioClip landSound;
//internal members
GameObject spriteObject;
UnityAnimator animator;
AudioSource audioSource;
void Start() {
audioSource = GetComponent<AudioSource>();
}
void Update() {
//spriter object is handled as an animation
HandleAnimation();
}
// Update is called once per frame
void HandleAnimation() {
if (spriteObject == null) {
foreach (Transform child in transform) {
if (child.name == "Ember") {
spriteObject = child.gameObject;
break;
}
}
}
if (animator == null && spriteObject != null) {
animator = spriteObject.GetComponent<SpriterDotNetBehaviour>().Animator;
animator.EventTriggered += AudioTriggers;
}
}
void AudioTriggers(string name) {
switch(name) {
case "S: footstep left":
audioSource.PlayOneShot(leftFootsteps[PickASlot(leftFootsteps.Length)]);
break;
case "S: footstep right":
audioSource.PlayOneShot(rightFootsteps[PickASlot(rightFootsteps.Length)]);
break;
case "S: jump":
audioSource.PlayOneShot(jumpSound);
break;
case "S: land":
audioSource.PlayOneShot(landSound);
break;
}
}
int PickASlot(int length) {
for (int i = 0; i < length; i++) {
if (Random.Range(0, 2) == 0) return i;
}
return 0;
}
}
@@ -0,0 +1,32 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Startups {
public class Debugger : MonoBehaviour {
AudioController audioController;
void Start() {
audioController = Object.FindObjectOfType(typeof(AudioController)) as AudioController;
audioController.Load("rockstar", "Audio/Music/EngineTest");
audioController.Load("forest_ambience", "Audio/Music/Forest_Ambience");
audioController.Load("forest_background", "Audio/Music/Forest_Background");
audioController.Play("rockstar", AudioController.Mode.JUMP, 5f, 15);
// StartCoroutine(DebugLoopMusic(10f));
}
IEnumerator DebugLoopMusic(float duration) {
for(;;) {
audioController.PauseFadeOutAll(3f, new List<string> {"forest_background"});
audioController.UnpauseFadeIn("forest_background", 3f, AudioController.Mode.LOOP);
yield return new WaitForSeconds(duration);
audioController.PauseFadeOutAll(3f, new List<string> {"forest_ambience"});
audioController.UnpauseFadeIn("forest_ambience", 3f, AudioController.Mode.LOOP);
yield return new WaitForSeconds(duration);
}
}
}
}
@@ -0,0 +1,29 @@
using UnityEngine;
using System.Collections;
//DOCS: http://wiki.unity3d.com/index.php/FramesPerSecond
namespace Startups {
public class FPSDisplay : MonoBehaviour {
float deltaTime = 0.0f;
void Update() {
deltaTime += (Time.unscaledDeltaTime - deltaTime) * 0.1f;
}
void OnGUI() {
int w = Screen.width, h = Screen.height;
GUIStyle style = new GUIStyle();
Rect rect = new Rect(0, 0, w, h * 2 / 100);
style.alignment = TextAnchor.UpperLeft;
style.fontSize = h * 2 / 100;
style.normal.textColor = new Color (0.0f, 0.0f, 0.5f, 1.0f);
float msec = deltaTime * 1000.0f;
float fps = 1.0f / deltaTime;
string text = string.Format("{0:0.0} ms ({1:0.} fps)", msec, fps);
GUI.Label(rect, text, style);
}
}
}
@@ -0,0 +1,40 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Startups {
public class PauseMenuHandler : MonoBehaviour {
public Canvas pauseMenuCanvas;
public Canvas optionsMenuCanvas;
public Canvas saveMenuCanvas;
PauseManager pauseManager;
void Start() {
pauseManager = PauseManager.Instance;
pauseManager.Paused = false;
pauseManager.PushOnPaused(() => {
pauseMenuCanvas.gameObject.SetActive(true);
Time.timeScale = 0f;
});
pauseManager.PushOnResume(() => {
pauseMenuCanvas.gameObject.SetActive(false);
optionsMenuCanvas.gameObject.SetActive(false);
saveMenuCanvas.gameObject.SetActive(false);
Time.timeScale = 1f;
});
}
void OnDestroy() {
pauseManager.PurgeLists();
}
void Update() {
if (GamePad.GetState().Pressed(CButton.Start)) {
pauseManager.Paused = !pauseManager.Paused;
}
}
}
}
@@ -0,0 +1,37 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
public class SaveHandler : MonoBehaviour {
public GameObject playerObject;
public Dictionary<string, Structures.Pedestal> pedestalDictionary = new Dictionary<string, Structures.Pedestal>();
public bool saveMenuAvailable = false;
public float startTime = 0f;
void Start() {
//create the save file if it doesn't exist
if (SaveFileManager.LoadedSaveSlot == null) {
SaveFileManager.saveSlotFileName = Path.Combine(Application.persistentDataPath, DateTime.Now.ToString("yyyyMMddTHHmmss") + ".sav");
SaveFileManager.LoadedSaveSlot = SaveFileManager.CreateBlankSaveSlot();
// SaveFileManager.SaveData(SaveFileManager.LoadedSaveSlot, SaveFileManager.saveSlotFileName);
}
//initialize the game world with the given save data
startTime = Time.time;
//convert the array into a quick-search dictionary
Structures.Pedestal[] pedestals = GameObject.FindObjectsOfType<Structures.Pedestal>();
foreach(Structures.Pedestal pedestal in pedestals) {
pedestal.SaveHandler = this;
pedestalDictionary[pedestal.name] = pedestal;
}
//place the player on their saved pedestal
playerObject.transform.position = pedestalDictionary[SaveFileManager.LoadedSaveSlot.currentLocation].gameObject.transform.position;
}
}