Beispiel #1
0
        /// <summary>
        /// Encode transform attributes for text.
        /// </summary>
        /// <param name="attr"></param>
        /// <param name="obj"></param>
        /// <param name="comp"></param>
        protected override void EncodeAttributes(ref ObjectAttributes attr, GameObject obj, ShapeComponent comp)
        {
            Transform transform = obj.transform;
            // Convert position to Unity position.
            Vector3 pos = FrameTransform.UnityToRemote(obj.transform.position, ServerInfo.CoordinateFrame);

            attr.X         = pos.x;
            attr.Y         = pos.y;
            attr.Z         = pos.z;
            attr.RotationX = transform.localRotation.x;
            attr.RotationY = transform.localRotation.y;
            attr.RotationZ = transform.localRotation.z;
            attr.RotationW = transform.localRotation.w;
            attr.ScaleX    = 1.0f;
            attr.ScaleY    = 1.0f;
            attr.ScaleZ    = 12.0f;

            TextMesh text = obj.GetComponent <TextMesh>();

            if (text != null)
            {
                attr.ScaleZ = text.fontSize;
            }
            if (comp != null)
            {
                attr.Colour = ShapeComponent.ConvertColour(comp.Colour);
            }
            else
            {
                attr.Colour = 0xffffffu;
            }
        }
        /// <summary>
        /// Serialises the currently active objects in for playback from file.
        /// </summary>
        /// <param name="writer">The write to serialise to.</param>
        /// <param name="info">Statistics</param>
        /// <returns>An error code on failure.</returns>
        public override Error Serialise(BinaryWriter writer, ref SerialiseInfo info)
        {
            Error err = new Error();

            info.PersistentCount = info.TransientCount = 0;
            if (_cameras.Count > 0)
            {
                PacketBuffer  packet = new PacketBuffer(256);
                CameraMessage msg    = new CameraMessage();
                Vector3       v      = Vector3.zero;
                msg.Reserved1 = 0;
                msg.Reserved2 = 0;
                foreach (CameraInfo camera in _cameras.Values)
                {
                    ++info.PersistentCount;
                    msg.CameraID = camera.ID;
                    v            = FrameTransform.UnityToRemote(camera.transform.localPosition, ServerInfo.CoordinateFrame);
                    msg.X        = v.x;
                    msg.Y        = v.y;
                    msg.Z        = v.z;
                    v            = FrameTransform.UnityToRemote(camera.transform.forward, ServerInfo.CoordinateFrame);
                    msg.DirX     = v.x;
                    msg.DirY     = v.y;
                    msg.DirZ     = v.z;
                    v            = FrameTransform.UnityToRemote(camera.transform.up, ServerInfo.CoordinateFrame);
                    msg.UpX      = v.x;
                    msg.UpY      = v.y;
                    msg.UpZ      = v.z;
                    msg.Near     = camera.Near;
                    msg.Far      = camera.Far;
                    msg.FOV      = camera.FOV;
                    packet.Reset(RoutingID, 0);
                    msg.Write(packet);
                    packet.FinalisePacket();
                    packet.ExportTo(writer);
                }
            }

            return(err);
        }