Unity code :
Code: Select all
using UnityEngine;
using System;
using System.Collections;
using SmartFoxClientAPI;
using SmartFoxClientAPI.Data;
using SmartFoxClientAPI.Util;
public class LoginGUI : MonoBehaviour {
private SmartFoxClient smartFox;
//private bool shuttingDown = false;
private string serverIP = "127.0.0.1";
private string serverPort = "9339";
public string zone = "alien8";
public bool debug = true;
void Awake() {
Application.runInBackground = true;
if ( SmartFox.IsInitialized() ) {
smartFox = SmartFox.Connection;
} else {
try {
smartFox = new SmartFoxClient(debug);
smartFox.runInQueueMode = true;
} catch ( Exception e ) {
//loginErrorMessage = e.ToString();
}
}
// Register callback delegate
SFSEvent.onConnection += OnConnection;
SFSEvent.onConnectionLost += OnConnectionLost;
SFSEvent.onRoomListUpdate += OnRoomList;
SFSEvent.onDebugMessage += OnDebugMessage;
}
void FixedUpdate() {
smartFox.ProcessEventQueue();
}
void OnGUI() {
smartFox.Connect(serverIP, Convert.ToInt32(serverPort));
if (smartFox.IsConnected()) {
smartFox.SendXtMessage("alien8", "loginRequest", null, SmartFoxClient.XTMSG_TYPE_STR);
} else {
GUI.Label(new Rect(10, 150, 100, 100), "Waiting for connection");
//GUI.Label(new Rect(10, 218, 100, 100), loginErrorMessage);
}
}
public void OnExtensionResponse(object data, string type) {
Debug.Log("hi");
}
/************
* Helper methods
************/
private void UnregisterSFSSceneCallbacks() {
// This should be called when switching scenes, so callbacks from the backend do not trigger code in this scene
SFSEvent.onConnection -= OnConnection;
SFSEvent.onConnectionLost -= OnConnectionLost;
SFSEvent.onRoomListUpdate -= OnRoomList;
SFSEvent.onDebugMessage -= OnDebugMessage;
}
/************
* Callbacks from the SFS API
************/
void OnConnection(bool success, string error) {
if ( success ) {
SmartFox.Connection = smartFox;
} else {
//loginErrorMessage = error;
}
}
void OnConnectionLost() {
//loginErrorMessage = "Connection lost / no connection to server";
}
public void OnDebugMessage(string message) {
Debug.Log("[SFS DEBUG] " + message);
}
void OnRoomList(Hashtable roomList) {
// When room list is updated we are ready to move on to the island
UnregisterSFSSceneCallbacks();
Debug.Log("go to main screen");
}
}
SFS Extension :
Code: Select all
function init()
{
}
function destroy()
{
trace("Extension destroyed")
}
function handleRequest(cmd, params, user, fromRoom)
{
var response = new Object()
response._cmd = "logOK"
_server.sendResponse(response, -1, null, chan)
}
function handleInternalEvent(evt)
{
Can anyone help me out with this. I just want to build a simple hello world setup using my custom .as file as an extension.