public void SendTPPCNetworkTime(long time) { if (this.serverConnection != null && this.serverConnection.IsConnected() && HolographicCameraManager.Instance != null) { // Create an outgoing network message to contain all the info we want to send NetworkOutMessage msg = CreateMessage((byte)TestMessageID.SetNetworkTime); msg.Write(time); #if UNITY_EDITOR if (HolographicCameraManager.Instance == null || HolographicCameraManager.Instance.tppcUser == null || !HolographicCameraManager.Instance.tppcUser.IsValid()) { // Send the message as a broadcast, which will cause the server to forward it to all other users in the session. serverConnection.Broadcast( msg, MessagePriority.Immediate, MessageReliability.UnreliableSequenced, MessageChannel.Avatar); } else { // We have a known tppc user, only send the offset time to that device. serverConnection.SendTo( HolographicCameraManager.Instance.tppcUser, ClientRole.Primary, msg, MessagePriority.Immediate, MessageReliability.UnreliableSequenced, MessageChannel.Avatar); } #endif } }
/// <summary> /// カメラのtransformをBroadcastしてもらうようサーバに依頼する /// </summary> /// <param name="position"></param> /// <param name="rotation"></param> public void SendHeadTransform(Vector3 position, Quaternion rotation) { if (serverConnection != null && serverConnection.IsConnected()) { NetworkOutMessage msg = CreateMessage((byte)TestMessageID.HeadTransform); AppendHeadTransform(msg, position, rotation); serverConnection.Broadcast( msg, MessagePriority.Immediate, MessageReliability.UnreliableSequenced, MessageChannel.Avatar); } }
public void SendStartGameCommand() { if (serverConnection != null && serverConnection.IsConnected()) { NetworkOutMessage msg = CreateMessage((byte)CommandType.Start); serverConnection.Broadcast( msg, MessagePriority.Immediate, MessageReliability.UnreliableSequenced, MessageChannel.UserMessageChannelStart); } }
public void SendCubePosition(Vector3 positon) { if (serverConnection != null && serverConnection.IsConnected()) { NetworkOutMessage msg = CreateMessage((byte)CustomMessageID.CubePostion); msg.Write(positon.x); msg.Write(positon.y); msg.Write(positon.z); serverConnection.Broadcast(msg, MessagePriority.Immediate, MessageReliability.ReliableOrdered, MessageChannel.Default); } }
// 将Cube位置广播给其他用户 public void SendCubePosition(Vector3 position, MessageReliability?reliability = MessageReliability.ReliableOrdered) { if (serverConnection != null && serverConnection.IsConnected()) { // 将Cube的位置写入消息 NetworkOutMessage msg = CreateMessage((byte)CustomMessageID.CubePosition); msg.Write(position.x); msg.Write(position.y); msg.Write(position.z); // 将消息广播给其他人 serverConnection.Broadcast(msg, MessagePriority.Immediate, //立即发送 reliability.Value, //可靠排序数据包 MessageChannel.Default); // 默认频道 } }
public void SyncMessage(HoloMessageType type, string key, List <float> values, int priority = 5) { if (!this.IsMaster) { return; } if (Time.frameCount - _frameCountSinceLastSync < priority) { return; } _frameCountSinceLastSync = Time.frameCount; UnityEngine.Debug.Log($"Sending key {key} value {string.Join(" ", values.Select(x => x.ToString()))}"); var msg = CreateMessage((byte)type, key, values); _serverConnection.Broadcast(msg); }