I have been analysing your code for Unity and have some doubts.
The code for SmartFoxConnection.cs is this one:
Code: Select all
using UnityEngine;
using Sfs2X;
// Statics for holding the connection to the SFS server end
// Can then be queried from the entire game to get the connection
public class SmartFoxConnection : MonoBehaviour
{
private static SmartFoxConnection mInstance;
private static SmartFox smartFox;
public static SmartFox Connection {
get {
if (mInstance == null) {
mInstance = new GameObject("SmartFoxConnection").AddComponent(typeof(SmartFoxConnection)) as SmartFoxConnection;
}
return smartFox;
}
set {
if (mInstance == null) {
mInstance = new GameObject("SmartFoxConnection").AddComponent(typeof(SmartFoxConnection)) as SmartFoxConnection;
}
smartFox = value;
}
}
public static bool IsInitialized {
get {
return (smartFox != null);
}
}
// Handle disconnection automagically
// ** Important for Windows users - can cause crashes otherwise
void OnApplicationQuit() {
if (smartFox.IsConnected) {
smartFox.Disconnect();
}
}
}Second: LoginGUI script is attached to the scene and supposed to be destroyed when switching the scene. Could or should we use DontDestroyOnLoad for keeping this class working in the new scene? I don't know if I'm wrong but, would it be easier than destroyed and creating the class and the listeners every time? I mean, you do keep the connexion trought the static var SmartFoxConnection.Connection, but not the listeners not the GameObject, why don't you keep all with DontDestroyOnLoad?
What I od is
Code: Select all
GameObject connectorGameObject = new GameObject ("Connector Object");
Object.DontDestroyOnLoad (connectorGameObject);
_connector = connectorGameObject.AddComponent<Connector> ();Regards.