public void BakePerAnimClip(AnimationClip clip) { ByteWrite byteWrite = new ByteWrite(); int curClipFrame = (int)(clip.frameRate * clip.length); float perFrameTime = clip.length / curClipFrame; m_Animation.Play(clip.name); float sampleTime = 0; byteWrite.WriteShort((short)curClipFrame); byteWrite.WriteShort((short)(perFrameTime * 1000)); for (int i = 0; i < curClipFrame; i++) { clip.SampleAnimation(m_Animation.gameObject, sampleTime); // m_Animation.Sample(); Mesh bakedMesh = new Mesh(); m_SkinRender.BakeMesh(bakedMesh); for (int j = 0; j < bakedMesh.vertexCount; j++) { Vector3 vertex = bakedMesh.vertices[j]; byteWrite.WriteShort((short)(vertex.x * 100)); byteWrite.WriteShort((short)(vertex.y * 100)); byteWrite.WriteShort((short)(vertex.z * 100)); } sampleTime += perFrameTime; } m_BinaryWriter.Write(byteWrite.ToByteArray()); }
private void EncapsulateMtu(int commandCount, long currentSendingTime) { int offset = 0; ByteWrite.SetByte(_udpBuffer, ref offset, (byte)CommandType.None); ByteWrite.SetInt(_udpBuffer, ref offset, _peerId); ByteWrite.SetLong(_udpBuffer, ref offset, currentSendingTime); ByteWrite.SetShort(_udpBuffer, ref offset, (short)commandCount); Array.Clear(_udpBuffer, offset, (int)Lengths.Crc); if (IsCrcEnabled) { long crc = _udpBuffer.CalculateCrc(_udpBufferIndex); ByteWrite.SetLong(_udpBuffer, ref offset, crc); } }
public byte[] CreateConnectCommand( short channelCount, short mtu, int protoVerison, int disconnectionTimeout, bool isCrcEnabled, BigInteger publicKey, long sendingTime) { var buffer = ByteBufferFactory.NewBuffer(); buffer.WriteByte((byte)CommandType.Connect); buffer.WriteInt(protoVerison); //4 buffer.WriteLong(sendingTime); //8 buffer.WriteShort(channelCount); //2 buffer.WriteShort(mtu); //2 buffer.WriteInt(disconnectionTimeout); //4 buffer.WriteShort((short)(isCrcEnabled == true ? 1 : 0)); //2 var publicKeyBytes = publicKey.ToByteArray(); buffer.WriteByte((byte)publicKeyBytes.Length); buffer.WriteBytes(publicKeyBytes); //4 buffer.WriteLong(0); //8 crc space var bytes = buffer.ToArray(); if (isCrcEnabled) { long crc = bytes.CalculateCrc(bytes.Length); int offset = bytes.Length - (int)Lengths.Crc; ByteWrite.SetLong(bytes, ref offset, crc); } SentCount++; return(bytes); }
public void Bake() { int vertexCount = m_SkinRender.sharedMesh.vertexCount; int[] trangles = m_SkinRender.sharedMesh.triangles; Vector2[] uvs = m_SkinRender.sharedMesh.uv; ByteWrite byteWrite = new ByteWrite(); byteWrite.WriteInt(vertexCount); byteWrite.WriteInt(trangles.Length); byteWrite.WriteInt(uvs.Length); for (int i = 0; i < trangles.Length; i++) { byteWrite.WriteShort((short)(trangles[i])); } for (int i = 0; i < uvs.Length; i++) { byteWrite.WriteByte((byte)(uvs[i].x * 100)); byteWrite.WriteByte((byte)(uvs[i].y * 100)); } if (m_Animation) { List <AnimationState> animClips = new List <AnimationState>(m_Animation.Cast <AnimationState>()); byteWrite.WriteByte((byte)(animClips.Count)); m_BinaryWriter.Write(byteWrite.ToByteArray()); for (int i = 0; i < animClips.Count; i++) { var clip = animClips[i].clip; if (!clip.legacy) { Debug.LogError(string.Format("{0} 动画系统", clip.name)); continue; } BakePerAnimClip(clip); } } else if (m_Animator) { var clips = m_Animator.runtimeAnimatorController.animationClips; byteWrite.WriteByte((byte)(clips.Length)); m_BinaryWriter.Write(byteWrite.ToByteArray()); for (int i = 0; i < clips.Length; i++) { BakePerAnimatorClip(clips[i]); } } if (m_BinaryWriter != null) { m_BinaryWriter.Close(); m_BinaryWriter = null; } if (m_FileStream != null) { m_FileStream.Close(); m_FileStream = null; } if (gameObject != null) { Object.DestroyImmediate(gameObject); gameObject = null; } }