Page 1 of 1

Managing multi-extension Zone

Posted: 14 May 2009, 00:25
by duke
The questions here might be a bit vague - i'm at work so I can't look at my project to point out specifics. What is the best way to handle multiple extensions in one Zone? Right now, I have:

Login
Manager
GameServer

..as extensions attached to the zone. The is an mmo project in Unity.

Login manages all logins! This takes place in it's own room, and I wanted to keep it seperate so I have the future possibility of putting it in a completely different server. If a user is logged in and isn't the GameServer, ActorAdd is fired.

Manager is pretty much the central Extension, although it has little to do with, or any dependence on Login. It receives commands such as ActorAdd, ActorMove, (everything else that comes from the clients), etc. This data is then handled by seperate Java classes that aren't attached as Extensions, like Actor, Inventory, etc.

GameServer is a seperate Unity build that manages and validates stuff that SFS can't, like player collisions, etc. The GameServer manages stuff such as the GameServer request for playerlists, and stuff is passed to it such as ActorAdd, ActorMove, ActorList etc.

Now the problems I continualy run into are that often these classes can't find the current Zone or current connection. So, has anyone done something similar where they then have a central ConnectionHolder or something, that maintains the connection the Zone so it can be called from anyway? I have a static function in my Manager script that's meant to do this, but sometimes it doesn't work, and I'm sure there's a cleaner way of doing it. Should I have all my scripts attached to the zone or can I leave it like it is with the Request Handlers in the Manager/Login/GS and everything else passed to unconnected but instanced classes (they're all called as singletons at the moment).

Posted: 18 May 2009, 08:56
by ThomasLund
You should be able to simply use "singletons" to keep state between scenes.

There are various ways to do this in Unity, but the simplest is to have a basic static class. If you look at the example codes I made, there is the smartfox.cs class that simply holds the connection.

That would be the easiest way to do it. Other ways are on the Unify wiki - a component you attach to a GO that has the "not destroyed on load" set. Effect is the same, so static class is simplest.

/Thomas

Posted: 19 May 2009, 01:06
by duke
Yeah that island demo is fantastic Thomas - thanks! I learnt about singletons and am using them successfully on both client and server. This question was more to do with serverside extensions than Unity (client). What i've got for now though, is a static GetZone function in my manager. So if i'm instancing any script or calling it's singleton instance, I just set zone to "Zone zone = Manager.GetZone();" and go from there if I need it.