Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e902a9f

Browse files
Add Init for existing instance and basic editor mode support
1 parent a61f77a commit e902a9f

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

‎Assets/Scripts/MonoSingleton.cs‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,25 @@ protected virtual void Awake ()
5050
if ( instance == null )
5151
{
5252
instance = this as T;
53-
DontDestroyOnLoad ( gameObject );
53+
54+
if (Application.isPlaying)
55+
{
56+
DontDestroyOnLoad(gameObject);
57+
}
58+
59+
// Init existing instance
60+
Init();
5461
}
5562
else
5663
{
57-
Destroy ( gameObject );
64+
if (Application.isPlaying)
65+
{
66+
Destroy(gameObject);
67+
}
68+
else
69+
{
70+
DestroyImmediate(gameObject);
71+
}
5872
}
5973
}
6074

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /