public void OnGUI()
        {
            _oldType = EditorDataFields.EditorDataField("旧的类型", _oldType);
            _newType = EditorDataFields.EditorDataField("新的类型", _newType);

            if (string.IsNullOrEmpty(_oldType) || string.IsNullOrEmpty(_newType))
            {
                return;
            }

            using (new EditorHorizontalLayout("Box"))
            {
                if (GUILayout.Button("替换客户端"))
                {
                    EditorUtility.DisplayDialog("错误", "功能未实现", "关闭");
                }

                if (GUILayout.Button("替换服务器"))
                {
                    if (!EditorUtility.DisplayDialog("警告", "修改后不能够回退,是否确认修改", "OK", "CANCEL"))
                    {
                        return;
                    }
                    string   path  = EditorTreeConfigHelper.Instance.Config.ServersPath;
                    string[] files = Directory.GetFiles(path, "*.txt");

                    foreach (string file in files)
                    {
                        try
                        {
                            StreamReader reader = new StreamReader(file);
                            string       data   = reader.ReadToEnd();
                            NodeProto    p      = MongoHelper.FromJson <NodeProto>(data);
                            p = TypeReplace(_oldType, _newType, p);
                            reader.Close();
                            StreamWriter writer = new StreamWriter(file);
                            writer.Write(MongoHelper.ToJson(p));
                            writer.Close();
                        }
                        catch (Exception err)
                        {
                            BehaviourTreeDebugPanel.Error($"文件({file})无法解析成行为树");
                            Log.Error(err);
                        }
                    }

                    EditorUtility.DisplayDialog("信息", "替换完成", "OK");
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Rpc请求
        /// </summary>
        public Task <T> RpcCall <T, K>(string address, K request, int waitTime = 0)
        {
            AChannel channel = this.service.GetChannel(address);

            ++this.requestId;
            byte[] requestBuffer = MongoHelper.ToBson(request);
            Opcode opcode        = EnumHelper.FromString <Opcode>(request.GetType().Name);

            byte[] opcodeBuffer = BitConverter.GetBytes((ushort)opcode);
            byte[] idBuffer     = BitConverter.GetBytes(this.requestId);
            channel.SendAsync(new List <byte[]> {
                opcodeBuffer, idBuffer, requestBuffer
            });
            var tcs = new TaskCompletionSource <T>();

            this.requestCallback[this.requestId] = (messageBytes, status) =>
            {
                switch (status)
                {
                case RpcResponseStatus.Timeout:
                    tcs.SetException(new Exception($"rpc timeout {opcode} {MongoHelper.ToJson(request)}"));
                    return;

                case RpcResponseStatus.Exception:
                    BinaryFormatter formatter = new BinaryFormatter(null, new StreamingContext(StreamingContextStates.All));
                    Exception       exception;
                    using (MemoryStream stream = new MemoryStream(messageBytes, 6, messageBytes.Length - 6))
                    {
                        exception = (Exception)formatter.Deserialize(stream);
                    }
                    tcs.SetException(exception);
                    return;
                }

                // RpcResponseStatus.Succee
                T response = MongoHelper.FromBson <T>(messageBytes, 6);
                tcs.SetResult(response);
            };

            if (waitTime > 0)
            {
                this.service.Timer.Add(TimeHelper.Now() + waitTime,
                                       () => { this.RpcCallback(channel, this.requestId, null, RpcResponseStatus.Timeout); });
            }
            return(tcs.Task);
        }
Пример #3
0
        private void SendMessage(object message)
        {
            Log.Debug($"send: {MongoHelper.ToJson(message)}");
            ushort opcode = this.network.Entity.GetComponent <OpcodeTypeComponent>().GetOpcode(message.GetType());

            byte[] messageBytes = this.network.MessagePacker.SerializeToByteArray(message);
            if (messageBytes.Length > 100)
            {
                byte[] newMessageBytes = ZipHelper.Compress(messageBytes);
                if (newMessageBytes.Length < messageBytes.Length)
                {
                    messageBytes = newMessageBytes;
                    opcode      |= 0x8000;
                }
            }

            byte[] opcodeBytes = BitConverter.GetBytes(opcode);

            this.byteses[0] = opcodeBytes;
            this.byteses[1] = messageBytes;
            channel.Send(this.byteses);
        }
Пример #4
0
 public override string ToString()
 {
     return(MongoHelper.ToJson(this));
 }
Пример #5
0
        public async Task StartAsync()
        {
            using (UnityWebRequestAsync request = EntityFactory.Create <UnityWebRequestAsync>())
            {
                string versionUrl = GlobalConfigComponent.Instance.GlobalProto.GetUrl() + "StreamingAssets/" + "Version.txt";
                Log.Debug(versionUrl);
                await request.DownloadAsync(versionUrl);

                this.VersionConfig = MongoHelper.FromJson <VersionConfig>(request.Request.downloadHandler.text);
            }

            Log.Debug("WebVersion:\n" + MongoHelper.ToJson(this.VersionConfig));

            // 对比本地的Version.txt
            string versionPath = Path.Combine(PathHelper.AppHotfixResPath, "Version.txt");

            if (!File.Exists(versionPath))
            {
                foreach (FileVersionInfo versionInfo in this.VersionConfig.FileVersionInfos)
                {
                    if (versionInfo.File == "Version.txt")
                    {
                        continue;
                    }
                    this.bundles.Enqueue(versionInfo.File);
                    this.TotalSize += versionInfo.Size;
                }
            }
            else
            {
                VersionConfig localVersionConfig = MongoHelper.FromJson <VersionConfig>(File.ReadAllText(versionPath));
                Log.Debug("LocalVersion:\n" + MongoHelper.ToJson(localVersionConfig));
                // 先删除服务器端没有的ab
                foreach (FileVersionInfo fileVersionInfo in localVersionConfig.FileVersionInfos)
                {
                    if (this.VersionConfig.FileInfoDict.ContainsKey(fileVersionInfo.File))
                    {
                        continue;
                    }
                    string abPath = Path.Combine(PathHelper.AppHotfixResPath, fileVersionInfo.File);
                    File.Delete(abPath);
                }

                // 再下载
                foreach (FileVersionInfo fileVersionInfo in this.VersionConfig.FileVersionInfos)
                {
                    FileVersionInfo localVersionInfo;
                    if (localVersionConfig.FileInfoDict.TryGetValue(fileVersionInfo.File, out localVersionInfo))
                    {
                        if (fileVersionInfo.MD5 == localVersionInfo.MD5)
                        {
                            continue;
                        }
                    }

                    if (fileVersionInfo.File == "Version.txt")
                    {
                        continue;
                    }

                    this.bundles.Enqueue(fileVersionInfo.File);
                    this.TotalSize += fileVersionInfo.Size;
                }
            }

            if (this.bundles.Count == 0)
            {
                return;
            }

            Log.Debug($"need download bundles: {this.bundles.ToList().ListToString()}");
            await this.WaitAsync();
        }
Пример #6
0
 public string SerializeToText(object obj)
 {
     return(MongoHelper.ToJson(obj));
 }
Пример #7
0
 public object Clone()
 {
     return(MongoHelper.FromJson <StartConfig>(MongoHelper.ToJson(this)));
 }
Пример #8
0
 public static string ToJson(object obj)
 {
     return(MongoHelper.ToJson(obj));
 }