Code: Select all
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using Sfs2X;
using Sfs2X.Util;
using Sfs2X.Logging;
using Sfs2X.Core;
using System;
public class Connector : MonoBehaviour {
private string defaultHost = "127.0.0.1";
private int defaultTcpPort = 9933;
private int defaultWsPort = 8888;
private SmartFox sfs;
public Text StatusTextBox;
// Use this for initialization
void Start () {
StatusTextBox.text = "Connecting....";
sfs = new SmartFox();
// Set ThreadSafeMode explicitly, or Windows Store builds will get a wrong default value (false)
sfs.ThreadSafeMode = true;
sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
sfs.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
sfs.AddLogListener(LogLevel.INFO, OnInfoMessage);
sfs.AddLogListener(LogLevel.WARN, OnWarnMessage);
sfs.AddLogListener(LogLevel.ERROR, OnErrorMessage);
ConfigData cfg = new ConfigData();
cfg.Host = defaultHost;
cfg.Port = defaultTcpPort;
cfg.Zone = "BasicExamples";
cfg.Debug = true;
// Connect to SFS2X
sfs.Connect(cfg);
}
private void OnErrorMessage(BaseEvent evt)
{
throw new NotImplementedException();
}
private void OnWarnMessage(BaseEvent evt)
{
throw new NotImplementedException();
}
private void OnInfoMessage(BaseEvent evt)
{
throw new NotImplementedException();
}
private void OnConnectionLost(BaseEvent evt)
{
StatusTextBox.text = "Connection Lost";
}
private void OnConnection(BaseEvent evt)
{
if ((bool)evt.Params["success"])
{
StatusTextBox.text = "connected";
}
else
{
StatusTextBox.text = "failed";
}
}
// Update is called once per frame
void Update () {
}
}