Advertisement
baflink

ForgeExample_WriteCustom_p22.cs

Jul 7th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.24 KB | None | 0 0
  1. /*-----------------------------+------------------------------\
  2. |                                                             |
  3. |                        !!!NOTICE!!!                         |
  4. |                                                             |
  5. |  These libraries are under heavy development so they are    |
  6. |  subject to make many changes as development continues.     |
  7. |  For this reason, the libraries may not be well commented.  |
  8. |  THANK YOU for supporting forge with all your feedback      |
  9. |  suggestions, bug reports and comments!                     |
  10. |                                                             |
  11. |                               - The Forge Team              |
  12. |                                 Bearded Man Studios, Inc.   |
  13. |                                                             |
  14. |  This source code, project files, and associated files are  |
  15. |  copyrighted by Bearded Man Studios, Inc. (2012-2015) and   |
  16. |  may not be redistributed without written permission.       |
  17. |                                                             |
  18. \------------------------------+-----------------------------*/
  19.  
  20.  
  21.  
  22. using UnityEngine;
  23.  
  24. using BeardedManStudios.Network;
  25.  
  26. public class ForgeExample_WriteCustom : MonoBehaviour
  27. {
  28.     public const uint CUSTOM_ID = 55000;
  29.  
  30.     private void Start()
  31.     {
  32.         Debug.Log("Registering read callback event");
  33.         Networking.PrimarySocket.AddCustomDataReadEvent(CUSTOM_ID, onRead);
  34.     }
  35.  
  36.     private void Update()
  37.     {
  38.         if (Input.GetKeyDown(KeyCode.Space))
  39.         {
  40.             string username = "Dennis";
  41.             string password = "Password";
  42.             ulong data = 9uL;
  43.             ushort LoginReq = 2;
  44.             BMSByte dataCache = new BMSByte();
  45.             dataCache.Clone(ObjectMapper.MapBytes(dataCache, LoginReq, username, password, data));
  46.             Networking.WriteCustom(CUSTOM_ID, Networking.PrimarySocket, dataCache, true, NetworkReceivers.All);
  47.         }
  48.     }
  49.  
  50.     public void onRead(NetworkingPlayer sender, NetworkingStream stream)
  51.     {
  52.         ushort LoginReq = ObjectMapper.Map<ushort>(stream);
  53.         string uname = ObjectMapper.Map<string>(stream);
  54.         string password = ObjectMapper.Map<string>(stream);
  55.         ulong ID = ObjectMapper.Map<ulong>(stream);
  56.  
  57.         Debug.Log(LoginReq);
  58.         Debug.Log(uname);
  59.         Debug.Log(password);
  60.         Debug.Log(ID);
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement