Files
tysdk-intergration/sdk-intergration/LocalPackages/PlayFabSDK/Shared/Internal/SingletonMonoBehaviour.cs
tech aa5ce1ff5a [U] add PlayFab SDK and SNS login improvements
- Add PlayFabSDK as local package dependency
- Add PlayFabTool.cs for PlayFab API integration
- Implement LoginBySns method in TYSdkFacade
- Add Android SNS login support in SDKManager and UnityBridgeFunc
- Add Build Android With Debug menu option
- Improve exception handling and timeout management

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-29 16:12:17 +08:00

59 lines
1.5 KiB
C#

using UnityEngine;
namespace PlayFab.Internal
{
//public to be accessible by Unity engine
public class SingletonMonoBehaviour<T> : MonoBehaviour where T : SingletonMonoBehaviour<T>
{
private static T _instance;
public static T instance
{
get
{
CreateInstance();
return _instance;
}
}
public static void CreateInstance()
{
if (_instance == null)
{
//find existing instance
_instance = FindObjectOfType<T>();
if (_instance == null)
{
//create new instance
var go = new GameObject(typeof(T).Name);
_instance = go.AddComponent<T>();
}
//initialize instance if necessary
if (!_instance.initialized)
{
_instance.Initialize();
_instance.initialized = true;
}
}
}
public virtual void Awake ()
{
if (Application.isPlaying)
{
DontDestroyOnLoad(this);
}
//check if instance already exists when reloading original scene
if (_instance != null)
{
DestroyImmediate (gameObject);
}
}
protected bool initialized;
protected virtual void Initialize() { }
}
}