Guest User

Untitled

a guest
Jan 18th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using PubNubAPI;
  5.  
  6.  
  7. public class pnVoteInput : MonoBehaviour
  8. {
  9.  
  10. ///these variable are used to set up Pubnub
  11. public static PubNub dataServer;
  12. public string pubKey = "pub-c-a705a585-4407-4f88-8b83-ac846c45e13a";
  13. public string subKey = "sub-c-64587bc8-b0cf-11e6-a7bb-0619f8945a4f";
  14. public string channelName = "phoneRotations";
  15. ////
  16.  
  17. public double rotX;
  18. public double rotY;
  19. public double rotZ;
  20.  
  21.  
  22. void Start ()
  23. {
  24.  
  25. //This section establishes the parameters for connecting to Pubnub
  26. PNConfiguration connectionSettings = new PNConfiguration ();
  27. connectionSettings.PublishKey = pubKey;
  28. connectionSettings.SubscribeKey = subKey;
  29. connectionSettings.LogVerbosity = PNLogVerbosity.BODY;
  30. connectionSettings.Secure = true;
  31. ////////
  32.  
  33. dataServer = new PubNub(connectionSettings); //make the connection to the server
  34.  
  35. Debug.Log("Connected to Pubnub");
  36.  
  37. //Subscribe to the channel specified above
  38. dataServer.Subscribe ()
  39. .Channels (new List<string> () { channelName } )
  40. .Execute();
  41.  
  42. //define the function that is called when a new message arrives
  43. //unlike javascript it is named and defined all at once rather than linking to another function
  44. dataServer.SusbcribeCallback += (sender, evt) =>
  45. {
  46.  
  47. SusbcribeEventEventArgs inMessage = evt as SusbcribeEventEventArgs;
  48.  
  49. if (inMessage.MessageResult != null) //error check to insure the message has contents
  50. {
  51.  
  52. //convert the object that holds the message contents into a Dictionary
  53. Dictionary<string, object> msg = inMessage.MessageResult.Payload as Dictionary<string, object>;
  54.  
  55.  
  56. rotX = (double)msg["rotX"];
  57. rotY = (double)msg["rotY"];
  58. rotZ = (double)msg["rotZ"];
  59.  
  60.  
  61. transform.eulerAngles = new Vector3((float)rotX,(float)rotY,(float)rotZ);
  62. }
  63.  
  64. };
  65.  
  66.  
  67. }
  68.  
  69. }
Add Comment
Please, Sign In to add comment