Пример #1
0
        /// <summary>
        /// Handle additional <see cref="CreateMessage"/> data.
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="msg"></param>
        /// <param name="packet"></param>
        /// <param name="reader"></param>
        /// <returns></returns>
        protected override Error PostHandleMessage(GameObject obj, CreateMessage msg, PacketBuffer packet, BinaryReader reader)
        {
            // Convert position to Unity position.
            obj.transform.localPosition = FrameTransform.RemoteToUnity(obj.transform.localPosition, ServerInfo.CoordinateFrame);

            // Read the text in the buffer.
            int textLength = reader.ReadUInt16();

            if (textLength > 0)
            {
                TextMesh textMesh = obj.GetComponent <TextMesh>();
                if (textMesh == null)
                {
                    textMesh = obj.AddComponent <TextMesh>();
                }

                byte[] textBytes = reader.ReadBytes(textLength);
                textMesh.text = System.Text.Encoding.UTF8.GetString(textBytes);
                ShapeComponent shapeComp = obj.GetComponent <ShapeComponent>();
                if (shapeComp != null)
                {
                    textMesh.fontSize = (int)msg.Attributes.ScaleZ;
                    textMesh.color    = shapeComp.Colour;
                }
            }

            if ((msg.Flags & (ushort)Text3DFlag.SceenFacing) != 0)
            {
                // Need to use -forward for text.
                ScreenFacing.AddToManager(obj, -Vector3.forward, Vector3.up);
            }

            return(base.PostHandleMessage(obj, msg, packet, reader));
        }
Пример #2
0
        /// <summary>
        /// Handle additional <see cref="UpdateMessage"/> data.
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="msg"></param>
        /// <param name="packet"></param>
        /// <param name="reader"></param>
        /// <returns></returns>
        protected override Error PostHandleMessage(GameObject obj, UpdateMessage msg, PacketBuffer packet, BinaryReader reader)
        {
            TextMesh       textMesh  = obj.GetComponent <TextMesh>();
            ShapeComponent shapeComp = obj.GetComponent <ShapeComponent>();

            if (textMesh != null && shapeComp != null)
            {
                textMesh.fontSize = (int)msg.Attributes.ScaleZ;
                textMesh.color    = shapeComp.Colour;
            }

            // Convert position to Unity position.
            obj.transform.localPosition = FrameTransform.RemoteToUnity(obj.transform.localPosition, ServerInfo.CoordinateFrame);

            if (shapeComp != null && (msg.Flags & (ushort)Text3DFlag.SceenFacing) != (shapeComp.ObjectFlags & (ushort)Text3DFlag.SceenFacing))
            {
                // Screen facing flag changed.
                if ((msg.Flags & (ushort)Text3DFlag.SceenFacing) != 0)
                {
                    // Need to use -forward for text.
                    ScreenFacing.AddToManager(obj, -Vector3.forward, Vector3.up);
                }
                else
                {
                    // Need to use -forward for text.
                    ScreenFacing.RemoveFromManager(obj);
                }
            }
            return(new Error());
        }
Пример #3
0
        /// <summary>
        /// The primary message handling function.
        /// </summary>
        /// <param name="packet"></param>
        /// <param name="reader"></param>
        /// <returns></returns>
        public override Error ReadMessage(PacketBuffer packet, BinaryReader reader)
        {
            CameraMessage msg = new CameraMessage();

            if (!msg.Read(reader))
            {
                return(new Error(ErrorCode.MalformedMessage));
            }

            CameraInfo camera = null;

            if (_cameras.ContainsKey(msg.CameraID))
            {
                camera = _cameras[msg.CameraID];
            }
            else
            {
                GameObject obj = new GameObject(string.Format("Camera {0}", msg.CameraID));
                camera = obj.AddComponent <CameraInfo>();
                _cameras.Add(msg.CameraID, camera);
                obj.transform.SetParent(_root.transform, false);
                camera.ID = msg.CameraID;
            }

            camera.Near = msg.Near;
            camera.Far  = msg.Far;
            camera.FOV  = msg.FOV;

            Transform transform = camera.transform;
            Vector3   dir       = FrameTransform.RemoteToUnity(new Vector3(msg.DirX, msg.DirY, msg.DirZ), ServerInfo.CoordinateFrame);
            Vector3   up        = FrameTransform.RemoteToUnity(new Vector3(msg.UpX, msg.UpY, msg.UpZ), ServerInfo.CoordinateFrame);

            transform.localPosition = FrameTransform.RemoteToUnity(new Vector3(msg.X, msg.Y, msg.Z), ServerInfo.CoordinateFrame);
            transform.LookAt(transform.position + dir, up);

            return(new Error());
        }