public void AddClientScript() { if (Network.IsServer || Network.IsClient) { return; } Network.SetupClient(Network.ServerIP, Network.ServerPort); GameObject clientScriptObject = new GameObject(); clientScript = clientScriptObject.AddComponent <ClientMonkScript>(); }
public ClientMonkScript() { Instance = this; Client.MessageReceivedEvent += Client_MessageReceivedEvent; Parser.AddRule(MessageType.HandshakeAck, (Message receivedMessage, Received data) => { RWConsole.LogInfo("Handshake acknowledged!"); }); Parser.AddRule(MessageType.RemotePlayerAnimation, (Message receivedMessage, Received data) => { string[] anim = receivedMessage.Contents.Split('|'); string username = anim[0]; int animation = int.Parse(anim[1]); int frame = int.Parse(anim[2]); Player.AnimationIndex animationIndex = (Player.AnimationIndex)animation; typeof(Player).GetProperty("animationFrame").SetValue(RemotePlayers[username].Player, frame, null); RemotePlayers[username].Animation = animationIndex; }); Parser.AddRule(MessageType.RemotePlayerChunkPosition, (Message receivedMessage, Received data) => { string[] pos = receivedMessage.Contents.Split('|', ','); string username = pos[0]; int chunkIndex = int.Parse(pos[1]); if (!float.TryParse(pos[4], out float rx)) { RWConsole.LogError("Bad chunkrotation x"); } if (!float.TryParse(pos[5], out float ry)) { RWConsole.LogError("Bad chunkrotation y"); } if (!float.TryParse(pos[6], out float velx)) { RWConsole.LogError("Bad velocity x"); } if (!float.TryParse(pos[7], out float vely)) { RWConsole.LogError("Bad velocity y"); } Vector2 chunkPosition = new Vector2(float.Parse(pos[2]), float.Parse(pos[3])); Vector2 chunkRotation = new Vector2(rx, ry); Vector2 chunkVelocity = new Vector2(velx, vely); CreateShellClientside(username); RemotePlayers[username].Creature.bodyChunks[chunkIndex].pos = chunkPosition; RemotePlayers[username].Creature.bodyChunks[chunkIndex].Rotation.Set(rx, ry); RemotePlayers[username].Creature.bodyChunks[chunkIndex].vel = chunkVelocity; }); }
public ClientMonkScript() { Instance = this; Client.MessageReceivedEvent += Client_MessageReceivedEvent; }