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 byte[] serialize() { ByteConstructor bc = new ByteConstructor(); bc.add(System.BitConverter.GetBytes(uniqueID)); bc.add(ByteHelper.colorBytes(color)); bc.add(ByteHelper.getBytes(name)); return(bc.getBytes()); }
//Vector3 public static byte[] vector3Bytes(Vector3 var) { ByteConstructor bc = new ByteConstructor(12); bc.add(var.x); bc.add(var.y); bc.add(var.z); return(bc.getBytes()); }
//Rigidbody public static byte[] rigidbodyBytes(Rigidbody var) { ByteConstructor bc = new ByteConstructor(28); bc.add(var.mass); bc.add(var.velocity); bc.add(var.angularVelocity); return(bc.getBytes()); }
public static byte[] planetSpawn(float mass, Vector3 linVel, Vector3 angVel, int seed, float radius) { ByteConstructor bc = new ByteConstructor(36); bc.add(rigidbodySpawn(mass, linVel, angVel)); bc.add(seed); bc.add(radius); return(bc.getBytes()); }
public static byte[] rigidbodySpawn(float mass, Vector3 linVel, Vector3 angVel) { ByteConstructor bc = new ByteConstructor(28); bc.add(mass); bc.add(linVel); bc.add(angVel); return(bc.getBytes()); }
//Quaternion public static byte[] quaternionBytes(Quaternion val) { ByteConstructor bc = new ByteConstructor(16); bc.add(val.x); bc.add(val.y); bc.add(val.z); bc.add(val.w); return(bc.getBytes()); }
//Color public static byte[] colorBytes(Color var) { ByteConstructor bc = new ByteConstructor(16); bc.add(var.r); bc.add(var.g); bc.add(var.b); bc.add(var.a); return(bc.getBytes()); }
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 } }
public virtual void ClientRequestConnect(int outConnectionId) { setConnected(true); ByteConstructor bc = new ByteConstructor(); bc.add(System.BitConverter.GetBytes((int)DataType.ConnAffirmation)); send(bc.getBytes(), outConnectionId); }
public byte[] getTransformBytes() { ByteConstructor bc = new ByteConstructor(); bc.add(new bool[] { sca, rot, pos }); if (pos) { bc.add(getPosition()); } if (rot) { bc.add(getRotation()); } if (sca) { bc.add(trans.localScale); } return(bc.getBytes()); }
// 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()); }
// public static byte[] genericSpawn(int objectID, int authorityID,int prefabIndex, Vector3 pos, Vector3 rot){ // ByteConstructor bc = new ByteConstructor(); // bc.add(NetObjSpawn.defaultInfo((int)NetObjSpawn.ObjectType.Generic,objectID,authorityID,prefabIndex,pos, rot)); // return bc.getBytes (); // } #region Specific Objects public static byte[] defaultInfo(int objectID, int authorityID, int type, int prefabIndex, Vector3 pos, Quaternion rot) { ByteConstructor bc = new ByteConstructor(44); bc.add(objectID); bc.add(authorityID); bc.add(type); bc.add(prefabIndex); bc.add(pos); bc.add(rot); return(bc.getBytes()); }