feat(AdvancedSingleton): Add AdvancedSingleton implementation

This commit is contained in:
EmirHanMamak 2026-03-01 15:18:24 +03:00
parent 193c04a7b3
commit ec165ed197
22 changed files with 1479 additions and 1 deletions

8
Assets/Foldering.meta Normal file
View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 64f61d57caa422c41abc5edf1a7d5458
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4a1493c1ecc61eb408b5dc4d56baa403
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bbbb102195539fb4d96705d631cc1421
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bc98d29e571e4044bab163fcf868b5c1
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: dd0505d1e466ae442b17dddc2f1c2b21
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: c9f34d40a890dd54bbb02526e5f11087
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3ded0b1c30392a24e9c2a7ca3f85c867
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,54 @@
using System;
using UnityEngine;
namespace Patterns_And_Principles.Patterns.The_Singleton_Pattern.AdvanceSingleton.Script
{
public class AdvancedSingleton : MonoBehaviour
{
private static AdvancedSingleton _instance;
public static AdvancedSingleton Instance
{
get
{
if (_instance == null)
{
SetupInstance();
}
return _instance;
}
}
public int Gem = 0;
private void Awake()
{
if (_instance != null && _instance != this)
{
Destroy(gameObject);
return;
}
_instance = this;
DontDestroyOnLoad(gameObject); // Sahne geçişlerinde yok olmaz
}
private static void SetupInstance()
{
_instance = FindAnyObjectByType<AdvancedSingleton>();
if (_instance == null)
{
GameObject gameObject = new GameObject(); // Yeni gameobject oluştur.
gameObject.name = "AdvancedSingleton";
_instance = gameObject.AddComponent<AdvancedSingleton>();
DontDestroyOnLoad(gameObject);
}
}
public void AddGem(int amount)
{
Gem += amount;
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e4066bc123f2480789fbed170865976d
timeCreated: 1772366365

View file

@ -0,0 +1,23 @@
using System;
using UnityEngine;
using UnityEngine.UI;
namespace Patterns_And_Principles.Patterns.The_Singleton_Pattern.AdvanceSingleton.Script
{
public class TestScript : MonoBehaviour
{
[SerializeField]
private Button _testButton;
private void Awake()
{
_testButton.onClick.AddListener(OnTestButtonClick);
}
private void OnTestButtonClick()
{
AdvancedSingleton.Instance.AddGem(100);
Debug.Log($"AdvancedSingleton Gem : {AdvancedSingleton.Instance.Gem}");
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e7639675720147c79696b195aeda1ab7
timeCreated: 1772366933

View file

@ -12,7 +12,7 @@ PlayerSettings:
targetDevice: 2
useOnDemandResources: 0
accelerometerFrequency: 60
companyName: DefaultCompany
companyName: MamakGames
productName: Programming Design Patterns And Principles
defaultCursor: {fileID: 0}
cursorHotspot: {x: 0, y: 0}

View file

@ -27,8 +27,17 @@ EditorUserSettings:
value: 06070c56510d5859095f592646250a44144e197f2a71243378281c6ae1b53060
flags: 0
RecentlyUsedSceneGuid-6:
value: 53010c515407590f545a092416210d4446151c727e7124672c7f1f32e7e36d6c
flags: 0
RecentlyUsedSceneGuid-7:
value: 5b085703000c580b5e580d7b43770e44154f4128782a74622c7b1860b4b1313e
flags: 0
RecentlyUsedSceneGuid-8:
value: 525051045457085f09080f2148730b4414154c7d742b7e687e7f1e60e3b26439
flags: 0
RecentlyUsedSceneGuid-9:
value: 0008525551515d0b0c56557214270a4414151a7a7e7d7466287c1b62b3b06c6f
flags: 0
lightmappingBakingProfile:
value: 51
flags: 0