GrpcChannelContronller.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Grpc.Core;
  5. using System.IO;
  6. public class GrpcChannelContronller : MonoSingletonDontDestory<GrpcChannelContronller>
  7. {
  8. private Channel channel;
  9. public Operate.OperateClient client;
  10. //public void Awake ()
  11. //{
  12. // string clientConfigFilePath = Path.Combine(Application.streamingAssetsPath, "GrpcServerConfig.cfg");
  13. // Debug.Log(File.ReadAllText(clientConfigFilePath));
  14. // GrpcServerConfig clientConfig = JsonHelper.DeserializeJsonToObject<GrpcServerConfig>(File.ReadAllText(clientConfigFilePath));
  15. // Debug.Log("开始连接!!");
  16. // Debug.Log(clientConfig.GrpcServerIp + ":" + clientConfig.GrpcServerPort);
  17. // string target = clientConfig.GrpcServerIp + ":" + clientConfig.GrpcServerPort;
  18. // channel = new Channel(target, ChannelCredentials.Insecure);
  19. // client = new Operate.OperateClient(channel);
  20. //}
  21. public void StartClient(string GrpcAddress)
  22. {
  23. channel = new Channel(GrpcAddress, ChannelCredentials.Insecure);
  24. client = new Operate.OperateClient(channel);
  25. }
  26. private void OnDestroy()
  27. {
  28. //channel.ShutdownAsync().Wait();
  29. Debug.Log("服务器已断开");
  30. }
  31. }