You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

MessageReceiver.cs 2.5 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Grpc.Core;
  5. using Google.Protobuf;
  6. using Protobuf;
  7. using System.Data;
  8. //using UnityEditor.U2D.Path;
  9. public class MessageReceiver : MonoBehaviour
  10. {
  11. private static int studentNum = 2;
  12. // Start is called before the first frame update
  13. async void Start()
  14. {
  15. var channel = new Channel("127.0.0.1:8888", ChannelCredentials.Insecure);
  16. var client = new AvailableService.AvailableServiceClient(channel);
  17. PlayerMsg msg = new PlayerMsg();
  18. msg.PlayerType = PlayerType.StudentPlayer;
  19. msg.PlayerId = 3000;
  20. map = null;
  21. var response = client.AddPlayer(msg);
  22. //while (await response.ResponseStream.MoveNext())
  23. //{
  24. // var responseVal = response.ResponseStream.Current;
  25. // if (isMap)
  26. // {
  27. // map = responseVal.ObjMessage[0].MapMessage;
  28. // //Debug.Log(map.ToString());
  29. // isMap = false;
  30. // for (int i = 0; i < studentNum; i++)
  31. // Instantiate(student_1, new Vector3(0f, 0f, 10.0f), new Quaternion(0, 0, 0, 0));
  32. // }
  33. // else
  34. // {
  35. // for (int i = 0; i < studentNum; i++)
  36. // {
  37. // Student[i] = responseVal.ObjMessage[i].StudentMessage;
  38. // }
  39. // }
  40. //}
  41. if(await response.ResponseStream.MoveNext())
  42. {
  43. var responseVal = response.ResponseStream.Current;
  44. map = responseVal.ObjMessage[0].MapMessage;
  45. }
  46. if (await response.ResponseStream.MoveNext())
  47. {
  48. var responseVal = response.ResponseStream.Current;
  49. for (int i = 0; i < studentNum; i++)
  50. {
  51. Student[i] = responseVal.ObjMessage[i].StudentMessage;
  52. Instantiate(student_1, new Vector3(0f, 0f, 10.0f), new Quaternion(0, 0, 0, 0));
  53. }
  54. }
  55. while(await response.ResponseStream.MoveNext())
  56. {
  57. var responseVal = response.ResponseStream.Current;
  58. for(int i=0;i<studentNum;i++)
  59. {
  60. Student[i] = responseVal.ObjMessage[i].StudentMessage;
  61. }
  62. }
  63. }
  64. // Update is called once per frame
  65. void Update()
  66. {
  67. }
  68. public static MessageOfMap map;
  69. public static MessageOfStudent[] Student = new MessageOfStudent[studentNum];
  70. public GameObject student_1;
  71. }