I have a singleton implemented with static instance variable approach.
When I set one of it’s member variable of enum
type, the editor lags and I have to force quit it everytime that happens.
public class SharedData {
private static SharedData m_onlyInstance = null;
public int a,b,c;
public ESampleType eType = ESampletype.Default;
public static SharedData Instance {
get {
if (m_onlyInstance == null) {
m_onlyInstance = new SharedData();
}
return m_onlyInstance;
}
}
//other codes...
}
public class TestClass : MonoBehaviour {
[SerializeField]
Slider m_sliderTest;
public void onStartBtn(){
Debug.Log("---START---");
SharedData data = SharedData.Instance;
ESampleType eType = (ESampleType)(int)m_sliderTest.value;
data.a = 1;
data.eType = eType; //***when I commented this line, the lag disappear.
data.b = 2;
data.c = 3;
Debug.Log("---END---");
}
//other codes...
}
Also, the log "---START---"
and "---END---"
won’t show up when the problematic line is there. It seems doesn’t compile well. It’s very weird!
Is this a limitation on C#? Please help me what’s happening here. I need to fix this problem.
My Unity editor version is 5.4.1.40776
.