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 ca0f8c7

Browse files
Merge pull request #8 from NoSLoofah/master
Add readme and test script for scene singleton
2 parents 040576c + 70bbeab commit ca0f8c7

File tree

8 files changed

+68
-0
lines changed

8 files changed

+68
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Hello.
2+
3+
Here is the supplementary content for the Singleton Pattern tutorial: Scene Singleton Pattern.
4+
5+
The Scene Singleton Pattern ensures that there is only one instance of a class in a given scene, but it does not require that the instance continues to exist after a scene switch. After switching scenes, the instance you access will be a new one, unique to the current scene.
6+
7+
This pattern is very useful when you need to manage specific resources or functionality within a single scene, but you don't want these resources or functionality to persist during scene switches.
8+
9+
To use the Scene Singleton Pattern in the current scene, you just need to call the Instance property of the scene singleton class, following the example of SceneTest.cs.
10+
11+
Hope you enjoy it.
12+
13+
Thanks.

‎Assets/Scripts/SceneSingleton/Readme.txt.meta‎

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using UnityEngine.SceneManagement;
5+
6+
public class SceneGameManager : SceneSingleton<SceneGameManager>
7+
{
8+
[SerializeField]
9+
protected string m_PlayerName = "NoSLoofah";
10+
11+
public string GetPlayerName()
12+
{
13+
return m_PlayerName;
14+
}
15+
}

‎Assets/Scripts/SceneSingleton/SceneGameManager.cs.meta‎

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.
File renamed without changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
public class SceneTest : MonoBehaviour
6+
{
7+
void Start()
8+
{
9+
Debug.Log(SceneGameManager.Instance.GetPlayerName());
10+
}
11+
}

‎Assets/Scripts/SceneSingleton/SceneTest.cs.meta‎

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
(0)

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