IEnumerator CallSyncHeartbeat()
 {
     while (true)
     {
         if (OpenRelayClient.inRoom)
         {
             OpenRelayClient.Sync((byte)EventType.Heatbeat, BitConverter.GetBytes(0), currentObjectId, OpenRelayClient.BroadcastFilter.Default);
         }
         yield return new WaitForSeconds(2f);
     }
 }
Exemplo n.º 2
0
 IEnumerator CallRaiseEvent()
 {
     while (true)
     {
         if (OpenRelayClient.inRoom)
         {
             OpenRelayClient.Sync(0, System.Text.Encoding.ASCII.GetBytes("2"), currentObjectId, OpenRelayClient.BroadcastFilter.Default);
         }
         yield return(new WaitForSeconds(0.05f));
     }
 }
Exemplo n.º 3
0
        public void SyncTransform()
        {
            if (!owner)
            {
                return;
            }

            var delta = Delta.None;

            if (beforePosition != transform.position)
            {
                delta |= Delta.Position;
            }
            //Debug.Log(beforePosition + ":" + transform.position);
            if (beforeRotation != transform.rotation)
            {
                delta |= Delta.Rotation;
            }
            //Debug.Log(beforeRotation + ":" + transform.rotation);
            if (beforeScale != transform.localScale)
            {
                delta |= Delta.Scale;
            }
            //Debug.Log(beforeScale + ":" + transform.localScale);

            if (delta == Delta.None)
            {
                return;
            }

            Debug.Log("called");

            //var messageBytes = new byte[sizeof(float) * 3 + sizeof(float) * 4];
            var stream  = new MemoryStream(transformBytes);
            var message = new EndiannessBinaryWriter(stream);

            try
            {
                // 1byte
                message.Write((byte)delta);
                // alignment
                message.Write(alignment3);

                if (delta.HasFlag(Delta.Position))
                {
                    // 12byte
                    message.Write(transform.position.x);
                    message.Write(transform.position.y);
                    message.Write(transform.position.z);
                }

                if (delta.HasFlag(Delta.Rotation))
                {
                    // 16byte
                    message.Write(transform.rotation.x);
                    message.Write(transform.rotation.y);
                    message.Write(transform.rotation.z);
                    message.Write(transform.rotation.w);
                }

                if (delta.HasFlag(Delta.Scale))
                {
                    // 12byte
                    message.Write(transform.position.x);
                    message.Write(transform.position.y);
                    message.Write(transform.position.z);
                }

                OpenRelayClient.Sync((byte)EventType.TransformContent, transformBytes, (UInt16)playerId, OpenRelayClient.BroadcastFilter.Default);

                if (delta.HasFlag(Delta.Position))
                {
                    beforePosition = transform.position;
                }
                if (delta.HasFlag(Delta.Rotation))
                {
                    beforeRotation = transform.rotation;
                }
                if (delta.HasFlag(Delta.Scale))
                {
                    beforeScale = transform.localScale;
                }
            }
            catch (Exception e)
            {
                Debug.LogError("error: " + e.Message);
                Debug.LogError("stacktrace: " + e.StackTrace);
            }
            message.Close();
            stream.Close();
        }