using System.Collections; using System.Collections.Generic; using UnityEngine; using Grpc.Core; using System.IO; public class GrpcChannelContronller : MonoSingletonDontDestory { 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(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("服务器已断开"); } }