Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gadig
Birb
Commits
7fdd5fc8
Commit
7fdd5fc8
authored
Feb 02, 2017
by
Tanner Grehawick
Browse files
add SingletonBehaviour class for managers, etc
parent
4a7f819a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Assets/Scripts/Util.meta
0 → 100644
View file @
7fdd5fc8
fileFormatVersion: 2
guid: c7d6923973dc24861b57ac5a01bebc03
folderAsset: yes
timeCreated: 1486083347
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
Assets/Scripts/Util/SingletonBehaviour.cs
0 → 100644
View file @
7fdd5fc8
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
;
}
}
}
Assets/Scripts/Util/SingletonBehaviour.cs.meta
0 → 100644
View file @
7fdd5fc8
fileFormatVersion: 2
guid: e4696889bee8b4b2c8a45d9b3b6eb2dd
timeCreated: 1486083348
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment