【发布时间】:2021-07-02 17:50:20
【问题描述】:
所以我有这个问题
我想在客户端和服务器上进行相同的对象轮换。但不知何故,它不会工作。 客户:
byte[] buff = new byte[sizeof(float) * 3];
Buffer.BlockCopy(BitConverter.GetBytes(Object.eulerAngles.x), 0, buff, 0 * sizeof(float), sizeof(float));
Buffer.BlockCopy(BitConverter.GetBytes(Object.eulerAngles.y), 0, buff, 1 * sizeof(float), sizeof(float));
Buffer.BlockCopy(BitConverter.GetBytes(Object.eulerAngles.z), 0, buff, 2 * sizeof(float), sizeof(float));
服务器:
vect.x = BitConverter.ToSingle(msg.Array, msg.Array.Length - 3 * sizeof(float));
vect.y = BitConverter.ToSingle(msg.Array, msg.Array.Length - 2 * sizeof(float));
vect.z = BitConverter.ToSingle(msg.Array, msg.Array.Length - sizeof(float));
q = Quaternion.Euler(vect);
Debug.Log(q);
TargetObject_Transform.rotation = q;
【问题讨论】:
-
似乎是一个错字。不应该是
msgArray.Length - 1 - (1,2, or 3) * sizeof(float)吗?为什么不像(0, 1, or 2) * sizeof(float)那样在BlockCopy调用中表达它? -
rot.x = BitConverter.ToSingle(msg, offset * sizeof(float) + 0 * sizeof(float)); // 这就是我开始工作时的格式
标签: c# unity3d networking quaternions