If you haven’t read below posts, you might wish to have a quick go through:
Using SmartFox with C# (I) : Installations and 1st handshaking
Using SmartFox with C# (II) : Login and join room
If you are comfortable with above implementations, you might be interested in below frequently called functions. Assuming below variable is instantiated successfully:
private SmartFox client;
To Send a message:
client.Send(new PublicMessageRequest(someMessage));
client.AddEventListener(SFSEvent.PUBLIC_MESSAGE, OnPublicMessage);
private void OnPublicMessage(BaseEvent evt) {
User sender = (User) evt.Params[“sender”];
string message = (string) evt.Params[“message”];
}
To create a room:
var settings = new RoomSettings(“New Room Name”);
settings.maxUsers = 100;
Settings.groupId = “ChatGroup”;
client.Send(new CreateRoomRequest(settings));client.addEventListener(SFSEvent.ROOM_ADD, OnRoomAdded);
For a zone, to join/remove a room:
client.Send(new Sfs2X.Requests.JoinRoomRequest(roomId));
client.AddEventListener(SFSEvent.ROOM_JOIN, OnRoomJoin);
private void OnRoomJoin(BaseEvent evt) {
Room room = (Room) evt.Params[“room”];
//room.Name, room.UserList
}
For user to enter/leave a room
client.Send(new Sfs2X.Requests.LeaveRoomRequest());
client.AddEventListener(SFSEvent.USER_EXIT_ROOM, OnUserExitRoom);
private void OnUserExitRoom(BaseEvent evt) { User user = (User) evt.Params[“user”]; }
For more information, have a read on SFSEvent class and Sfs2X.Requests namespace will be vey helpful.
Filed under: Dotnet/C#, Programming, Unity 3d Tagged: C#, example, how to, SmartFox, Unity, Unity 3d
