Exemplo n.º 1
0
        //============ TinyNetIdentity Functions ============//

        /// <summary>
        /// Applies the initial state of an object (it's <see cref="TinyNetSyncVar"/>).
        /// </summary>
        /// <param name="tinyNetId">The <see cref="TinyNetIdentity"/>r.</param>
        /// <param name="position">The position.</param>
        /// <param name="initialState">The initial state.</param>
        /// <param name="networkID">The network identifier.</param>
        /// <param name="newGameObject">The new <see cref="GameObject"/>.</param>
        void ApplyInitialState(TinyNetIdentity tinyNetId, Vector3 position, byte[] initialState, int networkID, GameObject newGameObject)
        {
            if (!tinyNetId.gameObject.activeSelf)
            {
                tinyNetId.gameObject.SetActive(true);
            }

            tinyNetId.transform.position = position;

            tinyNetId.OnNetworkCreate();

            if (initialState != null && initialState.Length > 0)
            {
                var initialStateReader = new NetDataReader(initialState);
                tinyNetId.DeserializeAllTinyNetObjects(initialStateReader, true);
            }

            if (newGameObject == null)
            {
                return;
            }

            newGameObject.SetActive(true);
            tinyNetId.ReceiveNetworkID(networkID);
            AddTinyNetIdentityToList(tinyNetId);

            // If the object was spawned as part of the initial replication (s_TineNetObjectSpawnFinishedMessage.state == 0) it will have it's OnStartClient called by OnObjectSpawnFinished.
            if (_isSpawnFinished)
            {
                tinyNetId.OnStartClient();
            }
        }
Exemplo n.º 2
0
        //============ TinyNetIdentity Functions ============//

        /// <summary>
        /// Applies the initial state of an object (it's <see cref="TinyNetSyncVar"/>).
        /// </summary>
        /// <param name="tinyNetId">The <see cref="TinyNetIdentity"/>r.</param>
        /// <param name="position">The position.</param>
        /// <param name="initialState">The initial state.</param>
        /// <param name="networkID">The network identifier.</param>
        /// <param name="newGameObject">The new <see cref="GameObject"/>.</param>
        void ApplyInitialState(TinyNetIdentity tinyNetId, Vector3 position, byte[] initialState, int networkID, GameObject newGameObject, ushort frameTick)
        {
            if (!tinyNetId.gameObject.activeSelf)
            {
                tinyNetId.gameObject.SetActive(true);
            }

            tinyNetId.transform.position = position;

            tinyNetId.OnNetworkCreate();

            if (newGameObject != null)
            {
                tinyNetId.ReceiveNetworkID(new TinyNetworkID(networkID));
            }

            if (initialState != null && initialState.Length > 0)
            {
                _stateUpdateReader.Clear();
                _stateUpdateReader.SetSource(initialState);
                _stateUpdateReader.SetFrameTick(frameTick);
                tinyNetId.TinyDeserialize(_stateUpdateReader, true);
            }

            // If this is null then this object already existed (already have a networkID and was registered in TinyNetScene), just apply the update to existing object
            if (newGameObject == null)
            {
                return;
            }

            newGameObject.SetActive(true);
            tinyNetId.ReceiveNetworkID(new TinyNetworkID(networkID));
            AddTinyNetIdentityToList(tinyNetId);

            // If the object was spawned as part of the initial replication (s_TineNetObjectSpawnFinishedMessage.state == 0) it will have it's OnStartClient called by OnObjectSpawnFinished.
            if (_isSpawnFinished)
            {
                tinyNetId.OnStartClient();
            }
        }