void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { Application.Quit(); } GCli.Receive(); frameSpan += Time.deltaTime; if (frameSpan >= 0.1f) { frameSpan = 0; PushData push = Players.GetPushData(); if (push != null) { GCli.Send(MessageType.Push, GCli.Serialize <PushData>(push), NetDeliveryMethod.UnreliableSequenced); } } /*if(firstFrame) * { * firstFrame = false; * InitData init = GetDummyInitData(); * GameObject.Find("Canvas").GetComponent<UIScript>().SetInitData(init.bmps); * }*/ }
public void BattleStartHandler(NetConnection connection, object data) { PlayerInitDatas inits = GCli.Deserialize <PlayerInitDatas>((byte[])data); GCli.ClearPacketHandler(); room.SetActive(false); menu.SetActive(false); GCli.SetPacketHandler(MessageType.Snapshot, DataType.Bytes, SnapshotHandler); GCli.SetPacketHandler(MessageType.ReplyWon, DataType.Int32, ReplyWonHandler); GCli.SetPacketHandler(MessageType.BattleEnd, DataType.Null, BattleEndHandler); GCli.SetPacketHandler(MessageType.ReplySetBlock, DataType.Bytes, ReplySetBlockHandler); GCli.SetPacketHandler(MessageType.ReplyFire, DataType.Int32, ReplyFire); foreach (PlayerInitData init in inits.datas) { if (init.sync.userid == Players.userid) { World.SetCoreFaction(init.faction); Players.AddPlayer(init); } } foreach (PlayerInitData init in inits.datas) { if (init.sync.userid != Players.userid) { Players.AddOtherPlayer(init); } } }
public void SnapshotHandler(NetConnection connection, object data) { SnapShotData snap = GCli.Deserialize <SnapShotData>((byte[])data); Players.UpdatePlayerSyncData(snap.syncs); ui.AddBlocks(snap.pixels); }
void SendDrawData(Dictionary <int, List <int> > rewrites) { DrawData draw = new DrawData(); foreach (KeyValuePair <int, List <int> > item in rewrites) { foreach (int y in item.Value) { if (surface == 0) { draw.pixels.Add(new PixelData() { isbot = true, x = item.Key, y = y, color = pixels[item.Key, y] }); } else { draw.pixels.Add(new PixelData() { isbot = false, x = item.Key, y = y, color = pixels[item.Key, y] }); } } } GCli.Send(MessageType.Draw, GCli.Serialize <DrawData>(draw), Lidgren.Network.NetDeliveryMethod.Unreliable); }
void SendFire(bool hit, int parts, int userid) { FireData data = new FireData { hit = hit, parts = parts, userid = userid }; GCli.Send(MessageType.SendFire, GCli.Serialize <FireData>(data), NetDeliveryMethod.ReliableOrdered); }
public void ConnectHandler(NetConnection connection, object data) { GCli.ClearPacketHandler(); debugText.text = ""; start.SetActive(true); GCli.SetPacketHandler(MessageType.ReplyUserID, DataType.Int32, ReplyUserIDHandler); }
public void ReplySuccessLeaveRoomHandler(NetConnection connection, object data) { GCli.ClearPacketHandler(); room.SetActive(false); lobby.SetActive(true); GCli.SetPacketHandler(MessageType.ReplyLobbyState, DataType.Bytes, ReplyLobbyStateHandler); GCli.SetPacketHandler(MessageType.ReplySuccessEnterRoom, DataType.Null, ReplySuccessEnterRoomHandler); }
void OnTriggerEnter(Collider other) { if (isEnemyCore) { if (other.tag == "MyPlayer") { GCli.Send(MessageType.TouchCore, NetDeliveryMethod.ReliableOrdered); } } }
public void ConnectSuccessHandler(NetConnection connection, object data) { GCli.ClearPacketHandler(); InitData init = GCli.Deserialize <InitData>((byte[])data); GameObject.Find("Canvas").GetComponent <UIScript>().SetInitData(init.bmps); Players.SetPlayer(init.sync); GCli.SetPacketHandler(MessageType.Snapshot, DataType.Bytes, SnapshotHandler); }
public void ReplyUserIDHandler(NetConnection connection, object data) { Players.userid = (int)data; GCli.ClearPacketHandler(); start.SetActive(false); lobby.SetActive(true); GCli.SetPacketHandler(MessageType.ReplyLobbyState, DataType.Bytes, ReplyLobbyStateHandler); GCli.SetPacketHandler(MessageType.ReplySuccessEnterRoom, DataType.Null, ReplySuccessEnterRoomHandler); }
void Construct() { if (weaponTimer <= 0 && !haveGun) { if (Input.GetButtonDown("Fire1")) { RaycastHit hit; if (Physics.Raycast(fpsCamera.position, fpsCamera.forward, out hit, distance)) { Vector3 hitPoint = hit.point + hit.normal * 0.1f; int x = (int)hitPoint.x; int y = (int)hitPoint.y; int z = (int)hitPoint.z; Collider[] cols = Physics.OverlapBox(new Vector3(x + 0.5f, y + 0.5f, z + 0.5f), new Vector3(0.49f, 0.49f, 0.49f)); if (cols.Length == 0) { if (Env.IsInsideWorld(x, y, z) && !Env.IsCorePos(x, y, z)) { BlockData block = new BlockData { x = x, y = y, z = z, blocktype = init.faction == 0 ? 2 : 3 }; GCli.Send(MessageType.SetBlock, GCli.Serialize <BlockData>(block), NetDeliveryMethod.ReliableOrdered); //World.SetBlock(x, y, z, init.faction == 0 ? 2 : 3); } } } } else if (Input.GetButtonDown("Fire2")) { RaycastHit hit; if (Physics.Raycast(fpsCamera.position, fpsCamera.forward, out hit, distance)) { Vector3 hitPoint = hit.point - hit.normal * 0.1f; int x = (int)hitPoint.x; int y = (int)hitPoint.y; int z = (int)hitPoint.z; if (Env.IsInsideWorld(x, y, z) && !Env.IsCorePos(x, y, z)) { BlockData block = new BlockData { x = x, y = y, z = z, blocktype = 0 }; GCli.Send(MessageType.SetBlock, GCli.Serialize <BlockData>(block), NetDeliveryMethod.ReliableOrdered); //World.SetBlock(x, y, z, 0); } } } } }
void Start() { if (!ReadFile(Application.dataPath + "/../Setting/setting.txt")) { return; } GCli.Init(); GCli.SetConnectPacketHandler(ConnectHandler); //GCli.SetDebugPacketHandler(DebugHandler); GCli.Connect("TwoDimBlocks0.1", host, port); }
public void BattleEndHandler(NetConnection connection, object data) { GCli.ClearPacketHandler(); Players.Destroy(); Cursor.lockState = CursorLockMode.None; Cursor.visible = true; World.CreateDefaultBlocks(); menu.SetActive(true); room.SetActive(true); GCli.SetPacketHandler(MessageType.ReplyRoomState, DataType.Bytes, ReplyRoomStateHandler); GCli.SetPacketHandler(MessageType.ReplySuccessLeaveRoom, DataType.Null, ReplySuccessLeaveRoomHandler); GCli.SetPacketHandler(MessageType.BattleStart, DataType.Bytes, BattleStartHandler); }
void Start() { if (!ReadFile(Application.dataPath + "/../Setting/setting.txt")) { return; } menu.SetActive(true); start.SetActive(false); lobby.SetActive(false); room.SetActive(false); GCli.Init(); GCli.SetConnectPacketHandler(ConnectHandler); GCli.SetDebugPacketHandler(DebugHandler); GCli.Connect("ILSnowballFight0.1", host, port); World.CreateDefaultBlocks(); }
void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { Application.Quit(); } GCli.Receive(); frameSpan += Time.deltaTime; if (frameSpan >= 0.1f) { frameSpan = 0; if (Players.GetPlayer() != null) { PushData push = Players.GetPushData(); if (push != null) { GCli.Send(MessageType.Push, GCli.Serialize <PushData>(push), NetDeliveryMethod.UnreliableSequenced); } } } }
public void ChangeReady() { GCli.Send(MessageType.ChangeReady, NetDeliveryMethod.ReliableOrdered); }
public void EnterRoom() { GCli.Send(MessageType.EnterRoom, summary.roomid, NetDeliveryMethod.ReliableOrdered); }
public void SnapshotHandler(NetConnection connection, object data) { PlayerSyncDatas datas = GCli.Deserialize <PlayerSyncDatas>((byte[])data); Players.UpdatePlayerSyncData(datas.datas); }
public void RequestLobbyState() { GCli.Send(MessageType.RequestLobbyState, NetDeliveryMethod.ReliableOrdered); }
public void ConnectHandler(NetConnection connection, object data) { GCli.ClearPacketHandler(); GCli.SetPacketHandler(MessageType.ConnectSuccess, DataType.Bytes, ConnectSuccessHandler); }
void OnDestroy() { GCli.Shutdown(); }
public void LeaveRoom() { GCli.Send(MessageType.LeaveRoom, NetDeliveryMethod.ReliableOrdered); }
public void SendUserName() { string name = username.text; GCli.Send(MessageType.SendUserName, name, NetDeliveryMethod.ReliableOrdered); }
public void ChangeFaction() { GCli.Send(MessageType.ChangeFaction, NetDeliveryMethod.ReliableOrdered); }
public void ReplyLobbyStateHandler(NetConnection connection, object data) { LobbyState state = GCli.Deserialize <LobbyState>((byte[])data); RefreshLobbyUI(state); }
public void ReplySetBlockHandler(NetConnection connection, object data) { BlockData block = GCli.Deserialize <BlockData>((byte[])data); World.SetBlock(block.x, block.y, block.z, block.blocktype); }
public void ReplyRoomStateHandler(NetConnection connection, object data) { RoomState state = GCli.Deserialize <RoomState>((byte[])data); RefreshRoomUI(state); }