public void Deserialize(NetworkReader reader) { drawerId = reader.ReadNetworkId(); type = (BrushActionType)reader.ReadByte(); time = reader.ReadSingle(); isPreview = reader.ReadBoolean(); switch (type) { case BrushActionType.Clear: break; case BrushActionType.Line: case BrushActionType.Box: case BrushActionType.Oval: case BrushActionType.PreviewBox: x0 = (short)reader.ReadUInt16(); y0 = (short)reader.ReadUInt16(); x1 = (short)reader.ReadUInt16(); y1 = (short)reader.ReadUInt16(); color = reader.ReadColor32(); size = (byte)reader.ReadByte(); break; case BrushActionType.FloodFill: x0 = (short)reader.ReadUInt16(); y0 = (short)reader.ReadUInt16(); color = reader.ReadColor32(); break; } }
public void Serialize(ref Color32 value) { if (IsReading) { value = m_Reader.ReadColor32(); } else { m_Writer.WriteColor32(value); } }
// Token: 0x06000A8A RID: 2698 RVA: 0x0003444E File Offset: 0x0003264E public override void Deserialize(NetworkReader reader) { base.Deserialize(reader); this.pickupToken = reader.ReadString(); this.pickupColor = reader.ReadColor32(); this.pickupQuantity = reader.ReadPackedUInt32(); }
public void TestColor32(Color32 input) { writer.WriteColor32(input); reader.Reset(writer.ToArraySegment()); Color32 output = reader.ReadColor32(); Assert.That(output, Is.EqualTo(input)); }
public void TestColor32(Color32 input) { writer.WriteColor32(input); var reader = new NetworkReader(writer.ToArray()); Color32 output = reader.ReadColor32(); Assert.That(output, Is.EqualTo(input)); }
public override void Deserialize(NetworkReader reader) { base.Deserialize(reader); data = new Color32[size]; for (int i = 0; i < size; i++) { data[i] = reader.ReadColor32(); } }
// Token: 0x06001288 RID: 4744 RVA: 0x0005AE60 File Offset: 0x00059060 public override void OnDeserialize(NetworkReader reader, bool initialState) { if (initialState) { this._id = GeneratedNetworkCode._ReadNetworkUserId_None(reader); this.rewiredPlayerId = (byte)reader.ReadPackedUInt32(); this._masterObjectId = reader.ReadNetworkId(); this.userColor = reader.ReadColor32(); this.netLunarCoins = reader.ReadPackedUInt32(); this.bodyIndexPreference = (int)reader.ReadPackedUInt32(); return; } int num = (int)reader.ReadPackedUInt32(); if ((num & 1) != 0) { this.OnSyncId(GeneratedNetworkCode._ReadNetworkUserId_None(reader)); } if ((num & 2) != 0) { this.rewiredPlayerId = (byte)reader.ReadPackedUInt32(); } if ((num & 4) != 0) { this.OnSyncMasterObjectId(reader.ReadNetworkId()); } if ((num & 8) != 0) { this.userColor = reader.ReadColor32(); } if ((num & 16) != 0) { this.netLunarCoins = reader.ReadPackedUInt32(); } if ((num & 32) != 0) { this.SetBodyPreference((int)reader.ReadPackedUInt32()); } }
// Token: 0x06000AD9 RID: 2777 RVA: 0x000358D4 File Offset: 0x00033AD4 public void Deserialize(NetworkReader reader) { this.origin = reader.ReadVector3(); this.rotation = reader.ReadQuaternion(); this.rootObject = reader.ReadGameObject(); this.modelChildIndex = (short)(reader.ReadByte() - 1); this.scale = reader.ReadSingle(); this.color = reader.ReadColor32(); this.start = reader.ReadVector3(); this.genericUInt = reader.ReadPackedUInt32(); this.genericFloat = reader.ReadSingle(); this.genericBool = reader.ReadBoolean(); }
public void TestColor32() { Color32[] inputs = new Color32[] { Color.black, Color.blue, Color.cyan, Color.yellow, Color.magenta, Color.white, new Color32(0xab, 0xcd, 0xef, 0x12), new Color32(125, 126, 0, 255) }; foreach (Color32 input in inputs) { NetworkWriter writer = new NetworkWriter(); writer.Write(input); NetworkReader reader = new NetworkReader(writer.ToArray()); Color32 output = reader.ReadColor32(); Assert.That(output, Is.EqualTo(input)); } }
// Read public static object Read(NetworkReader reader, Type type) { if (type == typeof(byte)) { return(reader.ReadByte()); } if (type == typeof(short)) { return(reader.ReadInt16()); } if (type == typeof(int)) { return(reader.ReadInt32()); } if (type == typeof(long)) { return(reader.ReadInt64()); } if (type == typeof(string)) { return(reader.ReadString()); } if (type == typeof(float)) { return(reader.ReadSingle()); } if (type == typeof(double)) { return(reader.ReadDouble()); } if (type == typeof(Vector2)) { return(reader.ReadVector2()); } if (type == typeof(Vector3)) { return(reader.ReadVector3()); } if (type == typeof(Vector4)) { return(reader.ReadVector4()); } if (type == typeof(Color)) { return(reader.ReadColor()); } if (type == typeof(Color32)) { return(reader.ReadColor32()); } if (type == typeof(Quaternion)) { return(reader.ReadQuaternion()); } if (type.IsValueType) { return(Activator.CreateInstance(type)); } return(null); }
private static object ReadData(NetworkReader reader) { object resultObj = null; byte dataType = reader.ReadByte(); if (dataType == BYTE) { resultObj = reader.ReadByte(); } else if (dataType == SBYTE) { resultObj = reader.ReadSByte(); } else if (dataType == CHAR) { resultObj = reader.ReadChar(); } else if (dataType == BOOL) { resultObj = reader.ReadBoolean(); } else if (dataType == SHORT) { resultObj = reader.ReadInt16(); } else if (dataType == USHORT) { resultObj = reader.ReadUInt16(); } else if (dataType == INT) { resultObj = reader.ReadInt32(); } else if (dataType == UINT) { resultObj = reader.ReadPackedUInt32(); } else if (dataType == LONG) { resultObj = reader.ReadInt64(); } else if (dataType == ULONG) { resultObj = reader.ReadPackedUInt64(); } else if (dataType == FLOAT) { resultObj = reader.ReadSingle(); } else if (dataType == DOUBLE) { resultObj = reader.ReadDouble(); } else if (dataType == DECIMAL) { resultObj = reader.ReadDecimal(); } else if (dataType == STRING) { resultObj = reader.ReadString(); } else if (dataType == VECTOR2) { resultObj = reader.ReadVector2(); } else if (dataType == VECTOR3) { resultObj = reader.ReadVector3(); } else if (dataType == VECTOR4) { resultObj = reader.ReadVector4(); } else if (dataType == COLOR) { resultObj = reader.ReadColor(); } else if (dataType == COLOR32) { resultObj = reader.ReadColor32(); } else if (dataType == QUATERNION) { resultObj = reader.ReadQuaternion(); } else if (dataType == TRANSFORM) { resultObj = reader.ReadTransform(); } else if (dataType == RECT) { resultObj = reader.ReadRect(); } else if (dataType == PLANE) { resultObj = reader.ReadPlane(); } else if (dataType == GAMEOBJECT) { resultObj = reader.ReadGameObject(); } else if (dataType == RAY) { resultObj = reader.ReadRay(); } else if (dataType == MATRIX4X4) { resultObj = reader.ReadMatrix4x4(); } else if (dataType == NETWORKHASH128) { resultObj = reader.ReadNetworkHash128(); } else if (dataType == NETWORKIDENTITY) { resultObj = reader.ReadNetworkIdentity(); } else if (dataType == MESSAGEBASE) { //resultObj = reader.ReadMessage<MessageBase>(); resultObj = null; } else if (dataType == NETWORKINSTANCEID) { resultObj = reader.ReadNetworkId(); } else if (dataType == NETWORKSCENEID) { resultObj = reader.ReadSceneId(); } //Debug.Log(resultObj); return(resultObj); }
public override void Deserialize(NetworkReader reader, out Color32 value) { value = reader.ReadColor32(); }
public bool Deserialize(byte[] _bytes) { using (MemoryStream ms = new MemoryStream(_bytes)) { using (NetworkReader nr = new NetworkReader(ms)) { Type type = GetType(); FieldInfo[] allFields = type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); PropertyInfo[] allProperties = type.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); IEnumerable <FieldInfo> fields = allFields .Where(o => o.GetCustomAttributes(typeof(SyncVar)).Count() > 0) .OrderBy(o => o.Name); IEnumerable <PropertyInfo> properties = allProperties .Where(o => o.GetCustomAttributes(typeof(SyncVar)).Count() > 0) .OrderBy(o => o.Name); Type fieldType; foreach (FieldInfo info in fields) { fieldType = info.FieldType; string typeString = fieldType.Name; object tmpValue = null; bool switchOnType = true; if (fieldType.IsEnum) { tmpValue = nr.ReadInt32(); switchOnType = false; } if (switchOnType) { switch (typeString) { case "Boolean": tmpValue = nr.ReadBoolean(); break; case "Byte": tmpValue = nr.ReadByte(); break; case "SByte": tmpValue = nr.ReadSByte(); break; case "Int16": tmpValue = nr.ReadInt16(); break; case "Int32": tmpValue = nr.ReadInt32(); break; case "Int64": tmpValue = nr.ReadInt64(); break; case "UInt16": tmpValue = nr.ReadUInt16(); break; case "UInt32": tmpValue = nr.ReadUInt32(); break; case "UInt64": tmpValue = nr.ReadUInt64(); break; case "Single": tmpValue = nr.ReadSingle(); break; case "Double": tmpValue = nr.ReadDouble(); break; case "Decimal": tmpValue = nr.ReadDecimal(); break; case "Char": tmpValue = nr.ReadChar(); break; case "String": tmpValue = nr.ReadString(); break; case "Byte[]": int length = nr.ReadInt32(); tmpValue = nr.ReadBytes(length); break; case "Vector2": tmpValue = nr.ReadVector2(); break; case "Vector3": tmpValue = nr.ReadVector3(); break; case "Vector4": tmpValue = nr.ReadVector4(); break; case "GameObject": tmpValue = nr.ReadGameObject(); break; case "Transform": tmpValue = nr.ReadTransform(); break; case "Color": tmpValue = nr.ReadColor(); break; case "Color32": tmpValue = nr.ReadColor32(); break; default: Debug.LogWarning("Could not serialize field! " + info.Name + "(" + info.FieldType.Name + ")", this); break; } } info.SetValue(this, tmpValue); SyncVar syncVar = info.GetCustomAttribute <SyncVar>(); if (syncVar is object && syncVar.Hook is object) { SendMessage(syncVar.Hook, tmpValue, SendMessageOptions.RequireReceiver); } } foreach (PropertyInfo info in properties) { fieldType = info.PropertyType; string typeString = fieldType.Name; object tmpValue = null; bool switchOnType = true; if (fieldType.IsEnum) { tmpValue = nr.ReadInt32(); switchOnType = false; } if (switchOnType) { switch (typeString) { case "Boolean": tmpValue = nr.ReadBoolean(); break; case "Byte": tmpValue = nr.ReadByte(); break; case "SByte": tmpValue = nr.ReadSByte(); break; case "Int16": tmpValue = nr.ReadInt16(); break; case "Int32": tmpValue = nr.ReadInt32(); break; case "Int64": tmpValue = nr.ReadInt64(); break; case "UInt16": tmpValue = nr.ReadUInt16(); break; case "UInt32": tmpValue = nr.ReadUInt32(); break; case "UInt64": tmpValue = nr.ReadUInt64(); break; case "Single": tmpValue = nr.ReadSingle(); break; case "Double": tmpValue = nr.ReadDouble(); break; case "Decimal": tmpValue = nr.ReadDecimal(); break; case "Char": tmpValue = nr.ReadChar(); break; case "String": tmpValue = nr.ReadString(); break; case "Byte[]": int length = nr.ReadInt32(); tmpValue = nr.ReadBytes(length); break; case "Vector2": tmpValue = nr.ReadVector2(); break; case "Vector3": tmpValue = nr.ReadVector3(); break; case "Vector4": tmpValue = nr.ReadVector4(); break; case "GameObject": tmpValue = nr.ReadGameObject(); break; case "Transform": tmpValue = nr.ReadTransform(); break; case "Color": tmpValue = nr.ReadColor(); break; case "Color32": tmpValue = nr.ReadColor32(); break; default: Debug.LogWarning("Could not serialize field! " + info.Name + "(" + info.PropertyType.Name + ")", this); break; } } info.SetValue(this, tmpValue); SyncVar syncVar = info.GetCustomAttribute <SyncVar>(); if (syncVar is object && syncVar.Hook is object) { SendMessage(syncVar.Hook, tmpValue, SendMessageOptions.RequireReceiver); } } } return(true); } }
private void ReceivePaletteEdit(NetworkReader reader) { byte index = reader.ReadByte(); Color color = reader.ReadColor32(); world.palette[index] = color; paletteEditor.Refresh(); SetPalette(index, color); }
private void Update() { if (Input.GetKeyDown(KeyCode.LeftBracket)) { paletteEditor.gameObject.SetActive(!paletteEditor.gameObject.activeSelf); } bool editing = tileEditor.gameObject.activeSelf; bool chatting = chatOverlay.gameObject.activeSelf; bool mapping = Input.GetKey(KeyCode.Tab) && !chatting; if (editing && !chatting) { tileEditor.CheckInput(); } if (Input.GetKeyDown(KeyCode.Escape)) { if (chatting) { chatOverlay.Hide(); } else if (editing) { tileEditor.OnClickedSave(); } else if (hostID != -1) { OnApplicationQuit(); SceneManager.LoadScene("Main"); return; } else { Application.Quit(); return; } } else if (Input.GetKeyDown(KeyCode.F12)) { string selfies = Application.persistentDataPath + "/selfies"; Directory.CreateDirectory(selfies); Application.CaptureScreenshot(string.Format("{0}/{1}.png", selfies, System.DateTime.Now.Ticks)); } else if (Input.GetKeyDown(KeyCode.F11)) { string maps = Application.persistentDataPath + "/maps"; Directory.CreateDirectory(maps); mapCamera.Render(); var old = RenderTexture.active; RenderTexture.active = mapTexture; mapTextureLocal.ReadPixels(Rect.MinMaxRect(0, 0, 1024, 1024), 0, 0); RenderTexture.active = old; File.WriteAllBytes(string.Format("{0}/{1}.png", maps, System.DateTime.Now.Ticks), mapTextureLocal.EncodeToPNG()); } else if (Input.GetKeyDown(KeyCode.F2)) { scale = 3 - scale; Screen.SetResolution(512 * scale, 512 * scale, false); } if (hostID == -1) return; config.hideTutorial |= !tutorialChat.activeSelf && !tutorialMove.activeSelf && !tutorialTile.activeSelf && !tutorialWall.activeSelf; tutorialObject.SetActive(!config.hideTutorial); mapCamera.gameObject.SetActive(mapping); mapObject.SetActive(mapping); camera.orthographicSize = Mathf.Lerp(128, 32, zoom); if (Input.GetKeyDown(KeyCode.Return)) { if (chatting) { chatOverlay.OnClickedSend(); } else { chatOverlay.Show(); } } if (!chatting && !editing) { if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W)) { Move(Vector2.up); } else if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A)) { Move(Vector2.left); } else if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)) { Move(Vector2.right); } else if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S)) { Move(Vector2.down); } } if (Input.GetKeyDown(KeyCode.Space) && stickypalette) { stickypalette = false; } if (!chatting && !editing && Input.GetKey(KeyCode.Space)) { if (!tilePalette.gameObject.activeSelf) { stickypalette = Input.GetKey(KeyCode.LeftControl); tilePalette.Show(); } } else if (!stickypalette) { tilePalette.Hide(); } if (!UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject() && Rect.MinMaxRect(0, 0, Screen.width, Screen.height).Contains(Input.mousePosition) && !editing) { bool picker = Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt); bool waller = !picker && (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)); tileCursor.gameObject.SetActive(true); pickerCursor.SetActive(picker); tileCursor.sprite = this.world.tiles[tilePalette.SelectedTile]; Vector2 mouse = Input.mousePosition; Vector3 world; RectTransformUtility.ScreenPointToWorldPointInRectangle(worldView.transform as RectTransform, mouse, camera, out world); int x = Mathf.FloorToInt(world.x / 32); int y = Mathf.FloorToInt(world.y / 32); tileCursor.transform.position = new Vector2(x * 32, y * 32); byte tile = tilePalette.SelectedTile; int location = (y + 16) * 32 + (x + 16); if (location >= 0 && location < 1024) { if (waller && Input.GetMouseButtonDown(0)) { tile = this.world.tilemap[location]; bool wall = !this.world.walls.Contains(tile); SendAll(SetWallMessage(tile, wall)); if (this.world.walls.Set(tile, wall)) { tutorialWall.SetActive(false); audio.PlayOneShot(placeSound); } worldView.RefreshWalls(); } else if (!waller && Input.GetMouseButton(0)) { if (!picker && this.world.tilemap[location] != tile) { audio.PlayOneShot(placeSound); worldView.SetTile(location, tile); if (tile != 0) tutorialTile.SetActive(false); SendAll(SetTileMessage(location, tile)); } else if (picker) { tilePalette.SetSelectedTile(this.world.tilemap[location]); } } } } else { tileCursor.gameObject.SetActive(false); } var eventType = NetworkEventType.Nothing; int connectionID; int channelId; int receivedSize; byte error; do { // Get events from the server/client game connection eventType = NetworkTransport.ReceiveFromHost(hostID, out connectionID, out channelId, recvBuffer, recvBuffer.Length, out receivedSize, out error); if ((NetworkError)error != NetworkError.Ok) { group.interactable = true; popups.Show("Network Error: " + (NetworkError)error, delegate { }); } if (eventType == NetworkEventType.ConnectEvent) { connected = true; if (hosting) { OnNewClientConnected(connectionID); } else { OnConnectedToHost(connectionID); } } else if (eventType == NetworkEventType.DisconnectEvent) { if (hosting) { OnClientDisconnected(connectionID); } else { OnDisconnectedFromHost(connectionID); } } else if (eventType == NetworkEventType.DataEvent) { var reader = new NetworkReader(recvBuffer); { Type type = (Type) reader.ReadByte(); if (type == Type.Tilemap) { world.tilemap = reader.ReadBytesAndSize(); worldView.SetWorld(world); } else if (type == Type.Palette) { for (int i = 0; i < 16; ++i) { world.palette[i] = reader.ReadColor32(); SetPalette((byte) i, world.palette[i]); } } else if (type == Type.PaletteEdit) { ReceivePaletteEdit(reader); } else if (type == Type.Walls) { world.walls.Clear(); foreach (var wall in reader.ReadBytesAndSize()) { world.walls.Add(wall); } worldView.RefreshWalls(); } else if (type == Type.Tileset) { int id = reader.ReadInt32(); tiledata[id] = reader.ReadBytesAndSize(); } else if (type == Type.ReplicateAvatar) { ReceiveCreateAvatar(reader); } else if (type == Type.DestroyAvatar) { ReceiveDestroyAvatar(reader); } else if (type == Type.GiveAvatar) { ReceiveGiveAvatar(reader); } else if (type == Type.MoveAvatar) { World.Avatar avatar = ID2Avatar(reader.ReadInt32()); Vector2 dest = reader.ReadVector2(); if (hosting) { if (connectionID == avatar.id && !Blocked(avatar, dest)) { avatar.source = avatar.destination; avatar.destination = dest; avatar.u = 0; SendAll(MoveAvatarMessage(avatar, avatar.destination), except: avatar.id); } else { Send(connectionID, MoveAvatarMessage(avatar, avatar.destination)); } } else { avatar.source = avatar.destination; avatar.destination = dest; avatar.u = 0; } } else if (type == Type.Chat) { World.Avatar avatar = ID2Avatar(reader.ReadInt32()); string message = reader.ReadString(); if (hosting) { if (connectionID == avatar.id) { SendAll(ChatMessage(avatar, message), except: connectionID); Chat(avatar, message); } } else { Chat(avatar, message); } } else if (type == Type.SetTile) { ReceiveSetTile(reader); } else if (type == Type.SetWall) { ReceiveSetWall(reader); } else if (type == Type.TileChunk) { ReceiveTileChunk(reader, connectionID); } else if (type == Type.LockTile) { ReceiveLockTile(reader); } else if (type == Type.AvatarChunk) { ReceiveAvatarChunk(reader, connectionID); } else if (type == Type.TileStroke) { ReceiveTileStroke(reader, connectionID); } } } } while (eventType != NetworkEventType.Nothing); }