Commit 7fdd5fc8 authored by Tanner Grehawick's avatar Tanner Grehawick
Browse files

add SingletonBehaviour class for managers, etc

parent 4a7f819a
fileFormatVersion: 2
guid: c7d6923973dc24861b57ac5a01bebc03
folderAsset: yes
timeCreated: 1486083347
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
// singleton behaviour
// if your script will have a single instance that needs to be accessed by other scripts,
// it should subclass SingletonBehaviour
// primarily used for Manager scripts
public abstract class SingletonBehaviour<T> : MonoBehaviour where T : SingletonBehaviour<T> {
private static T _instance;
public static T instance {
get {
if (_instance == null) {
_instance = Object.FindObjectOfType<T>();
if (_instance == null) {
Debug.LogErrorFormat("Missing instance of {0} in scene.", typeof(T).Name);
}
}
return _instance;
}
}
}
fileFormatVersion: 2
guid: e4696889bee8b4b2c8a45d9b3b6eb2dd
timeCreated: 1486083348
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment