您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
56 行
1.6 KiB
56 行
1.6 KiB
using System.Diagnostics;
|
|
using UnityEngine;
|
|
|
|
namespace Unity.UIWidgets.debugger {
|
|
public class InspectorObjectGroupManager : Singleton<InspectorObjectGroupManager> {
|
|
[SerializeField] int m_NextId = 0;
|
|
|
|
public string nextGroupName(string name) {
|
|
return $"pid{Process.GetCurrentProcess().Id}_{name}_{this.m_NextId++}";
|
|
}
|
|
}
|
|
|
|
public class Singleton<T> : ScriptableObject where T : ScriptableObject {
|
|
static T m_Instance;
|
|
static bool m_CreateNonSingletonInstance;
|
|
bool m_IsNonSingletonInstance;
|
|
|
|
public static T Instance {
|
|
get {
|
|
if (m_Instance == null) {
|
|
m_Instance = CreateInstance<T>();
|
|
}
|
|
|
|
return m_Instance;
|
|
}
|
|
}
|
|
|
|
|
|
void OnEnable() {
|
|
if (m_CreateNonSingletonInstance) {
|
|
this.m_IsNonSingletonInstance = true;
|
|
this.Initialize();
|
|
}
|
|
else if (this.m_IsNonSingletonInstance) {
|
|
DestroyImmediate((Object) this);
|
|
}
|
|
else if (m_Instance == null) {
|
|
m_Instance = this as T;
|
|
this.Initialize();
|
|
}
|
|
else {
|
|
DestroyImmediate((Object) this);
|
|
}
|
|
}
|
|
|
|
protected virtual void Initialize() {
|
|
}
|
|
|
|
public static T Create() {
|
|
m_CreateNonSingletonInstance = true;
|
|
var instance = CreateInstance<T>();
|
|
m_CreateNonSingletonInstance = false;
|
|
return (T) instance;
|
|
}
|
|
}
|
|
}
|