Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by vikasch · Jun 27, 2011 at 10:26 AM · onserializenetworkviewbitstream

Virtual Whiteboard stream writing problem

Hey I am building a collaborative 3d whiteboard. Users can draw on a 3d whiteboard which all the other users can see and edit.My problem is only the user who starts the server is able to write, while the rest can only see his drawing and cannot stream their drawing over the network. Any suggestions?My network streaming code is this

       void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info) {
         if (stream.isWriting) {
         Debug.Log("Writing");
         if(Input.GetMouseButton(0)){
         myray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(myray, out myhit, 100.0f) && Input.GetMouseButtonDown(0))
             Debug.Log(myhit.point);
         mouseDown =Input.GetMouseButton(0);
         curr = myhit.point;
         Vector3 currentC=curr;
         //Debug.Log("This is the Current Coordinate"+ currentC);
         stream.Serialize(ref currentC);
         stream.Serialize(ref mouseDown);
         Debug.Log(curr);
         }
         else {
             mouseDown =Input.GetMouseButton(0);
             stream.Serialize(ref mouseDown);
         }
     } 
     else {
         Debug.Log("Reading");
         Vector3 currentC= new Vector3(0,0,-100.0f);
         mouseDown=false;
         stream.Serialize(ref currentC);
         stream.Serialize(ref mouseDown);
         Debug.Log(mouseDown);
         curr=currentC;
         Debug.Log(curr);
         
         if(mouseDown){
         if(last.z != -100.0f) {
             myObject.createLine(last,curr,lineSize,col);
             Debug.Log("last:"+last+" current:"+curr);
             points.Add(curr);
         }    
         last = curr;
     }
     else {
         last.z = -100.0f;
     }
     }


I am new to unity3d ..can anyone help?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Bunny83 · Jun 27, 2011 at 12:01 PM

Only the owner of a NetworkView can "send" data because it's his object so he controls it. All data streaming with OnSerializeNetworkView is always unidirectional. In your case it's better to use RPCs.

Btw: you have to be careful you can stream different content in OnSerializeNetworkView but you have to make sure that the clients are able to read it the same way. It seems you have two different "network-packet-formats": (Vector3 + bool) or (bool). You can't distinguish between those two when receiving it. If you send only a bool but the clients read a Vector3 you will end up with garbage data.

One way to send variable data is that you send always a byte first that identifies what data follows. If you just reverse the bool and Vector3 you could use the bool to selectively write & read the Vector3.

Anyways :D RPCs!

 float sendRate = 20.0f;
 float nextUpdate = 0.0f;
 
 void Update()
 {
     bool mouseDown = Input.GetMouseButton(0);
     myray = Camera.main.ScreenPointToRay(Input.mousePosition);
     if (Physics.Raycast(myray, out myhit, 100.0f) && Input.GetMouseButtonDown(0))
     {
         if (Time.time > nextUpdate)
         {
             // Send to all others
             networkView.RPC("OnNetworkMouseMove",RPCMode.Others,myhit.point,mouseDown,Network.player);
             // call it locally
             OnNetworkMouseMove(myhit.point, mouseDown, Network.player);

             nextUpdate = Time.time + 1.0f / sendRate;
         }
     }
 }
 
 [RPC]
 void OnNetworkMouseMove(Vector3 mousePosition, bool down, NetworkPlayer owner)
 {
     // Now save the points you get seperated for each player!!
     // If you use one list and two players are drawing it will be a mixture ;)
     // Also if down is false you should save the last mouseposition of each player,
     // otherwise it will produce a continuous line which can't be interrupted.
 }


Just a small note: I used RPCMode.Others and not RPCMode.All because if you are the server RPCMode.All will not send it to you. The server can't send a message to itself. On clients it would be no problem but it's also unnecessary traffic.

I don't know how you actually "draw" so that's up to you ;) Just make sure you seperate the users by it's NetworkPlayer and you'll be fine.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Jun 27, 2011 at 12:03 PM 0
Share

It can be optimised by sending nothing when the mouse position hasn't changed. usually 90%+ of the users will idle so it's better to do nothing ;)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Mysterious OnSerializeNetworkView calls with an invalid NetworkMessageInfo.sender 1 Answer

How does BitStream work? 1 Answer

Data Synchronization using OnSerializeNetworkView 1 Answer

How to send a gameobject in the OnSerializeNetworkView() 0 Answers

OnSerializeNetworkView NOT sending a bool value when button is pressed??? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges