Open-sourced some code
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Startups {
|
||||
public class ConfigHandler : MonoBehaviour {
|
||||
void OnDestroy() {
|
||||
ConfigurationManager.Instance.CleanUp();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
//Must include Spriter Namespace
|
||||
using SpriterDotNetUnity;
|
||||
|
||||
enum animationMode
|
||||
{
|
||||
lookUp,
|
||||
lookDown,
|
||||
move,
|
||||
straightJump,
|
||||
rollingJump,
|
||||
}
|
||||
|
||||
public class EmberAnimationCycle : MonoBehaviour
|
||||
{
|
||||
/*
|
||||
* Instead of putting the script on Spriter's automatically generated prefab, which will cause it to be unset every
|
||||
* time Evan tweaks the damn animations, we put the control scripts on a seperate gameobject which becomes a parent
|
||||
* of the Spriter prefab and take a reference to the Spriter object so we can manipulate it.
|
||||
*/
|
||||
public GameObject Ember;
|
||||
|
||||
// This is the actual thing we use to animate the character.
|
||||
UnityAnimator anim;
|
||||
|
||||
void Start()
|
||||
{
|
||||
}
|
||||
|
||||
bool slash = false;
|
||||
animationMode mode = animationMode.lookUp;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Ember == null)
|
||||
{
|
||||
foreach (Transform child in transform)
|
||||
{
|
||||
if (child.name == "Ember") { Ember = child.gameObject; break;}
|
||||
}
|
||||
}
|
||||
|
||||
if (anim == null)
|
||||
{
|
||||
anim = Ember.GetComponent<SpriterDotNetBehaviour>().Animator;
|
||||
//This event is fired whenever an animation ends.
|
||||
anim.AnimationFinished += animationTransitions;
|
||||
}
|
||||
|
||||
if (Input.anyKeyDown)
|
||||
{
|
||||
//Advance the animation.
|
||||
if (anim.CurrentAnimation.Name == "Statue") anim.Play("Statue to Idle");
|
||||
else if (anim.CurrentAnimation.Name == "Idle")
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case animationMode.move:
|
||||
anim.Play("Idle to Walk");
|
||||
mode = animationMode.straightJump;
|
||||
break;
|
||||
case animationMode.straightJump:
|
||||
anim.Play("Begin Straight Jump");
|
||||
mode = animationMode.rollingJump;
|
||||
break;
|
||||
case animationMode.rollingJump:
|
||||
anim.Play("Begin Rolling Jump");
|
||||
mode = animationMode.lookUp;
|
||||
break;
|
||||
case animationMode.lookUp:
|
||||
if (!slash)
|
||||
{
|
||||
anim.Play("Grounded Forward Slash");
|
||||
slash = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
slash = false;
|
||||
anim.Play("Idle to Lookup");
|
||||
mode = animationMode.lookDown;
|
||||
}
|
||||
break;
|
||||
case animationMode.lookDown:
|
||||
anim.Play("Idle to Crouch");
|
||||
mode = animationMode.move;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (anim.CurrentAnimation.Name == "Walk") anim.Play("Run");
|
||||
else if (anim.CurrentAnimation.Name == "Run") anim.Play("Idle");
|
||||
else if (anim.CurrentAnimation.Name == "Straight Jump Rising")
|
||||
{
|
||||
if (!slash)
|
||||
{
|
||||
anim.Play("Airborn Upward Slash");
|
||||
slash = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
anim.Play("Straight Jump Crest");
|
||||
slash = false;
|
||||
}
|
||||
}
|
||||
else if (anim.CurrentAnimation.Name == "Straight Jump Falling"
|
||||
|| anim.CurrentAnimation.Name == "Rolling Jump")
|
||||
{
|
||||
if (!slash)
|
||||
{
|
||||
if (anim.CurrentAnimation.Name == "Straight Jump Falling") anim.Play("Airborn Forward Slash");
|
||||
else anim.Play("Airborn Downward Slash");
|
||||
slash = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
anim.Play("Straight Jump Landing");
|
||||
slash = false;
|
||||
}
|
||||
}
|
||||
else if (anim.CurrentAnimation.Name == "Crouch") anim.Play("Crouch to Idle");
|
||||
else if (anim.CurrentAnimation.Name == "Lookup")
|
||||
{
|
||||
if (!slash)
|
||||
{
|
||||
anim.Play("Grounded Upward Slash");
|
||||
slash = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
anim.Play("Lookup to Idle");
|
||||
slash = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void animationTransitions(string name)
|
||||
{
|
||||
//We check to see if it's one of our transition animations and if so advance to the animation
|
||||
// we are transitioning to.
|
||||
if (name == "Statue to Idle") anim.Play("Idle");
|
||||
else if (name == "Idle to Walk") anim.Play("Walk");
|
||||
else if (name == "Begin Straight Jump") anim.Play("Straight Jump Rising");
|
||||
else if (name == "Straight Jump Crest") anim.Play("Straight Jump Falling");
|
||||
else if (name == "Begin Rolling Jump") anim.Play("Rolling Jump");
|
||||
else if (name == "Straight Jump Landing") anim.Play("Idle");
|
||||
else if (name == "Idle to Crouch") anim.Play("Crouch");
|
||||
else if (name == "Crouch to Idle") anim.Play("Idle");
|
||||
else if (name == "Idle to Lookup") anim.Play("Lookup");
|
||||
else if (name == "Lookup to Idle") anim.Play("Idle");
|
||||
else if (name == "Grounded Forward Slash") anim.Play("Idle");
|
||||
else if (name == "Grounded Upward Slash") anim.Play("Lookup");
|
||||
else if (name == "Airborn Upward Slash") anim.Play("Straight Jump Rising");
|
||||
else if (name == "Airborn Forward Slash") anim.Play("Straight Jump Falling");
|
||||
else if (name == "Airborn Downward Slash") anim.Play("Rolling Jump");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user