Skip to content

Instantly share code, notes, and snippets.

@ZeredaGames
Last active February 27, 2019 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZeredaGames/cf36af5f69ca337112f410bd69f87a06 to your computer and use it in GitHub Desktop.
Save ZeredaGames/cf36af5f69ca337112f410bd69f87a06 to your computer and use it in GitHub Desktop.
A MonoBehavior Music list for in the scene. Used in our example.
#region using
using UnityEngine;
//#if UNITY_EDITOR
//using UnityEditor;
//#endif
//using UnityEngine.UI;
//using UnityEngine.SceneManagement;
//using System;
//using System.Collections;
using System.Collections.Generic;
#endregion
#region Script
namespace ZeredaGamesEngine.Core.MusicListsExamples.Example3
{
#region Attributes
//[RequireComponent (typeof())]
//[System.Serializable]
#endregion
public class Example : MonoBehaviour
{
#region Variables
public bool DebugMode = false;
public List<AudioClip> PlayList = new List<AudioClip>();
static MusicAssetList asset = null;
#endregion
#region Unity Methods
///<summary> Awake is called when the script instance is being loaded.</summary>
void Awake () {
DebugMode = GetDebugMode;
asset = (MusicAssetList)Resources.Load("Music/GeneralMusicList");
PlayList = asset.PlayList;
if (DebugMode){
if (asset == null)
{
Debug.LogError(string.Format("[DEBUGMODE]Storage1 missing in database.;"));
}
if (PlayList==null) {
Debug.LogError(string.Format("[DEBUGMODE]Playlist Empty in resources;"));
}
Debug.Log(string.Format("[DEBUGMODE]Awake ().Complete;"));
}
}
///<summary> Start is called just before any of the Update methods is called the first time.</summary>
void Start () {
if (DebugMode){
Debug.Log(string.Format("[DEBUGMODE]Start ().Complete;"));
}
}
///<summary> Update is called every frame, if the MonoBehaviour is enabled.</summary>
void Update () {
if(DebugMode){
Debug.Log(string.Format("[DEBUGMODE]Update ().Hits;"));
}
}
#endregion
#region ZeredaGames Methods
///<summary> Can be used for starting this instance.</summary>
//[MenuItem ("Editors/ZeredaGamesEngine/Example ")]
public static void StaticInit()
{
instance.AwakeSingleton ();
if(instance.DebugMode){
Debug.Log(string.Format("[DEBUGMODE]StaticInit ().Complete;"));
}
}
public void Init()
{
StaticInit();
if(DebugMode){
Debug.Log(string.Format("[DEBUGMODE]Public Init ().Complete;"));
}
//Start writting here
}
public bool GetDebugMode {
get {
string message = PlayerPrefs.GetString ("DebugMode");
if (message == "true") {
DebugMode = true;
return DebugMode;
} else {
DebugMode = false;
return DebugMode;
}
Debug.Log(string.Format("[DEBUGMODE]DebugMode enabled = {0};", DebugMode));
}
}
#region Internal Singleton
private static Example instance;
public bool SetDontDestroyOnLoad = false;
public Example Instance {
get {
if (instance == null) {//in case not awake yet
instance = FindObjectOfType<Example> ();
}
if(DebugMode){
check1=false;
check1 = Equals(instance,this.gameObject);
Debug.Log(string.Format("[DEBUGMODE]Singleton set. {0} found; {0} = {1}?: {2};",this.gameObject,instance,check1));
}
return instance;
}
}
static bool check1 = false;
void AwakeSingleton ()
{
check1=false;
// if the singleton hasn't been initialized yet
if (SetDontDestroyOnLoad) {
if (instance != null && instance != this) {
if(DebugMode)
Debug.LogException (new System.Exception(string.Format("[DEBUGMODE]Duplicate singleton {0} created; destroying it now",this.gameObject)));
Destroy (this.gameObject);
}
if (instance != this) {
instance = this;
if(DebugMode){
check1 = Equals(instance,this.gameObject);
Debug.Log(string.Format("[DEBUGMODE]Singleton set. {0} found; {0} = {1}?: {2};",this.gameObject,instance,check1));
}
DontDestroyOnLoad (this.gameObject);
}
} else {
instance = this;
}
}
#endregion
#region Constuctors
public Example ()
{
DebugMode=false;
if(DebugMode){
Debug.Log(string.Format("[DEBUGMODE]Example Instance A."));
}
}
public Example (bool debugMode)
{
DebugMode=debugMode;
if(DebugMode){
Debug.Log(string.Format("[DEBUGMODE]Example Instance B."));
}
}
#endregion
#endregion
}
}
#endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment