/// <inheritdoc/> protected override void OnMessageReceived(IncomingMessage msg) { Google.Protobuf.WellKnownTypes.Any anyMessage = null; try { anyMessage = Google.Protobuf.WellKnownTypes.Any.Parser.ParseFrom(msg.GetRawBytes()); } catch (Google.Protobuf.InvalidProtocolBufferException) { // Bad message, nothing we can do about it, so just ignore. return; } if (anyMessage.Is(TrainingEnvironmentInitialized.Descriptor)) { var envInitProto = anyMessage.Unpack <TrainingEnvironmentInitialized>(); var envInitEvent = envInitProto.ToTrainingEnvironmentInitializedEvent(); TrainingAnalytics.TrainingEnvironmentInitialized(envInitEvent); } else if (anyMessage.Is(TrainingBehaviorInitialized.Descriptor)) { var behaviorInitProto = anyMessage.Unpack <TrainingBehaviorInitialized>(); var behaviorTrainingEvent = behaviorInitProto.ToTrainingBehaviorInitializedEvent(); TrainingAnalytics.TrainingBehaviorInitialized(behaviorTrainingEvent); } // Don't do anything for unknown types, since the user probably can't do anything about it. }
public override Task <AnyMessageResponse> DoAny(AnyMessage request, ServerCallContext context) { AnyMessageResponse anyMessageResponse; switch (request.TypeUrl) { case "type.googleapis.com/any.AnyProductRequest": var product = request.Unpack <AnyProductRequest>(); anyMessageResponse = new AnyMessageResponse { Message = $"{product.Quantity} x {product.Name}" }; break; case "type.googleapis.com/any.AnyUserRequest": var user = request.Unpack <AnyUserRequest>(); anyMessageResponse = new AnyMessageResponse { Message = $"{user.Name} - {(user.Enabled ? "Enabled" : "Disabled")}" }; break; default: throw new InvalidOperationException("Unexpected type URL."); } return(Task.FromResult(anyMessageResponse)); }
//private void OnGUI() //{ // if (GUI.Button(new Rect(0, 0, 100, 30), "行走")) // { // string tag = "" + ((1 << 13) ^ (1 << 9) ^ (1 << 5)); // hashMap[tag].Transition(Item.STATE_TAG.WALK); // } // if (GUI.Button(new Rect(110, 0, 100, 30), "攻击")) // { // hashMap[tag].Transition(Item.STATE_TAG.ATTACK1); // } // if (GUI.Button(new Rect(220, 0, 100, 30), "攻击2")) // { // hashMap[tag].Transition(Item.STATE_TAG.ATTACK2); // } //} //// Update is called once per frame //void Update() //{ // //float fix = Time.deltaTime * speed; // foreach (string key in hashMap.Keys) // { // Item item = hashMap[key]; // //updateItem(item, fix); // item.Do(Time.deltaTime); // } //} //private void updateItem(Item item, float dt) //{ // if (!item.DV.IsZero()) // { // var curPos = item.GO.transform.localPosition; // item.GO.GetComponent<CharacterController>().Move(new Vector3(-dt * (float)item.DV.x, 0, -dt * (float)item.DV.z)); // transition(2); // } // else // transition(1); //} //// handleLogicTick 处理逻辑层传过来的演示数据,更新目标状态 //private void handleLogicTick(EventLogicTickList action) //{ // foreach (EventLogicTick tick in action) // { // Debug.Log("handle logic tick"); // //string tag = "" + tick.tag; // //var item = hashMap[tag]; // //if (!item.GO.CompareTag(tag)) // // continue; // //item.DV = tick.v3; // //if (tick.v3.IsZero()) // // continue; // //float radian = Mathf.Atan2(decimal.ToSingle(item.DV.z), decimal.ToSingle(item.DV.x)); // //float angle = radian / Mathf.PI * 180; // //item.GO.transform.rotation = Quaternion.Euler(0, -90.0f - angle, 0); // } //} //NOTE: 处理匹配消息完成 private void handleNetMatch(Google.Protobuf.WellKnownTypes.Any any) { WarPb.War_Match match = any.Unpack <WarPb.War_Match>(); GameObject prefab; switch (match.MapId) { default: prefab = (GameObject)Resources.Load("Prefabs/CompleteLevelArt"); break; } GameObject plane = Instantiate(prefab); SceneManager.MoveGameObjectToScene(plane, gameObject.scene); Net.WsClient.Instance.ID = match.Id; //plane.GetComponent<Views.PlaneManager>().DoMatch(match); var pm = plane.GetComponent <PlaneManager>(); pm.DoMatch(match); Driver d = gameObject.AddComponent <Driver>(); //NOTE: 添加Driver 组件,处理数据 d.M = pm.m_Meet; EventFollow.Instance.Invoke(pm.Look); }
//监听网络tick消息 private void handleNetTick(Google.Protobuf.WellKnownTypes.Any any) { M.DoNetTick(any.Unpack <WarPb.Tick>()); }