public void ResetVoxel() { InitialSetup(); StructureChangeMsg outMsg = new StructureChangeMsg(); outMsg.from = this.id; outMsg.textureType = this.textureType; outMsg.pos = transform.position; outMsg.Vertices = mesh.vertices; outMsg.Triangles = mesh.triangles; netManager.ChangeModel(outMsg); meshChanged = false; }
private StructureChangeMsg SCMSGVars(byte[] vars) //needs testing { byte[] size = new byte[4]; byte[] pos = new byte[12]; int index = 0; //Console.WriteLine(vars.Length); Array.Copy(vars, index, pos, 0, 12); index += 12; Array.Copy(vars, index, size, 0, 4); index += 4; Int32 vertSize = ByteInt32(size); byte[] vertices = new byte[vertSize]; Array.Copy(vars, index, vertices, 0, vertSize); index += vertSize; Array.Copy(vars, index, size, 0, 4); index += 4; Int32 triSize = ByteInt32(size); byte[] triangles = new byte[triSize]; Array.Copy(vars, index, triangles, 0, triSize); index += triSize; StructureChangeMsg msg = new StructureChangeMsg(); msg.pos = ByteVec3(pos); msg.vertices = ByteVec3Array(vertices); byte[][] tri = new byte[vars.Length / 4][]; //Console.WriteLine(vars.Length); for (int i = 0; i < vars.Length / 4; i += 4) { Array.Copy(vars, i, tri[i], 0, 4); } msg.triangles = ByteInt32(tri); return(msg); }
// Structure Change MSG private StructureChangeMsg GetSCMSG(byte[] msg, Int64 msgSize) { Int32 type = ByteInt32(msg[8]); byte[] seq_num = new byte[4]; byte[] vars = new byte[msgSize - 13]; Array.Copy(msg, 9, seq_num, 0, 4); Array.Copy(msg, 13, vars, 0, msgSize - 13); StructureChangeMsg SCMSG = SCMSGVars(vars); SCMSG.msgType = type; return(SCMSG); }
void Update() { if (this.netManager == null) { this.netManager = NetworkManager.Instance; return; } //Right click for raycasting. Rays are visible in Scene Editor /* if (Input.GetMouseButtonDown(1)) * { * ////Debug.Log("Got here"); * RaycastHit hit; * Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); * if (Physics.Raycast(ray, out hit, 100.0f)) * { * //Vector3 forward = transform.TransformDirection(Vector3.forward) * 10; * void OnCollisionEnter(Collision collision) * { * foreach (ContactPoint contact in collision.contacts) * { * Debug.DrawLine(contact.point, contact.point, Color.green, 2, false); * } * } * //Destroy(hit.transform.gameObject); * // Draws raycast line in scene * // DrawRay (start position, end position, color, duration of time ) * Debug.DrawRay(transform.position, Camera.main.transform.forward * 10, Color.green, 10.0f); * ////Debug.Log("You hit the " + hit.transform.name); // ensure you picked right object * Vector3 pointOfCollision = hit.point; * ////Debug.Log("Hit at point: " + pointOfCollision.ToString("F4")); * } * }*/ //if (timer < waitTime) //{ // timer += Time.deltaTime; // //Debug.Log(timer); //} //if (!timerWentOff) //{ // if (timer > waitTime) // { // for(int i = 0; i < 10; i++) // { // for(int j = 0; j < 10; j++) // { // for (int k = 0; k < 10; k++) // { // voxel[i, j, k] = null; // } // } // } // resetMesh(); // rebuildMesh(); // timerWentOff = true; // } //} if (!hasran && meshed) { StructureChangeMsg outMsg = new StructureChangeMsg(); outMsg.textureType = this.textureType; outMsg.pos = transform.position; outMsg.Vertices = mesh.vertices; outMsg.Triangles = mesh.triangles; id = netManager.AddModel(outMsg); hasran = true; } else if (meshChanged) { StructureChangeMsg outMsg = new StructureChangeMsg(); outMsg.from = this.id; outMsg.textureType = this.textureType; outMsg.pos = transform.position; outMsg.Vertices = mesh.vertices; outMsg.Triangles = mesh.triangles; netManager.ChangeModel(outMsg); meshChanged = false; } //this.gameObject.GetComponent<Collider>().enabled = false; }
public byte[] SerializeMSG(StructureChangeMsg msg) { byte[] header = Header(msg.msgType); byte[] body = BuildMSG(msg.pos, msg.vertices, msg.triangles); return(Combine(IntByte((Int64)8 + header.Length + body.Length), header, body)); }