public void syncOthers() { ByteConstructor bc = new ByteConstructor(); bc.addLevels(new int[] { (int)DataType.ListUpdate, (int)ListUpdateType.SyncOthers }); //add types if (playerInfoList.Count == 1) { return; } bc.add(playerInfoList.Count - 1); //add ammount of Players int byte[] standardBytes = bc.getBytes(); for (int q = 0; q < playerInfoList.Count; q++) //loop for all Players { ByteConstructor bcL = new ByteConstructor(standardBytes); for (int i = 0; i < playerInfoList.Count; i++) //add all players { if (playerInfoList[i].connID != playerInfoList[q].connID) { bcL.add(playerInfoList [i].serialize()); } } send(bcL.getBytes(), playerInfoList[q].connID); //send to player } }
private byte[] getSpawnBytes(IdentityAndTransform iat) // list index means index in the IDAndTransforms list, and conn { ByteConstructor bc = new ByteConstructor(); bc.addLevels(new int[] { (int)DataType.Sync, (int)SyncType.Spawning }); bc.add(NetObjBytes.defaultInfo(iat.netIdentity.objID, iat.netIdentity.AuthorityID, (int)iat.type, iat.prefabIndex, iat.netTrans.trans.position, iat.netTrans.trans.rotation)); switch (iat.type) { case NetObjBytes.ObjectType.Planet: var pg3 = iat.netIdentity.GetComponent <PlanetGenerator3> (); if (pg3 != null) { var rb = iat.netIdentity.GetComponent <ConstraintTrans> ().otherTrans.GetComponent <Rigidbody> (); bc.add(NetObjBytes.planetSpawn(rb.mass, rb.velocity, rb.angularVelocity, pg3.seed, pg3.radius)); } else { var rb = iat.netIdentity.GetComponent <Rigidbody> (); bc.add(NetObjBytes.planetSpawn(rb.mass, rb.velocity, rb.angularVelocity, 0, 0)); } break; case NetObjBytes.ObjectType.Rigidbody: var rb1 = iat.netIdentity.GetComponent <ConstraintTrans> ().otherTrans.GetComponent <Rigidbody> (); bc.add(NetObjBytes.rigidbodySpawn(rb1.mass, rb1.velocity, rb1.angularVelocity)); break; } return(bc.getBytes()); }
public void sendUniverseUpdateRequest() { ByteConstructor bc = new ByteConstructor(12); bc.addLevels(new int[] { (int)DataType.Sync, (int)SyncType.Request, (int)RequestType.Universe }); sendServer(bc.getBytes()); }
public void updatePlayer(int uniqueID) { var pi = playerInfoList [findWithUniqueID(uniqueID)]; ByteConstructor bc = new ByteConstructor(); send(bc.addLevels(new int[] { (int)DataType.ListUpdate, (int)ListUpdateType.UpdateYourself }, pi.serialize()), pi.connID); syncOthers(); }
// private byte[] transUpdateBytes(IdentityAndTransform iat){ // return transUpdateBytes (iat.netTrans.trans, iat.netTrans.updateType, iat.netIdentity.objID); // } private byte[] transUpdateBytes(IdentityAndTransform iat) { ByteConstructor bc = new ByteConstructor(); bc.addLevels(new int[] { (int)DataType.Sync, (int)SyncType.TransUpdate }); bc.add(iat.netIdentity.objID); bc.add((int)iat.netTrans.updateType); switch (iat.netTrans.updateType) { case TransUpdateType.Transform: bc.add(iat.netTrans.getPosition()); bc.add(iat.netTrans.getRotation()); bc.add(iat.netTrans.trans.localScale); break; // case TransUpdateType.Position: // bc.add (ByteHelper.vector3Bytes(transform.position)); // break; // case TransUpdateType.Rotation: // bc.add (ByteHelper.quaternionBytes(transform.rotation)); // break; // case TransUpdateType.Scale: // // break; case TransUpdateType.TransAndRigidbody: bc.add(iat.netTrans.getPosition()); bc.add(iat.netTrans.getRotation()); bc.add(iat.netTrans.trans.localScale); var body = iat.netTrans.trans.GetComponent <Rigidbody> (); bc.add(body.velocity); bc.add(body.angularVelocity); break; default: break; } return(bc.getBytes()); }