void SubscribeHandler() { pubnub.Subscribe().Channels(new List <string> () { ch1 }).WithPresence().Execute(); }
void Start() { PNConfiguration pnConfiguration = new PNConfiguration(); pnConfiguration.SubscribeKey = subKey; pnConfiguration.PublishKey = pubKey; pnConfiguration.UUID = myID; dataServer = new PubNub(pnConfiguration); dataServer.Subscribe() .Channels(new List <string> () { subscribeChannel }) .Execute(); dataServer.SubscribeCallback += (sender, e) => { SubscribeEventEventArgs inMessage = e as SubscribeEventEventArgs; if (inMessage.MessageResult != null) //error check to insure the message has contents { //save the UUID of the last sender lastSender = inMessage.MessageResult.IssuingClientId; Debug.Log(lastSender); //save the message into a Dictionary Dictionary <string, object> msg = inMessage.MessageResult.Payload as Dictionary <string, object>; //retrieve and convert the value you need using the key name /* * convert to integer - (int)msg["keyName"] * convert to float - (float)msg["keyName"] * convert to string - (float)msg["keyName"] * */ /*list all keys * foreach (string key in msg.Keys) * { * Debug.Log(key); * } */ xVal = (int)msg["x"]; yVal = (int)msg["y"]; transform.position = new Vector3(xVal * 2, 0, yVal * -2); } }; }
// Use this for initialization void Start() { // Use this for initialization PNConfiguration pnConfiguration = new PNConfiguration(); pnConfiguration.PublishKey = "pub-c-efb4a8fe-605a-42e8-866a-facc7271a49d"; pnConfiguration.SubscribeKey = "sub-c-1bb9d4ac-52f4-11e8-85c6-a6b0a876dba1"; pnConfiguration.LogVerbosity = PNLogVerbosity.BODY; //pnConfiguration.UUID = Random.Range (0f, 999999f).ToString (); inputResponse = GameObject.Find("InputObject").GetComponent <InputScript>().UUIDinput.ToString(); Debug.Log(inputResponse); pnConfiguration.UUID = inputResponse; pubnub = new PubNub(pnConfiguration); Debug.Log(pnConfiguration.UUID); UUIDText.text = "UUID: " + pnConfiguration.UUID; pubnub.SusbcribeCallback += (sender, e) => { SusbcribeEventEventArgs mea = e as SusbcribeEventEventArgs; if (mea.Status != null) { } if (mea.MessageResult != null) { lastClickText.text = "Last Publish Sent by: " + mea.MessageResult.IssuingClientId.ToString(); if ((int)mea.MessageResult.Payload == 1) { CubeObject.GetComponent <Renderer>().material = Pepe; } if ((int)mea.MessageResult.Payload == 2) { CubeObject.GetComponent <Renderer>().material = Pepe2; } if ((int)mea.MessageResult.Payload == 3) { CubeObject.GetComponent <Renderer>().material = Pepe3; } } if (mea.PresenceEventResult != null) { //lastClickText.text = mea.PresenceEventResult.UUID.ToString(); Debug.Log("In Example, SusbcribeCallback in presence" + mea.PresenceEventResult.Channel + mea.PresenceEventResult.Occupancy + mea.PresenceEventResult.Event); } }; pubnub.Subscribe() .Channels(new List <string> () { "my_channel" }) .WithPresence() .Execute(); }
private Vector3 _heading; // Where the user looking. void Start() { MLEyes.Start(); // Start eye tracking. MLInput.Start(); // Start input controller. MLInput.OnTriggerDown += HandleOnTriggerDown; // Get trigger down event. meshRenderer = gameObject.GetComponent <MeshRenderer>(); // Get the game object. PNConfiguration pnConfiguration = new PNConfiguration(); // Start PubNub pnConfiguration.PublishKey = "pub-c-bb13912e-7007-46ce-a954-74fe4c6cb131"; // YOUR PUBLISH KEY HERE. pnConfiguration.SubscribeKey = "sub-c-e14cda48-b857-11e8-b27d-1678d61e8f93"; // YOUR SUBSCRIBE KEY HERE. pubnub = new PubNub(pnConfiguration); pn_uuid = pnConfiguration.UUID; // Get the UUID of the PubNub client. pubnub.Subscribe() .Channels(new List <string>() { meshRenderer.name // Subscribe to the channel for the game object. }) .Execute(); pubnub.SusbcribeCallback += (sender, e) => { SusbcribeEventEventArgs message = e as SusbcribeEventEventArgs; if (message.Status != null) { switch (message.Status.Category) { case PNStatusCategory.PNUnexpectedDisconnectCategory: case PNStatusCategory.PNTimeoutCategory: pubnub.Reconnect(); break; } } if (message.MessageResult != null) { // Does the message equal the UUID for this client? if (message.MessageResult.Payload.ToString() == pn_uuid) // Message and client UUID are the same. { meshRenderer.material = OwnedMaterial; // The user owns the game object, change material to OwnedMaterial to show. looking = false; owned = true; } else // Message and client UUID are NOT the same. { if (owned) // Only need to change color if the user owns the game object. { meshRenderer.material = NonFocusedMaterial; // Another user has taken the game object, change material to NonFocusedMaterial to show.. owned = false; } } } }; }
void SubscribeHandler() { Dictionary <string, string> dict = new Dictionary <string, string>(); dict.Add("k1", "v1"); pubnub.SubscribeCallback += SubscribeCallbackHandler; pubnub.Subscribe().Channels(new List <string> () { ch1 }).WithPresence().QueryParam(dict).Execute(); }
void Start() { //This section establishes the parameters for connecting to Pubnub PNConfiguration connectionSettings = new PNConfiguration(); connectionSettings.PublishKey = pubKey; connectionSettings.SubscribeKey = subKey; connectionSettings.LogVerbosity = PNLogVerbosity.BODY; connectionSettings.Secure = true; //////// dataServer = new PubNub(connectionSettings); //make the connection to the server Debug.Log("Connected to Pubnub"); //Subscribe to the channel specified above dataServer.Subscribe() .Channels(new List <string>() { channelName }) .Execute(); //define the function that is called when a new message arrives //unlike javascript it is named and defined all at once rather than linking to another function dataServer.SusbcribeCallback += (sender, evt) => { SusbcribeEventEventArgs inMessage = evt as SusbcribeEventEventArgs; if (inMessage.MessageResult != null) //error check to insure the message has contents { //convert the object that holds the message contents into a Dictionary Dictionary <string, object> msg = inMessage.MessageResult.Payload as Dictionary <string, object>; Debug.Log(inMessage.MessageResult.Payload); Debug.Log("GOOOO!!!"); // //trainSpeed = (float)msg["trainS"]; //force convert the "slide" parameter of the dictionary to be an integer and assign it to the currentSlide variable. trainSpeed = (int)msg["train"]; //force convert the "slide" parameter of the dictionary to be an integer and assign it to the currentSlide variable. } }; }
public void Onsubscribe() { pubnub.SusbcribeCallback += (sender, e) => { SusbcribeEventEventArgs mea = e as SusbcribeEventEventArgs; if (mea.Status != null) { log.text = "called mea.status"; } if (mea.MessageResult != null) { log.text = "called mea.status"; Debug.Log("Entered in Mea.Subscribe"); Dictionary <string, object> msg = mea.MessageResult.Payload as Dictionary <string, object>; string[] strArr = msg["username"] as string[]; string[] strScores = msg["score"] as string[]; int usernamevar = 1; foreach (string username in strArr) { string usernameobject = "Line" + usernamevar; GameObject.Find(usernameobject).GetComponent <Text>().text = usernamevar.ToString() + ". " + username.ToString(); usernamevar++; Debug.Log(username); log.text = "username: "******""; } int scorevar = 1; foreach (string score in strScores) { string scoreobject = "Score" + scorevar; GameObject.Find(scoreobject).GetComponent <Text>().text = "Score: " + score.ToString(); scorevar++; Debug.Log(score); log.text = "score: " + score + ""; } } if (mea.PresenceEventResult != null) { Debug.Log("In Example, SusbcribeCallback in presence" + mea.PresenceEventResult.Channel + mea.PresenceEventResult.Occupancy + mea.PresenceEventResult.Event); } }; pubnub.Subscribe() .Channels(new List <string>() { "LEaderBoardchannel" }) .WithPresence() .Execute(); }
void Start() { PNConfiguration pnConfiguration = new PNConfiguration(); pnConfiguration.SubscribeKey = subKey; pnConfiguration.PublishKey = pubKey; pnConfiguration.UUID = myID; dataServer = new PubNub(pnConfiguration); dataServer.Subscribe() .Channels(new List <string> () { channelName }) .Execute(); dataServer.SubscribeCallback += (sender, e) => { SubscribeEventEventArgs inMessage = e as SubscribeEventEventArgs; if (inMessage.MessageResult != null) //error check to insure the message has contents { //save the UUID of the last sender lastSender = inMessage.MessageResult.IssuingClientId; //save the message into a Dictionary Dictionary <string, object> msg = inMessage.MessageResult.Payload as Dictionary <string, object>; //retrieve and convert the value you need using the key name /* * convert to integer - (int)msg["keyName"] * convert to float - (float)msg["keyName"] * convert to string - (float)msg["keyName"] * */ xVal = (int)msg["x"]; yVal = (int)msg["y"]; Instantiate(clickDrop, new Vector3(xVal * 2, 800, yVal * -2), Quaternion.identity); } }; }
void Start() { videoPlayer.SetActive(false); PNConfiguration connectionSettings = new PNConfiguration(); connectionSettings.PublishKey = pubKey; connectionSettings.SubscribeKey = subKey; connectionSettings.LogVerbosity = PNLogVerbosity.BODY; connectionSettings.Secure = true; //////// dataServer = new PubNub(connectionSettings); Debug.Log("Connected to Pubnub"); dataServer.Subscribe() .Channels(new List <string>() { channelName }) .Execute(); //// when message arrives:///////// dataServer.SusbcribeCallback += (sender, evt) => { SusbcribeEventEventArgs inMessage = evt as SusbcribeEventEventArgs; if (inMessage.MessageResult != null) { Dictionary <string, object> msg = inMessage.MessageResult.Payload as Dictionary <string, object>; inVote = (int)msg["totalHits"]; if (inVote > currentVote) { videoPlayer.SetActive(true); currentVote = inVote; } } }; }
private static void Connect() { _pnConfiguration.SubscribeKey = "sub-c-ec33873a-53d1-11e8-84ad-b20235bcb09b"; _pnConfiguration.PublishKey = "pub-c-56bfd71d-e6e9-479d-9c08-b2c719d6a4c7"; _pnConfiguration.SecretKey = "sec-c-OWY1ZDU0NGUtN2IyZC00YmJmLWFmNTEtOTc3NDFkYWE0YjUw"; _pnConfiguration.LogVerbosity = PNLogVerbosity.BODY; _pnConfiguration.UUID = "shmart-city-unity"; _pubnub = new PubNub(_pnConfiguration); _pubnub.SusbcribeCallback += Callback; // subscribe to this channels _channels = new List <string>() { "route-to-fire" }; _pubnub.Subscribe().Channels(_channels).Execute(); }
void Start() { PNConfiguration connectionSettings = new PNConfiguration(); connectionSettings.PublishKey = pubKey; connectionSettings.SubscribeKey = subKey; connectionSettings.LogVerbosity = PNLogVerbosity.BODY; connectionSettings.Secure = true; dataServer = new PubNub(connectionSettings); dataServer.Subscribe() .Channels(new List <string>() { channelName }) .Execute(); }
///------------------------------------------------------------------------------------------------- /// <summary> AmazonAlexaManager Constructor. </summary> /// /// <remarks> Austin Wilson, 9/15/2018. </remarks> /// /// <param name="publishKey"> Your PubNub publish key. </param> /// <param name="subscribeKey"> Your PubNub subscribe key. </param> /// <param name="channel"> Your player's channel. (Should be unique to the player) </param> /// <param name="tableName"> Name of your skill's DynamoDB table where the persistant attributes are stored. </param> /// <param name="identityPoolId"> Identifier of your AWS Cognito identity pool. </param> /// <param name="AWSRegion"> The AWS Region where your DynamoDB table and Cognito identity pool are hosted. </param> /// <param name="gameObject"> The GameObject you are attaching this manager instance to. </param> /// <param name="messageCallback"> The callback for when a message is recived from your Alexa Skill. </param> /// <param name="debug"> (Optional) True to debug. </param> ///------------------------------------------------------------------------------------------------- public AmazonAlexaManager(string publishKey, string subscribeKey, string channel, string tableName, string identityPoolId, string AWSRegion, GameObject gameObject, Action <HandleMessageEventData> messageCallback, Action <ConnectionStatusEventData> connectionStatusCallback, bool debug = false) { PNConfiguration pnConfiguration = new PNConfiguration(); pnConfiguration.SubscribeKey = subscribeKey; pnConfiguration.PublishKey = publishKey; if (debug) { pnConfiguration.LogVerbosity = PNLogVerbosity.BODY; } pubnub = new PubNub(pnConfiguration); handleMessageCallback = messageCallback; handleConnectionStatusCallback = connectionStatusCallback; this.channel = channel; this.debug = debug; this.tableName = tableName; this.identityPoolId = identityPoolId; this.AWSRegion = AWSRegion; if (PlayerPrefs.HasKey("alexaUserDynamoKey")) { alexaUserDynamoKey = PlayerPrefs.GetString("alexaUserDynamoKey"); } if (PlayerPrefs.HasKey("lastMessageTimestamp")) { lastMessageTimestamp = long.Parse(PlayerPrefs.GetString("lastMessageTimestamp")); } else { lastMessageTimestamp = 0; } pubnub.SusbcribeCallback += MessageListener; pubnub.Subscribe() .Channels(new List <string>() { this.subChannel }) .Execute(); Debug.Log(displayName + "Started for scene on channel " + channel + "! Listening for messages..."); }
void Start() { // Use this for initialization PNConfiguration pnConfiguration = new PNConfiguration(); pnConfiguration.PublishKey = "<PUT-HERE-THE-PUBNUB-PUBLISH-KEY>"; pnConfiguration.SubscribeKey = "<PUT-HERE-THE-PUBNUB-SUBSCRIBE-KEY>"; pnConfiguration.LogVerbosity = PNLogVerbosity.BODY; pnConfiguration.UUID = Random.Range(0f, 999999f).ToString(); pubnub = new PubNub(pnConfiguration); Debug.Log(pnConfiguration.UUID); MyClass myFireObject = new MyClass(); myFireObject.test = "Player 1"; string fireobject = JsonUtility.ToJson(myFireObject); pubnub.Fire() .Channel("beach_cg_channel") .Message(fireobject) .Async((result, status) => { if (status.Error) { Debug.Log(status.Error); Debug.Log(status.ErrorData.Info); } else { Debug.Log(string.Format("Fire Timetoken: {0}", result.Timetoken)); } }); pubnub.SusbcribeCallback += (sender, e) => { SusbcribeEventEventArgs mea = e as SusbcribeEventEventArgs; if (mea.Status != null) { } if (mea.MessageResult != null) { Dictionary <string, object> msg = mea.MessageResult.Payload as Dictionary <string, object>; string[] strArr = msg["username"] as string[]; string[] strScores = msg["score"] as string[]; int usernamevar = 1; foreach (string username in strArr) { string usernameobject = "Line" + usernamevar; GameObject.Find(usernameobject).GetComponent <Text>().text = usernamevar.ToString() + ". " + username.ToString(); usernamevar++; Debug.Log(username); } int scorevar = 1; foreach (string score in strScores) { string scoreobject = "Score" + scorevar; GameObject.Find(scoreobject).GetComponent <Text>().text = "Score: " + score.ToString(); scorevar++; Debug.Log(score); } } if (mea.PresenceEventResult != null) { Debug.Log("In Example, SusbcribeCallback in presence" + mea.PresenceEventResult.Channel + mea.PresenceEventResult.Occupancy + mea.PresenceEventResult.Event); } }; pubnub.Subscribe() .Channels(new List <string> () { "beach_cg_channel" }) .WithPresence() .Execute(); }
void Start() { //Brings up Team Selectoin Menue Team_Selector.SetActive(true); Blue_HUD.SetActive(false); Red_HUD.SetActive(false); while (TeamSelectStatus == true) { } //Brings up HUD for coresponding team if (BlueTeamSelect == false) { Blue_HUD.SetActive(false); Red_HUD.SetActive(true); } else { Blue_HUD.SetActive(true); Red_HUD.SetActive(false); } //Changes Controller Material to match team if (BlueTeamSelect == false) { controllerRend.material = controllerRed; } else { controllerRend.material = controllerBlue; } _mlSpatialMapper.gameObject.transform.position = _camera.gameObject.transform.position; _mlSpatialMapper.gameObject.transform.localScale = _bounded ? _boundedExtentsSize : _boundlessExtentsSize; // Initializing a new pubnub Connection PNConfiguration pnConfiguration = new PNConfiguration(); pnConfiguration.PublishKey = "pub-c-86694f64-f8a5-4dea-a382-d99cef5f71e9"; pnConfiguration.SubscribeKey = "sub-c-ef60f02c-80b8-11e9-bc4f-82f4a771f4c5"; pnConfiguration.LogVerbosity = PNLogVerbosity.BODY; pnConfiguration.UUID = "GameMNGR"; pnConfiguration.ReconnectionPolicy = PNReconnectionPolicy.LINEAR; PubNub pubnub = new PubNub(pnConfiguration); //Sets up Subscriber Callback which handles received messages pubnub.SubscribeCallback += (sender, e) => { SubscribeEventEventArgs mea = e as SubscribeEventEventArgs; if (mea.MessageResult != null) { if (mea.MessageResult.Payload == "BumperPress") { CubeRenderer.enabled = false; } else { CubeRenderer.enabled = true; } } }; //Subscribes to channels in list pubnub.Subscribe() .Channels(new List <string>() { "cube" }) .Execute(); }
//public Object[] tiles = {} // Use this for initialization void Start() { Button btn = SubmitButton.GetComponent <Button>(); btn.onClick.AddListener(TaskOnClick); // Use this for initialization PNConfiguration pnConfiguration = new PNConfiguration(); pnConfiguration.PublishKey = "pub-c-87790afb-caa1-41c1-954d-37ccbd86682c"; pnConfiguration.SubscribeKey = "sub-c-7b4a7626-a628-11eb-96f4-7e87b170c68c"; //Publish Key: pub - c - 87790afb - caa1 - 41c1 - 954d - 37ccbd86682c //Subscribe Key: sub - c - 7b4a7626 - a628 - 11eb - 96f4 - 7e87b170c68c pnConfiguration.LogVerbosity = PNLogVerbosity.BODY; pnConfiguration.UUID = Random.Range(0f, 999999f).ToString(); pubnub = new PubNub(pnConfiguration); Debug.Log(pnConfiguration.UUID); MyClass myFireObject = new MyClass(); myFireObject.test = "new user"; string fireobject = JsonUtility.ToJson(myFireObject); pubnub.Fire() .Channel("submit_score") .Message(fireobject) .Async((result, status) => { if (status.Error) { Debug.Log(status.Error); Debug.Log(status.ErrorData.Info); } else { Debug.Log(string.Format("Fire Timetoken: {0}", result.Timetoken)); } }); pubnub.SusbcribeCallback += (sender, e) => { SusbcribeEventEventArgs mea = e as SusbcribeEventEventArgs; if (mea.Status != null) { } if (mea.MessageResult != null) { Dictionary <string, object> msg = mea.MessageResult.Payload as Dictionary <string, object>; string[] strArr = msg["username"] as string[]; string[] strScores = msg["score"] as string[]; int usernamevar = 1; foreach (string username in strArr) { string usernameobject = "Line" + usernamevar; GameObject.Find(usernameobject).GetComponent <Text>().text = usernamevar.ToString() + ". " + username.ToString(); usernamevar++; Debug.Log(username); } int scorevar = 1; foreach (string score in strScores) { string scoreobject = "Score" + scorevar; GameObject.Find(scoreobject).GetComponent <Text>().text = "Score: " + score.ToString(); scorevar++; Debug.Log(score); } } if (mea.PresenceEventResult != null) { Debug.Log("In Example, SusbcribeCallback in presence" + mea.PresenceEventResult.Channel + mea.PresenceEventResult.Occupancy + mea.PresenceEventResult.Event); } }; pubnub.Subscribe() .Channels(new List <string>() { "leaderboard_scores" }) .WithPresence() .Execute(); }
void Start() { // Use this for initialization PNConfiguration pnConfiguration = new PNConfiguration(); pnConfiguration.PublishKey = "demo"; pnConfiguration.SubscribeKey = "demo"; pnConfiguration.LogVerbosity = PNLogVerbosity.BODY; pnConfiguration.UUID = "user-1"; pubnub = new PubNub(pnConfiguration); // Add Listener to Submit button to send messages Button btn = SubmitButton.GetComponent <Button>(); btn.onClick.AddListener(TaskOnClick); // Fetch the maxMessagesToDisplay messages sent on the given PubNub channel pubnub.FetchMessages() .Channels(new List <string> { channel }) .Count(maxMessagesToDisplay) .Async((result, status) => { if (status.Error) { Debug.Log(string.Format( " FetchMessages Error: {0} {1} {2}", status.StatusCode, status.ErrorData, status.Category )); } else { foreach (KeyValuePair <string, List <PNMessageResult> > kvp in result.Channels) { foreach (PNMessageResult pnMessageResult in kvp.Value) { // Format data into readable format JSONInformation chatmessage = JsonUtility.FromJson <JSONInformation>(pnMessageResult.Payload.ToString()); // Call the function to display the message in plain text CreateChat(chatmessage); } } } }); // This is the subscribe callback function where data is recieved that is sent on the channel pubnub.SubscribeCallback += (sender, e) => { SubscribeEventEventArgs message = e as SubscribeEventEventArgs; if (message.MessageResult != null) { // Format data into a readable format JSONInformation chatmessage = JsonUtility.FromJson <JSONInformation>(message.MessageResult.Payload.ToString()); // Call the function to display the message in plain text CreateChat(chatmessage); // When a new chat is created, remove the first chat and transform all the messages on the page up SyncChat(); } }; // Subscribe to a PubNub channel to receive messages when they are sent on that channel pubnub.Subscribe() .Channels(new List <string>() { channel }) .WithPresence() .Execute(); }
void Start() { // Use this for initialization PNConfiguration pn_configuration = new PNConfiguration(); pn_configuration.PublishKey = "pub-c-c9fedf8b-6c91-46cf-b6d9-14b5ec353a21"; pn_configuration.SubscribeKey = "sub-c-5b8e3a72-8796-11ea-b883-d2d532c9a1bf"; pn_configuration.LogVerbosity = PNLogVerbosity.BODY; pn_configuration.UUID = System.Guid.NewGuid().ToString(); pubnub = new PubNub(pn_configuration); // Add listener to submit button to send messages Button btn = submit_button.GetComponent <Button>(); btn.onClick.AddListener(task_on_click); // Fetch the last 13 messages sent on the given PubNub channel pubnub.FetchMessages().Channels(new List <string> { "chatchannel13" }).Count(10).Async((result, status) => { if (status.Error) { Debug.Log(string.Format("Fetch Messages Error: {0} {1} {2}", status.StatusCode, status.ErrorData, status.Category)); } else { foreach (KeyValuePair <string, List <PNMessageResult> > kvp in result.Channels) { foreach (PNMessageResult pn_message_result in kvp.Value) { // Format Data into readable format JSONInformation chatmessage = JsonUtility.FromJson <JSONInformation>(pn_message_result.Payload.ToString()); // Call the function to display the message in plaintext create_chat(chatmessage); // Counter used for positioning the text UI if (counter != 200) { counter += 20; } } } } }); // Subscribe to a PubNub Channel to receive messages when they are sent on that channel pubnub.Subscribe().Channels(new List <string>() { "chatchannel13" }).WithPresence().Execute(); // This is the subscribe callback function where data is received that is received on the channel pubnub.SubscribeCallback += (sender, e) => { SubscribeEventEventArgs message = e as SubscribeEventEventArgs; if (message.MessageResult != null) { // Format data into readable format JSONInformation chatmessage = JsonUtility.FromJson <JSONInformation>(message.MessageResult.Payload.ToString()); // Call the function to display the message in plaintext create_chat(chatmessage); // When a new Chat is created, remove the first chat and transform all the messages on the page up sync_chat(); // Counter used for positioning the text UI if (counter != 200) { counter += 20; } } }; }
void Start() { PNConfiguration pnConfiguration = new PNConfiguration(); pnConfiguration.SubscribeKey = subKey; pnConfiguration.PublishKey = pubKey; pnConfiguration.UUID = myID; pnConfiguration.Secure = true; dataServer = new PubNub(pnConfiguration); if (myID == "player1") { ListenForPlayers2 script1 = Player1.GetComponent <ListenForPlayers2>(); script1.enabled = true; ListenForPlayers script2 = this.GetComponent <ListenForPlayers>(); script2.enabled = false; } else if (myID == "player2") { ListenForPlayers2 script1 = Player1.GetComponent <ListenForPlayers2>(); script1.enabled = true; ListenForPlayers script2 = this.GetComponent <ListenForPlayers>(); script2.enabled = false; } else { ListenForPlayers script2 = this.GetComponent <ListenForPlayers>(); script2.enabled = true; ListenForPlayers2 script1 = Player1.GetComponent <ListenForPlayers2>(); script1.enabled = false; } rb2.MovePosition(startpos); dataServer.Subscribe() .Channels(new List <string>() { subscribeChannel }) .Execute(); dataServer.SubscribeCallback += (sender, e) => { SubscribeEventEventArgs inMessage = e as SubscribeEventEventArgs; if (inMessage.MessageResult != null) //error check to insure the message has contents { //save the UUID of the last sender lastSender = inMessage.MessageResult.IssuingClientId; //save the message into a Dictionary Dictionary <string, object> msg = inMessage.MessageResult.Payload as Dictionary <string, object>; //retrieve and convert the value you need using the key name /* * convert to integer - (int)msg["keyName"] * convert to float - (float)msg["keyName"] * convert to string - (string)msg["keyName"] * */ xVal = (float)(double)msg["x"]; yVal = (float)(double)msg["y"]; Debug.Log($"x:{msg["x"]} y:{msg["y"]}"); } }; }
//public InputField FieldUsername; //public InputField FieldScore; //public Object[] tiles = {} // Use this for initialization void Start() { //Button btn = SubmitButton.GetComponent<Button>(); //btn.onClick.AddListener(TaskOnClick); // Use this for initialization PNConfiguration pnConfiguration = new PNConfiguration(); pnConfiguration.PublishKey = "pub-c-552fdd0f-5c19-4557-baa4-1f8c2263b4ed"; pnConfiguration.SubscribeKey = "sub-c-b55b4074-8312-11e9-84b9-2e401b25e788"; pnConfiguration.LogVerbosity = PNLogVerbosity.BODY; pnConfiguration.UUID = Random.Range(0f, 999999f).ToString(); pubnub = new PubNub(pnConfiguration); Debug.Log(pnConfiguration.UUID); MyClass myFireObject = new MyClass(); myFireObject.test = "Player 1"; string fireobject = JsonUtility.ToJson(myFireObject); pubnub.Fire() .Channel("beach_cg_channel") .Message(fireobject) .Async((result, status) => { if (status.Error) { Debug.Log(status.Error); Debug.Log(status.ErrorData.Info); } else { Debug.Log(string.Format("Fire Timetoken: {0}", result.Timetoken)); } }); pubnub.SusbcribeCallback += (sender, e) => { SusbcribeEventEventArgs mea = e as SusbcribeEventEventArgs; if (mea.Status != null) { } if (mea.MessageResult != null) { Dictionary <string, object> msg = mea.MessageResult.Payload as Dictionary <string, object>; string[] strArr = msg["username"] as string[]; string[] strScores = msg["score"] as string[]; int usernamevar = 1; foreach (string username in strArr) { string usernameobject = "Line" + usernamevar; GameObject.Find(usernameobject).GetComponent <Text>().text = usernamevar.ToString() + ". " + username.ToString(); usernamevar++; Debug.Log(username); } int scorevar = 1; foreach (string score in strScores) { string scoreobject = "Score" + scorevar; GameObject.Find(scoreobject).GetComponent <Text>().text = "Score: " + score.ToString(); scorevar++; Debug.Log(score); } } if (mea.PresenceEventResult != null) { Debug.Log("In Example, SusbcribeCallback in presence" + mea.PresenceEventResult.Channel + mea.PresenceEventResult.Occupancy + mea.PresenceEventResult.Event); } }; pubnub.Subscribe() .Channels(new List <string> () { "beach_cg_channel" }) .WithPresence() .Execute(); }
// Use this for initialization void Start() { Button btn = SubmitButton.GetComponent <Button> (); btn.onClick.AddListener(TaskOnClick); // Use this for initialization PNConfiguration pnConfiguration = new PNConfiguration(); pnConfiguration.PublishKey = "pub-c-36e8fff3-a450-4b43-98be-5a14f10c69b4"; pnConfiguration.SubscribeKey = "sub-c-68d3c0d8-9b58-11e9-9ac8-0ed882abeb26"; pnConfiguration.LogVerbosity = PNLogVerbosity.BODY; pnConfiguration.UUID = Random.Range(0f, 999999f).ToString(); pubnub = new PubNub(pnConfiguration); Debug.Log(pnConfiguration.UUID); MyClass myFireObject = new MyClass(); myFireObject.test = "new user"; string fireobject = JsonUtility.ToJson(myFireObject); pubnub.Fire() .Channel("my_channel") .Message(fireobject) .Async((result, status) => { if (status.Error) { Debug.Log(status.Error); Debug.Log(status.ErrorData.Info); } else { Debug.Log(string.Format("Fire Timetoken: {0}", result.Timetoken)); } }); pubnub.SusbcribeCallback += (sender, e) => { SusbcribeEventEventArgs mea = e as SusbcribeEventEventArgs; if (mea.Status != null) { } if (mea.MessageResult != null) { Dictionary <string, object> msg = mea.MessageResult.Payload as Dictionary <string, object>; string[] strArr = msg["username"] as string[]; string[] strScores = msg["score"] as string[]; string[] strTimes = msg["time"] as string[]; for (int i = 0; i < names.Length; i++) { names[i].text = strArr[i]; scores[i].text = strScores[i]; times[i].text = strTimes[i]; } // Hide submit stuff if score not high enough if (ScoreCounter.Score <= int.Parse(strScores[4])) { HighScoreFields.SetActive(false); } } if (mea.PresenceEventResult != null) { Debug.Log("In Example, SusbcribeCallback in presence" + mea.PresenceEventResult.Channel + mea.PresenceEventResult.Occupancy + mea.PresenceEventResult.Event); } }; pubnub.Subscribe() .Channels(new List <string> () { "my_channel2" }) .WithPresence() .Execute(); }
// Use this for initialization void Start() { Debug.Log(PlayerPrefs.GetString("EMAIL")); Debug.Log(PlayerPrefs.GetInt("Score")); publishKey = "pub-c-ed03b041-dbd1-4421-af39-404baa9fdcce"; subscribeKey = "sub-c-22588262-e977-11e8-8495-720743810c32"; Button btn = SubmitButton.GetComponent <Button>(); btn.onClick.AddListener(TaskOnClick); // Use this for initialization PNConfiguration pnConfiguration = new PNConfiguration(); pnConfiguration.PublishKey = publishKey; pnConfiguration.SubscribeKey = subscribeKey; pnConfiguration.LogVerbosity = PNLogVerbosity.BODY; pnConfiguration.UUID = Random.Range(0f, 999999f).ToString(); pubnub = new PubNub(pnConfiguration); Debug.Log(pnConfiguration.UUID); MyClass myFireObject = new MyClass(); myFireObject.test = "new user"; string fireobject = JsonUtility.ToJson(myFireObject); pubnub.Fire() .Channel("LEaderBoardchannel") .Message(fireobject) .Async((result, status) => { if (status.Error) { Debug.Log(status.Error); Debug.Log(status.ErrorData.Info); log.text = status.Error.ToString(); } else { Debug.Log(string.Format("Fire Timetoken: {0}", result.Timetoken)); log.text = string.Format("Fire Timetoken: {0}", result.Timetoken); } }); pubnub.SusbcribeCallback += (sender, e) => { SusbcribeEventEventArgs mea = e as SusbcribeEventEventArgs; if (mea.Status != null) { log.text = "called mea.status"; } if (mea.MessageResult != null) { log.text = "called mea.status"; Debug.Log("Entered in Mea.Subscribe"); Dictionary <string, object> msg = mea.MessageResult.Payload as Dictionary <string, object>; string[] strArr = msg["username"] as string[]; string[] strScores = msg["score"] as string[]; int usernamevar = 1; foreach (string username in strArr) { string usernameobject = "Line" + usernamevar; GameObject.Find(usernameobject).GetComponent <Text>().text = usernamevar.ToString() + ". " + username.ToString(); usernamevar++; Debug.Log(username); log.text = "username: "******""; } int scorevar = 1; foreach (string score in strScores) { string scoreobject = "Score" + scorevar; GameObject.Find(scoreobject).GetComponent <Text>().text = "Score: " + score.ToString(); scorevar++; Debug.Log(score); log.text = "score: " + score + ""; } } if (mea.PresenceEventResult != null) { Debug.Log("In Example, SusbcribeCallback in presence" + mea.PresenceEventResult.Channel + mea.PresenceEventResult.Occupancy + mea.PresenceEventResult.Event); } }; pubnub.Subscribe() .Channels(new List <string>() { "LEaderBoardchannel" }) .WithPresence() .Execute(); }