Skip to content

Instantly share code, notes, and snippets.

@ZeredaGames
Last active February 28, 2019 10:13
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/b89a30507aeac048821cf81cc6fad07c to your computer and use it in GitHub Desktop.
Save ZeredaGames/b89a30507aeac048821cf81cc6fad07c to your computer and use it in GitHub Desktop.
#region Licencing
/*
ZeredaGamesEngine
Author:
Zereda Games
Thamas Bell : thamasbell@hotmail.com (Depricated, but have ownership - Locked out.)
thamasbell@gmail.com (Personal email A)
thamasabell@gmail.com (Personal email B)
thamasbell@zeredagames.vpweb.ca (Preffered for Website Based Questions)
zeredagames@hotmail.com (Preferred for Scriping Based Questions.)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
This permission notice shall be included in all copies or substantial portions of the Software diriving from this software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Extra Unity Menthods:
///<summary> LateUpdate is called every frame, if the Behaviour is enabled.</summary>
void LateUpdate () {
}
///<summary> This function is called every fixed framerate frame, if the MonoBehaviour is enabled.</summary>
void FixedUpdate () {
}
///<summary> OnGUI is called for rendering and handling GUI events.</summary>
void OnGUI () {
}
///<summary> This function is called after a new level was loaded.</summary>
void OnLevelWasLoaded (int level) {
}
///<summary> Sent to all game objects when the player gets or looses focus.</summary>
void OnApplicationFocus (bool focus) {
}
///<summary> Sent to all game objects when the player pauses.</summary>
void OnApplicationPause (bool pause) {
}
///<summary> Sent to all game objects before the application is quit.</summary>
void OnApplicationQuit () {
}
///<summary> This function is called when the object becomes enabled and active.</summary>
void OnEnable () {
}
///<summary> This function is called when the behaviour becomes disabled () or inactive.</summary>
void OnDisable () {
}
///<summary> This function is called when the MonoBehaviour will be destroyed.</summary>
void OnDestroy () {
}
///<summary> OnTriggerEnter is called when the Collider other enters the trigger.</summary>
void OnTriggerEnter (Collider other) {
}
///<summary> OnTriggerExit is called when the Collider other has stopped touching the trigger.</summary>
void OnTriggerExit (Collider other) {
}
///<summary> OnTriggerStay is called once per frame for every Collider other that is touching the trigger.</summary>
void OnTriggerStay (Collider other) {
}
///<summary> OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.</summary>
void OnCollisionEnter (Collision collision) {
}
///<summary> OnCollisionExit is called when this collider/rigidbody has stopped touching another rigidbody/collider.</summary>
void OnCollisionExit (Collision collisionInfo) {
}
///<summary> OnCollisionStay is called once per frame for every collider/rigidbody that is touching rigidbody/collider.</summary>
void OnCollisionStay (Collision collisionInfo) {
}
*/
#endregion
#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
{
#region Attributes
//[RequireComponent (typeof())]
//[System.Serializable]
#endregion
public class #SCRIPTNAME# : MonoBehaviour//, IQuitable
{
#region Variables
///<summary> Sets Defaults in update.</summary>
public static bool setDefaults;
public bool DebugMode = false;
#endregion
#region Unity Methods
///<summary> Awake is called when the script instance is being loaded.</summary>
void Awake () {
DebugMode = GetDebugMode;
if(DebugMode){
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(setDefaults){
OnSetDefaults(setDefaults);
}
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/#SCRIPTNAME# ")]
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
}
///<summary> Enables Set to Defaults.</summary>
public void OnSetDefaults (bool enable) {
setDefaults = enable;
if(setDefaults){
OnSaveData ();
}
if(DebugMode){
Debug.Log(string.Format("[DEBUGMODE]OnSetDefaults ().Complete; SetDefaults = {0}", setDefaults));
}
}
///<summary> Used for saving data in tis script.</summary>
void OnSaveData () {
//Start writting here
if(DebugMode){
Debug.Log(string.Format("[DEBUGMODE]OnSaveData ().Complete;"));
}
}
/// <summary> Quit this application instance.</summary>
public void Quit ()
{
//Start writting here
if(DebugMode){
Debug.Log(string.Format("[DEBUGMODE]Quit ().Complete;"));
}
}
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 #SCRIPTNAME# instance;
public bool DontDestroyOnLoad = false;
public #SCRIPTNAME# Instance {
get {
if (instance == null) {//in case not awake yet
instance = FindObjectOfType<#SCRIPTNAME#> ();
}
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 (DontDestroyOnLoad) {
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 #SCRIPTNAME# ()
{
DebugMode=false;
setDefaults=true;
if(DebugMode){
Debug.Log(string.Format("[DEBUGMODE]#SCRIPTNAME# Instance A."));
}
}
public #SCRIPTNAME# (bool debugMode)
{
DebugMode=debugMode;
setDefaults=true;
if(DebugMode){
Debug.Log(string.Format("[DEBUGMODE]#SCRIPTNAME# Instance B."));
}
}
public #SCRIPTNAME# (bool debugMode, bool setDefaultSettings)
{
DebugMode=debugMode;
setDefaults=setDefaultSettings;
if(DebugMode){
Debug.Log(string.Format("[DEBUGMODE]#SCRIPTNAME# Instance C."));
}
}
#endregion
#endregion
}
}
#endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment