Author Topic: Converting Photon project to TNet  (Read 6952 times)

sberghici

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Converting Photon project to TNet
« on: November 16, 2013, 10:35:32 AM »
Hi ArenMook
I'm converting FPS Kit V2 to work with TNet, and so far only one problem I have is how to implement "OnPhotonSerializeView"
http://doc.exitgames.com/photon-cloud/PUNOverview/

I think RFC can be used, please advice
« Last Edit: November 16, 2013, 12:27:19 PM by sberghici »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Converting Photon project to TNet
« Reply #1 on: November 16, 2013, 08:53:08 PM »
OnPhotonSerializeView is a function that matches similar one-way communication that exists in Unity's networking implementation. It should not be used. Instead, just do an RFC call. So for example, instead of this:
  1. void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
  2. {
  3.    if (stream.isWriting)
  4.    {
  5.        //We own this player: send the others our data
  6.        stream.SendNext((int)controllerScript._characterState);
  7.        stream.SendNext(transform.position);
  8.        stream.SendNext(transform.rotation);
  9.    }
  10.    else
  11.    {
  12.        //Network player, receive data
  13.        controllerScript._characterState = (CharacterState)(int)stream.ReceiveNext();
  14.        correctPlayerPos = (Vector3)stream.ReceiveNext();
  15.        correctPlayerRot = (Quaternion)stream.ReceiveNext();
  16.    }
  17. }
You could do this:
  1. [RFC]
  2. void OnMyData (int state, Vector3 pos, Quaternion rot)
  3. {
  4.     controllerScript._characterState = (CharacterState)state;
  5.     correctPlayerPos = pos;
  6.     correctPlayerRot = rot;
  7. }
You would then call this function on the object's owner like so:
  1. if (tno.isMine) tno.Send("OnMyData", Target.OthersSaved, (int)controllerScript_characterState, correctPlayerPos, correctPlayerRot);

....However... what would be even easier is to just use TNAutoSync script instead, pointing to the values you want sync'd. Doing so you can achieve all this without having to write any code at all.

sberghici

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: Converting Photon project to TNet
« Reply #2 on: November 17, 2013, 04:50:11 AM »
Thanks ArenMook, it worked! I use tno.SendQuickly(UDP) sending updates 20 times per second. The project is fully converted to TNet and works pretty good. Tomorrow I'll test it with my VPS hosting to see how it behaves in the real environment.
Great product and support!   

sberghici

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: Converting Photon project to TNet
« Reply #3 on: November 22, 2013, 02:04:14 PM »
Take a look at the game demo. It has been hosted on VPS in New Jersey:
http://exposedconflict.com/unity/TNet.html

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Converting Photon project to TNet
« Reply #4 on: November 22, 2013, 04:12:52 PM »
Halp! I can't climb ladders, and have to hop over small stairs! :P

sberghici

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: Converting Photon project to TNet
« Reply #5 on: November 23, 2013, 12:18:00 PM »
Halp! I can't climb ladders, and have to hop over small stairs! :P
Fixed, FPS Kit project was screwed up.

sberghici

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: Converting Photon project to TNet
« Reply #6 on: November 25, 2013, 12:57:16 AM »
Aren
I have one more question regarding TNet. What is the best way to send list of objects using tno.Send? I use kind of serialization, but I guess you may have the better way to do it.