Locate() публичный статический Метод

Locate a Simple Networked Monobehavior given a ID
public static Locate ( ulong id ) : SimpleNetworkedMonoBehavior
id ulong ID of the Simple Networked Monobehavior
Результат SimpleNetworkedMonoBehavior
Пример #1
0
        /// <summary>
        /// Prepare the NetworkingStream to be used
        /// </summary>
        /// <param name="socket">The NetWorker socket to be used</param>
        /// <param name="identifierType">The type of Identifier it is going to prepare</param>
        /// <param name="networkedBehavior">NetworkedBehavior to use</param>
        /// <param name="extra">Extra parameters to prepare</param>
        /// <param name="receivers">Who shall be receiving this NetworkingStream</param>
        /// <param name="bufferedRPC">To know if this is a Buffered RPC</param>
        /// <param name="customidentifier">A custom Identifier to be passed through</param>
        /// <returns></returns>
        public NetworkingStream Prepare(NetWorker socket, IdentifierType identifierType, ulong networkBehaviorId, BMSByte extra = null, NetworkReceivers receivers = NetworkReceivers.All, bool bufferedRPC = false, uint customidentifier = 0, ulong senderId = 0, bool noBehavior = false)
        {
            if (noBehavior)
            {
                NetworkedBehavior = null;
            }
            else
            {
                lock (networkedObjectMutex)
                {
                    NetworkedBehavior = SimpleNetworkedMonoBehavior.Locate(networkBehaviorId);
                }
            }

            if (ReferenceEquals(NetworkedBehavior, null) && (extra == null || extra.Size == 0))
            {
                throw new NetworkException(9, "Prepare was called but nothing was sent to write");
            }

            NetworkedBehaviorId = networkBehaviorId;

            return(PrepareFinal(socket, identifierType, networkBehaviorId, extra, receivers, bufferedRPC, customidentifier, senderId));
        }
Пример #2
0
        /// <summary>
        /// To consume the data of the NetWorker with a player's data
        /// </summary>
        /// <param name="socket">The NetWorker socket to be used</param>
        /// <param name="sender">The player who is sending the data</param>
        /// <param name="message">Data that is being sent</param>
        /// <returns></returns>
        public NetworkingStream Consume(NetWorker socket, NetworkingPlayer sender, BMSByte message)
        {
            lock (networkedObjectMutex)
            {
                Sender = sender;

                NetworkedBehaviorId = 0;
                ByteReadIndex       = 0;
                Bytes.Clone(message);
                FrameIndex = message[message.StartIndex() + message.Size - 1];

                ProtocolType = (Networking.ProtocolType)ObjectMapper.Map <int>(this);
                Receivers    = (NetworkReceivers)ObjectMapper.Map <int>(this);
                RealSenderId = ObjectMapper.Map <ulong>(this);

                if (ProtocolType == Networking.ProtocolType.HTTP || ProtocolType == Networking.ProtocolType.QuickUDP || ProtocolType == Networking.ProtocolType.QuickTCP)
                {
                    Ready = true;
                    return(this);
                }

                char identifier = (char)ReadByte();                // ObjectMapper.Map<char>(this);

                if (identifier == identifier_NONE)
                {
                    identifierType = IdentifierType.None;
                }
                else if (identifier == identifier_RPC)
                {
                    identifierType = IdentifierType.RPC;
                    BufferedRPC    = ReadByte() == 1;
                }
                else if (identifier == identifier_PLAYER)
                {
                    identifierType = IdentifierType.Player;
                }
                else if (identifier == identifier_NETWORKED_BEHAVIOR)
                {
                    identifierType = IdentifierType.NetworkedBehavior;
                }
                else if (identifier == identifier_DISCONNECT)
                {
                    identifierType = IdentifierType.Disconnect;
                }
                else if (identifier == identifier_CUSTOM)
                {
                    identifierType = IdentifierType.Custom;
                }

                NetworkedBehaviorId = ObjectMapper.Map <ulong>(this);

                NetworkedBehavior = SimpleNetworkedMonoBehavior.Locate(NetworkedBehaviorId);

                if (NetworkedBehaviorId > 0 && ReferenceEquals(NetworkedBehavior, null) && identifierType != IdentifierType.RPC)
                {
                    return(null);
                }

                // Remove the size of ProtocolType, identifier, NetworkId, etc.
                Bytes.RemoveStart(ByteReadIndex);

                ByteReadIndex = 0;

                if (socket.Uniqueidentifier == 0 && !socket.IsServer && identifierType == IdentifierType.Player)
                {
                    if (socket != null)
                    {
                        socket.AssignUniqueId(ObjectMapper.Map <ulong>(this));
                        Bytes.RemoveStart(sizeof(ulong));
                    }
                    else
                    {
                        Bytes.RemoveStart(sizeof(ulong));
                    }

                    if (socket != null && !socket.IsServer)
                    {
                        if (!socket.MasterServerFlag)
                        {
                            if (socket.UsingUnityEngine && ((ReferenceEquals(NetworkingManager.Instance, null) || !NetworkingManager.Instance.IsSetup || ReferenceEquals(NetworkingManager.Instance.OwningNetWorker, null))))
                            {
                                NetworkingManager.setupActions.Add(socket.GetNewPlayerUpdates);
                            }
                            else
                            {
                                socket.GetNewPlayerUpdates();
                            }
                        }
                    }
                }

                ByteReadIndex = 0;

                if (identifierType == IdentifierType.NetworkedBehavior && !ReferenceEquals(NetworkedBehavior, null))
                {
                    if (NetworkedBehavior is NetworkedMonoBehavior)
                    {
                        ((NetworkedMonoBehavior)NetworkedBehavior).PrepareDeserialize(this);
                    }
                    else
                    {
                        throw new Exception("Only NetworkedMonoBehaviors can be used for serialization and deserialization across the network, object with id " + NetworkedBehavior.NetworkedId + " is not a \"NetworkedMonoBehavior\"");
                    }
                }

                if (identifierType == IdentifierType.Custom)
                {
                    Customidentifier = ObjectMapper.Map <uint>(this);
                    Bytes.RemoveStart(sizeof(uint));
                }

                ByteReadIndex = 0;

                Ready = true;

                if (NetworkedBehaviorId > 0 && ReferenceEquals(NetworkedBehavior, null))
                {
                    if (identifierType == IdentifierType.RPC)
                    {
                        SimpleNetworkedMonoBehavior.QueueRPCForInstantiate(NetworkedBehaviorId, this);
                        QueuedRPC = true;
                        return(null);
                    }

                    return(null);
                }

                return(this);
            }
        }