コード例 #1
0
ファイル: ObjectSyncComponent.cs プロジェクト: Najsr/MSCMP
        /// <summary>
        /// Send object sync as the host.
        /// </summary>
        public void SendObjectSyncHost(int objectID, Vector3 pos, Quaternion rot, ObjectSyncManager.SyncTypes syncType, float[] syncedVariables, ObjectSyncManager.Flags flags)
        {
            Network.Messages.ObjectSyncMessage msg = new Network.Messages.ObjectSyncMessage();

            msg.objectID = objectID;
            msg.SyncType = (int)syncType;
            if (syncedVariables != null)
            {
                msg.SyncedVariables = syncedVariables;
            }

            switch (flags)
            {
            case ObjectSyncManager.Flags.Full:
                msg.Position = Utils.GameVec3ToNet(pos);
                msg.Rotation = Utils.GameQuatToNet(rot);
                break;

            case ObjectSyncManager.Flags.RotationOnly:
                msg.Rotation = Utils.GameQuatToNet(rot);
                break;

            case ObjectSyncManager.Flags.PositionOnly:
                msg.Position = Utils.GameVec3ToNet(pos);
                break;
            }

            if (syncType != ObjectSyncManager.SyncTypes.PeriodicSync && syncType != ObjectSyncManager.SyncTypes.GenericSync)
            {
                Network.Messages.ObjectSyncMessage msgBroadcast = new Network.Messages.ObjectSyncMessage();
                // Set owner as host.
                if (syncType == ObjectSyncManager.SyncTypes.SetOwner)
                {
                    if (Owner == null)
                    {
                        Owner                 = NetManager.Instance.GetLocalPlayer();
                        SyncEnabled           = true;
                        msgBroadcast.SyncType = (int)ObjectSyncManager.SyncTypes.SetOwner;
                    }
                }
                // Remove owner as host.
                else if (syncType == ObjectSyncManager.SyncTypes.RemoveOwner)
                {
                    Owner = null;
                    OwnerRemoved();
                    msgBroadcast.SyncType = (int)ObjectSyncManager.SyncTypes.RemoveOwner;
                }
                // Force take sync control as host.
                else if (syncType == ObjectSyncManager.SyncTypes.ForceSetOwner)
                {
                    SyncEnabled           = true;
                    msgBroadcast.SyncType = (int)ObjectSyncManager.SyncTypes.ForceSetOwner;
                }

                // Send updated ownership info to other clients.
                msgBroadcast.objectID      = msg.objectID;
                msgBroadcast.OwnerPlayerID = NetManager.Instance.GetPlayerIDBySteamID(Steamworks.SteamUser.GetSteamID());
                NetManager.Instance.BroadcastMessage(msgBroadcast, Steamworks.EP2PSend.k_EP2PSendReliable);
            }
            else
            {
                NetManager.Instance.BroadcastMessage(msg, Steamworks.EP2PSend.k_EP2PSendReliable);
            }
        }
コード例 #2
0
ファイル: ObjectSyncComponent.cs プロジェクト: Najsr/MSCMP
        /// <summary>
        /// Send object sync.
        /// </summary>
        /// <param name="objectID">The Object ID of the object.</param>
        /// <param name="setOwner">Set owner of the object.</param>
        public void SendObjectSync(int objectID, Vector3 pos, Quaternion rot, ObjectSyncManager.SyncTypes syncType, float[] syncedVariables, ObjectSyncManager.Flags flags)
        {
            if (NetManager.Instance.IsHost)
            {
                SendObjectSyncHost(objectID, pos, rot, syncType, syncedVariables, flags);
                return;
            }

            Network.Messages.ObjectSyncMessage msg = new Network.Messages.ObjectSyncMessage();
            msg.objectID = objectID;
            msg.SyncType = (int)syncType;
            if (syncedVariables != null)
            {
                msg.SyncedVariables = syncedVariables;
            }

            switch (flags)
            {
            case ObjectSyncManager.Flags.Full:
                msg.Position = Utils.GameVec3ToNet(pos);
                msg.Rotation = Utils.GameQuatToNet(rot);
                break;

            case ObjectSyncManager.Flags.RotationOnly:
                msg.Rotation = Utils.GameQuatToNet(rot);
                break;

            case ObjectSyncManager.Flags.PositionOnly:
                msg.Position = Utils.GameVec3ToNet(pos);
                break;
            }

            NetManager.Instance.BroadcastMessage(msg, Steamworks.EP2PSend.k_EP2PSendReliable);
        }