12345678910111213141516171819202122232425262728293031323334353637383940 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Grpc.Core;
- using System.IO;
- public class GrpcChannelContronller : MonoSingletonDontDestory<GrpcChannelContronller>
- {
- private Channel channel;
- public Operate.OperateClient client;
- //public void Awake ()
- //{
- // string clientConfigFilePath = Path.Combine(Application.streamingAssetsPath, "GrpcServerConfig.cfg");
- // Debug.Log(File.ReadAllText(clientConfigFilePath));
- // GrpcServerConfig clientConfig = JsonHelper.DeserializeJsonToObject<GrpcServerConfig>(File.ReadAllText(clientConfigFilePath));
- // Debug.Log("开始连接!!");
- // Debug.Log(clientConfig.GrpcServerIp + ":" + clientConfig.GrpcServerPort);
- // string target = clientConfig.GrpcServerIp + ":" + clientConfig.GrpcServerPort;
- // channel = new Channel(target, ChannelCredentials.Insecure);
- // client = new Operate.OperateClient(channel);
- //}
- public void StartClient(string GrpcAddress)
- {
- channel = new Channel(GrpcAddress, ChannelCredentials.Insecure);
- client = new Operate.OperateClient(channel);
- }
- private void OnDestroy()
- {
- //channel.ShutdownAsync().Wait();
- Debug.Log("服务器已断开");
- }
- }
|