Code:
Code: Select all
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Text;
using SmartFoxClientAPI;
using SmartFoxClientAPI.Data;
public class NewConnect : MonoBehaviour {
private SmartFoxClient smartFox;
private string statusMessage = "";
private string zone = "Sorrow";
private string username = "";
private string password = "";
private string loginErrorMessage = "";
private bool isLoggedIn;
public GUISkin gSkin;
// Use this for initialization
void Start () {
SmartFoxClient smartFox = new SmartFoxClient();
smartFox.Connect("*.*.*.*", 9339);
//Resgister Callbacks
SFSEvent.onConnection += OnConnection;
SFSEvent.onLogin += OnLogin;
SFSEvent.onLogout += OnLogout;
}
// Update is called once per frame
void Update () {
}
//Do the connection
void OnConnection(bool success, string error)
{
if (success)
{
SmartFox.Connection = smartFox;
statusMessage = "Connected!";
Debug.Log("OnConnection Worked");
}
else
{
statusMessage = "Can't connect!";
}
}
//Login Callback
void OnLogin(bool success, string name, string error)
{
Debug.Log("On Login callback got: " + success + " : " + error + " : " + name);
if (success)
{
isLoggedIn = true;
}
else
{
loginErrorMessage = error;
Debug.Log("Login error: " + error);
}
}
//Logout Callback
void OnLogout()
{
Debug.Log("OnLogout");
isLoggedIn = false;
}
void OnGUI()
{
GUI.skin = gSkin;
GUI.Label(new Rect(10, 10, 500, 100), "Status: " + statusMessage);
// Login
if (!isLoggedIn)
{
GUI.Label(new Rect(10, 90, 100, 100), "Zone: ");
zone = GUI.TextField(new Rect(100, 90, 200, 20), zone, 25);
GUI.Label(new Rect(10, 116, 100, 100), "Userame: ");
username = GUI.TextField(new Rect(100, 116, 200, 20), username, 25);
GUI.Label(new Rect(10, 142, 100, 100), "Password: ");
password = GUI.TextField(new Rect(100, 142, 200, 20), password, 4);
GUI.Label(new Rect(10, 218, 100, 100), loginErrorMessage);
if (GUI.Button(new Rect(100, 166, 100, 24), "Login") || (Event.current.type == EventType.keyDown && Event.current.character == '\n'))
{
****ERROR ON THIS LINE smartFox.Login(zone, username, password); ***
}
}
else
{
// If they're there
if (GUI.Button(new Rect(580, 478, 90, 24), "Logout"))
{
smartFox.Logout();
}
}
}
}
I'm sure it's something simple and I'll be embarrassed but I can't figure it out. I have other scripts that work - and I must be blind because I can't see the difference, and the console in Unity is not throwing any Debug.Log errors. Any thoughts appreciated.