Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
man-in-the-mirror
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MIM
man-in-the-mirror
Commits
fda84f05
Commit
fda84f05
authored
Mar 23, 2019
by
15박보승
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SingletonBehaviour 추가
parent
e098f997
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
1 deletion
+46
-1
Generals.meta
Assets/Scripts/Generals.meta
+1
-1
SingletonBehaviour.cs
Assets/Scripts/Generals/SingletonBehaviour.cs
+34
-0
SingletonBehaviour.cs.meta
Assets/Scripts/Generals/SingletonBehaviour.cs.meta
+11
-0
No files found.
Assets/Scripts/
Map
.meta
→
Assets/Scripts/
Generals
.meta
View file @
fda84f05
fileFormatVersion: 2
guid:
5bc10e17adc09f34d8d61ffefb655889
guid:
0157d683def24ef4cabaa85d3d4dae38
folderAsset: yes
DefaultImporter:
externalObjects: {}
...
...
Assets/Scripts/Generals/SingletonBehaviour.cs
0 → 100644
View file @
fda84f05
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
public
class
SingletonBehaviour
<
T
>
:
MonoBehaviour
where
T
:
MonoBehaviour
{
private
static
T
_inst
=
null
;
public
static
T
inst
{
get
{
if
(
_inst
==
null
)
{
if
(
FindObjectsOfType
<
T
>().
Length
>
1
)
Debug
.
LogError
(
"More than one"
);
else
if
(
FindObjectOfType
<
T
>()
!=
null
)
_inst
=
FindObjectOfType
<
T
>();
else
{
GameObject
go
=
new
GameObject
();
go
.
name
=
typeof
(
T
).
Name
;
_inst
=
go
.
AddComponent
<
T
>();
}
}
return
_inst
;
}
}
public
void
SetStatic
()
{
if
(
_inst
!=
null
)
DontDestroyOnLoad
(
_inst
.
gameObject
);
}
}
Assets/Scripts/Generals/SingletonBehaviour.cs.meta
0 → 100644
View file @
fda84f05
fileFormatVersion: 2
guid: 0f664c2cd668e604ca073ee9f5635893
MonoImporter:
externalObjects: {}
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