public void MovingRequest(Vector3 Position, Quaternion Rotation) { MessageMove move = new MessageMove(Position, Rotation.eulerAngles); move.NetworkID = MyID; SendMessage(move); }
private void OnMove(MessageMove data) { ExampleSimpleGameSettings settings = ExampleSimpleGameSettings.settings(); m_position.x = data.x * settings.areaWidth; m_position.z = settings.areaHeight - (data.y * settings.areaHeight) - 1; // because in 2D down is positive. gameObject.transform.localPosition = m_position; }
private void OnMove(MessageMove data) { ExampleCameraGameSettings settings = ExampleCameraGameSettings.settings(); m_position.x = data.x * settings.areaWidth; m_position.z = settings.areaHeight - (data.y * settings.areaHeight) - 1; // because in 2D down is positive. gameObject.transform.localPosition = m_position; }
public void OnMoveMessage(MessageMove message) { ClientKeys key = GetClientKeyInformation(message.NetworkID); Clients [key].State.Stats.Position = message.Position; Clients [key].State.Stats.Rotation = Quaternion.Euler(message.Rotation); string s = JsonUtility.ToJson(message); BroadcastingMessage(s); }
IEnumerator SendInputToServer() { while (true) { MessageMove message = new MessageMove(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), false); SendToServer(ByteSerializer.GetBytes(message), SendType.Unreliable); yield return(new WaitForSecondsRealtime(1.0f / inputsPerSec)); } }
protected override void OnServerReceivedMessageRaw(byte[] data, ulong steamID) { MessageMove message = ByteSerializer.FromBytes <MessageMove>(data); horizontalInput = message.horizontalInput; verticalInput = message.verticalInput; jump = message.jump; if (jump) { Vector3 jumpForce = jumpHeight * Vector3.up; GetComponent <Rigidbody>().AddForce(jumpForce, ForceMode.VelocityChange); } }
protected override void UpdateClient() { if (Input.GetKeyDown(KeyCode.Space)) { MessageMove message = new MessageMove(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), true); SendToServer(ByteSerializer.GetBytes(message), SendType.Reliable); } if (Input.GetKeyDown(KeyCode.I)) { networkObject.interpolateOnClient = true; } if (Input.GetKeyDown(KeyCode.O)) { networkObject.interpolateOnClient = false; } }
void OnMoveMessage(MessageMove message) { //自己的方法 if (message.NetworkID == MyID) { return; float distance = Vector3.Distance(transform.position, message.Position); if (distance > 3) { Debug.Log("Name" + clients [MyID].unit); clients [MyID].unit.transform.SetPositionAndRotation(message.Position, Quaternion.Euler(message.Rotation)); } } else //别人的方法 { clients[message.NetworkID].unit.Moving(message.Position, Quaternion.Euler(message.Rotation)); } }
public abstract void OnMove(MessageMove data);
void OnMove(MessageMove data) { m_direction = data.dir; }
public static void SendMove(MessageMove msg) { MessageControl.SendMove(msg); }
public static void ReceiveMove(MessageMove msg) { GameFlow.OnMove(msg); }
public override void OnMove(MessageMove data) { m_direction = data.dir; }
void OnMove(MessageMove data) { m_direction = data.dir; }
private static Race LoadRace(PropertyBag raceProp, DropMacroCollection <Item> dropMacros, Content content, out int depth, out int rarity) { Character character = new Character('*', TermColor.Purple); PropertyBag art; if (raceProp.TryGetValue("art", out art)) { //### bob: old style color and glyph combined character = Character.Parse(art.Value); } else { // separate glyph and color character = new Character( Character.ParseGlyph(raceProp["glyph"].Value), TermColors.FromName(raceProp["color"].Value)); } // depth depth = raceProp["depth"].ToInt32(); // speed int speed = raceProp.GetOrDefault("speed", 0) + Energy.NormalSpeed; // health Roller health = Roller.Parse(raceProp["health"].Value); // rarity rarity = raceProp.GetOrDefault("rarity", 1); // create the race Race race = new Race(content, raceProp.Name, depth, character, speed, health); // attacks PropertyBag attacks; if (raceProp.TryGetValue("attacks", out attacks)) { foreach (PropertyBag attackProp in attacks) { string[] attackParts = attackProp.Value.Split(' '); // create the attack Roller damage = Roller.Parse(attackParts[0]); FlagCollection flags = new FlagCollection(); Element element = Element.Anima; // add the flags or element for (int i = 1; i < attackParts.Length; i++) { try { // see if the part is an element element = (Element)Enum.Parse(typeof(Element), attackParts[i], true); } catch (ArgumentException) { // must be a flag flags.Add(attackParts[i]); } } //### bob: need to support different effect types Attack attack = new Attack(damage, 0, 1.0f, element, attackProp.Name, EffectType.Hit, flags); race.Attacks.Add(attack); } } // moves PropertyBag moves; if (raceProp.TryGetValue("moves", out moves)) { foreach (PropertyBag moveProp in moves) { string moveName = moveProp.Name; // if an explicit move field is provided, then the prop name is not the name of the move itself PropertyBag explicitMove; if (moveProp.TryGetValue("move", out explicitMove)) { moveName = explicitMove.Value; } // parse the specific move info MoveInfo info = ParseMove(moveProp); Move move; // construct the move switch (moveName) { case "haste self": move = new HasteSelfMove(); break; case "ball self": move = new BallSelfMove(); break; case "cone": move = new ElementConeMove(); break; case "breathe": move = new BreatheMove(); break; case "bolt": move = new BoltMove(); break; case "message": move = new MessageMove(); break; case "breed": move = new BreedMove(); break; default: throw new Exception("Unknown move \"" + moveName + "\"."); } move.BindInfo(info); race.Moves.Add(move); } } // flags foreach (PropertyBag childProp in raceProp) { if (childProp.Name.StartsWith("+ ")) { string flag = childProp.Name.Substring(2).Trim(); // handle the flags switch (flag) { case "groups": race.SetGroupSize(GroupSize.Group); break; case "packs": race.SetGroupSize(GroupSize.Pack); break; case "swarms": race.SetGroupSize(GroupSize.Swarm); break; case "hordes": race.SetGroupSize(GroupSize.Horde); break; case "very-bright": race.SetLightRadius(2); break; case "bright": race.SetLightRadius(1); break; case "glows": race.SetLightRadius(0); break; case "unmoving": race.SetPursue(Pursue.Unmoving); break; case "slightly-erratic": race.SetPursue(Pursue.SlightlyErratically); break; case "erratic": race.SetPursue(Pursue.Erratically); break; case "very-erratic": race.SetPursue(Pursue.VeryErratically); break; case "unique": race.SetFlag(RaceFlags.Unique); break; case "boss": race.SetFlag(RaceFlags.Boss); break; case "opens-doors": race.SetFlag(RaceFlags.OpensDoors); break; default: Console.WriteLine("Unknown flag \"{0}\"", flag); break; } } } // resists PropertyBag resists; if (raceProp.TryGetValue("resists", out resists)) { ParseResists(resists.Value, race); } // drops PropertyBag drops; if (raceProp.TryGetValue("drops", out drops)) { var parser = new ItemDropParser(content); IDrop <Item> drop = parser.ParseDefinition(drops, dropMacros); race.SetDrop(drop); } // description PropertyBag description; if (raceProp.TryGetValue("description", out description)) { race.SetDescription(description.Value); } // groups PropertyBag groups; if (raceProp.TryGetValue("groups", out groups)) { race.SetGroups(groups.Value.Split(' ')); } return(race); }
public void DecodeMessage(Socket sender, byte[] Message, int count) { string message = System.Text.Encoding.Default.GetString(Message); // string[] s = message.Split ('"'); // string type = s [3]; // //判断数据类型 // //TODO 你永远也更新不完 // if (type == "MessageMove") { // try { // MessageMove move = (MessageMove)JsonUtility.FromJson (message, Type.GetType (s [3])); // OnMoveMessage (move); // } catch { // Debug.Log (message); // } // } else if (type == "MessageAttack") { // MessageAttack Attack = (MessageAttack)JsonUtility.FromJson (message, Type.GetType (s [3])); // OnAttackMessage (Attack); // } else if (type == "MessageChangingWeapon") { // MessageChangingWeapon change = (MessageChangingWeapon)JsonUtility.FromJson (message, Type.GetType (s [3])); // OnChangingWeaponMessage (change); // } // else if (type == "MessageDamage") // { // MessageDamage Damage = (MessageDamage)JsonUtility.FromJson(message, Type.GetType(s[3])); // OnDamageMessage(Damage); // } // else if (type == "MessagePlayerDead") // { // MessagePlayerDead dead = (MessagePlayerDead)JsonUtility.FromJson(message, Type.GetType(s[3])); // OnPlayerDeadMessage(dead); // } // else if (type == "MessageClientsStats") // { // MessageClientsStats Stats = (MessageClientsStats)JsonUtility.FromJson(message, Type.GetType(s[3])); // OnNewClientMessage(Stats); // } // else if (type == "MessageRespawnPlayer") // { // MessageRespawnPlayer respawn = (MessageRespawnPlayer)JsonUtility.FromJson(message, Type.GetType(s[3])); // OnRespawnPlayer(respawn); // } string[] s = message.Split('$'); foreach (string text in s) { try { MessageBase TempBase = JsonUtility.FromJson <MessageBase> (text); MessageBase MsgBase = (MessageBase)JsonUtility.FromJson(text, Type.GetType(TempBase.ProtoName)); if (typeof(MessageMove).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageMove move = (MessageMove)MsgBase; OnMoveMessage(move); } else if (typeof(MessageAttack).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageAttack attack = (MessageAttack)MsgBase; OnAttackMessage(attack); } else if (typeof(MessageBuildingAttack).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageBuildingAttack attack = (MessageBuildingAttack)MsgBase; OnBuildingAttackMessage(attack); } else if (typeof(MessageBuildingFocusing).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageBuildingFocusing focus = (MessageBuildingFocusing)MsgBase; OnBuildingFocusingMessage(focus); } else if (typeof(MessageInteractiveStart).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageInteractiveStart interactive = (MessageInteractiveStart)MsgBase; OnInteractiveStartMessage(interactive); } else if (typeof(MessageInteractiveExit).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageInteractiveExit interactive = (MessageInteractiveExit)MsgBase; OnInteractiveExitMessage(interactive); } else if (typeof(MessageChangingWeapon).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageChangingWeapon Stats = (MessageChangingWeapon)MsgBase; OnChangingWeaponMessage(Stats); } else if (typeof(MessageDamage).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageDamage Stats = (MessageDamage)MsgBase; OnDamageMessage(Stats); } else if (typeof(MessagePlayerDead).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessagePlayerDead dead = (MessagePlayerDead)MsgBase; OnPlayerDeadMessage(dead); } else if (typeof(MessageClientsStats).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageClientsStats Stats = (MessageClientsStats)MsgBase; OnNewClientMessage(sender, Stats); } else if (typeof(MessageRespawnPlayer).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageRespawnPlayer respawn = (MessageRespawnPlayer)MsgBase; OnRespawnPlayer(respawn); } else if (typeof(MessageRespawnConstruction).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageRespawnConstruction respawn = (MessageRespawnConstruction)MsgBase; OnConstructionRespawn(respawn); } else if (typeof(MessageChat).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageChat chat = (MessageChat)MsgBase; OnChattingMessage(chat); } else { Debug.Log("未知数据类型,该数据为:" + text + ",服务器已做丢包处理.或者说,你忘记处理了?"); } }catch (ArgumentException ex) { }catch (Exception ex) { Debug.LogError("协议包无法解析!出错报告为:" + ex.ToString()); Debug.LogError("数据包为:" + text); } } }
public static void OnMove(MessageMove msg) { playerControl.OnMove(msg.Id, msg.To); GameFlowControl.SendMove(msg); }
public void FiringMessage(string s) { string[] message = s.Split('$'); foreach (string text in message) { try { if (text.Length < 4) { return; } MessageBase TempBase = JsonUtility.FromJson <MessageBase> (text); MessageBase MsgBase = (MessageBase)JsonUtility.FromJson(text, Type.GetType(TempBase.ProtoName)); //批发处理 if (typeof(MessageMove).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageMove move = (MessageMove)MsgBase; OnMoveMessage(move); } else if (typeof(MessageAttack).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageAttack attack = (MessageAttack)MsgBase; OnAttackMessage(attack); } else if (typeof(MessageBuildingAttack).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageBuildingAttack attack = (MessageBuildingAttack)MsgBase; OnBuildingAttackMessage(attack); } else if (typeof(MessageBuildingFocusing).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageBuildingFocusing focus = (MessageBuildingFocusing)MsgBase; OnBuildingFocusMessage(focus); } else if (typeof(MessageInteractiveStart).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageInteractiveStart interactive = (MessageInteractiveStart)MsgBase; OnInteractiveStartMessage(interactive); } else if (typeof(MessageInteractiveExit).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageInteractiveExit interactive = (MessageInteractiveExit)MsgBase; OnInteractiveExitMessage(interactive); } else if (typeof(MessageRespawnConstruction).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageRespawnConstruction respawn = (MessageRespawnConstruction)MsgBase; OnConstructionRespawn(respawn); } else if (typeof(MessageChangingWeapon).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageChangingWeapon Stats = (MessageChangingWeapon)MsgBase; OnChangeingWeaponMessage(Stats); } else if (typeof(MessageDamage).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageDamage Stats = (MessageDamage)MsgBase; OnDamageMessage(Stats); } else if (typeof(MessagePlayerDead).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessagePlayerDead dead = (MessagePlayerDead)MsgBase; OnPlayerDeadMessage(dead); } else if (typeof(MessageClientsStats).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageClientsStats Stats = (MessageClientsStats)MsgBase; OnNewClientMessage(Stats); } else if (typeof(MessageRespawnPlayer).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageRespawnPlayer respawn = (MessageRespawnPlayer)MsgBase; OnRespawnPlayer((MessageRespawnPlayer)MsgBase); } else if (typeof(MessageLeaveGame).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageLeaveGame leave = (MessageLeaveGame)MsgBase; OnPlayerLeaveGame(leave); } else if (typeof(MessageChat).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageChat chat = (MessageChat)MsgBase; OnPlayerChatting(chat); } else { Debug.Log("未知数据类型,该数据为:" + MsgBase.ToString() + ",记得处理!"); } }catch (ArgumentException ex) { }catch (Exception ex) { Debug.LogError("协议包无法解析!出错报告为:" + ex.ToString()); Debug.LogError("数据包为:" + text); } } }
void OnMove(MessageMove data) { messageReceiver.OnMove(data); }