[Integrated] Sending classes from c# unity to sfs 2x java

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

Post Reply
Robbilie
Posts: 190
Joined: 04 Sep 2010, 19:48
Location: Ratingen, Germany

[Integrated] Sending classes from c# unity to sfs 2x java

Post by Robbilie »

hey guys

I hope the title says all :D

Is this possible ? Thomas?
Last edited by Robbilie on 23 Feb 2011, 18:23, edited 1 time in total.
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Post by ThomasLund »

The SFS2X Java client API is modelled after the C# one (I copy pasted/made it - hehe).

So the interface itself is almost identical.

Only part that is a little different is how you register callbacks. Example here:

Code: Select all

	@Test
	public void TestLoginLogout() {
		sfs = new SmartFox(true);
		sfs.addEventListener(SFSEvent.CONNECTION, new IEventListener() {
			public void dispatch(BaseEvent evt) {
				onConnection(evt);
			}
		});
		sfs.addEventListener(SFSEvent.LOGIN, new IEventListener() {
			@Override
			public void dispatch(BaseEvent evt) throws SFSException {
				onLogin(evt);
			}
		});
     }
......

	private void onConnection(BaseEvent evt) {
		if ((Boolean) evt.getArguments().get("success")) {
			sfs.send(new LoginRequest("", "", sfs.getCurrentZone()));
		}
	}

	private void onLogin(BaseEvent evt) {
		loggedIn = true;
		sfs.send(new LogoutRequest());
	}

So as you can see its very similar in general
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund
Robbilie
Posts: 190
Joined: 04 Sep 2010, 19:48
Location: Ratingen, Germany

Post by Robbilie »

sry transfering is the wrong word i think....

I meant sending classes from unity client (in c#) to sfs 2x (which is in java)
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Post by ThomasLund »

Ahhhh - there is unannounced experimental support for it in the latest dll.

SFSObject has a PutClass and GetClass

Test code:

Code: Select all

		[Test]
		public void TestObjectNestedClass() {
			DefaultSFSDataSerializer serializer = DefaultSFSDataSerializer.Instance;
			DefaultSFSDataSerializer.RunningAssembly = Assembly.GetExecutingAssembly();
			
			ISFSObject sfsObj = new SFSObject();
			
			TestObject obj1 = new TestObject();
			obj1.intField = 60;
			TestObject obj2 = new TestObject();
			obj2.intField = 70;
			
			sfsObj.PutClass("obj1", obj1);
			sfsObj.PutClass("obj2", obj2);
																		
			ByteArray data = serializer.Object2Binary(sfsObj);
			Assert.Greater(data.Length, 0);
			
			ISFSObject res = serializer.Binary2Object(data);
			Assert.AreEqual(2, res.Size());
			
			TestObject res1 = res.GetClass("obj1") as TestObject;
			TestObject res2 = res.GetClass("obj2") as TestObject;
			
			Assert.AreEqual(60, res1.intField);
			Assert.AreEqual(70, res2.intField);
		}
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund
Robbilie
Posts: 190
Joined: 04 Sep 2010, 19:48
Location: Ratingen, Germany

Post by Robbilie »

can u give a bit coment on that code?

Most i uderstand (the part i wanted to know bout....)

But the rest....?

Assert?
And what are u doin there? What do u try to archieve?

PS: thanks thomas for this great feature ;)

Realy need for rpg data like inventory and stuf..
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Post by ThomasLund »

The asserts are all from unit test framework. You can mostly forget about that.

/Thomas
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund
Post Reply