Exemplo n.º 1
0
        /// <summary>
        /// Called when an object is spawned on the client.
        /// </summary>
        public void OnStartClient()
        {
            if (bStartClientTwiceTest)
            {
                if (TinyNetLogLevel.logError)
                {
                    TinyLogger.LogError("OnStartClient CALLED TWICE FOR: " + gameObject + " netId:" + NetworkID + " localPlayerAuthority: " + _localPlayerAuthority);
                }
            }
            else
            {
                bStartClientTwiceTest = true;
            }

            for (int i = 0; i < _tinyNetObjects.Length; i++)
            {
                if (!isServer)
                {
                    TinyNetScene.AddTinyNetObjectToList(_tinyNetObjects[i]);
                }
                _tinyNetObjects[i].OnStartClient();
            }

            if (TinyNetLogLevel.logDev)
            {
                TinyLogger.Log("OnStartClient " + gameObject + " netId:" + NetworkID + " localPlayerAuthority: " + _localPlayerAuthority);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Called when destroyed by the network.
 /// </summary>
 public virtual void OnNetworkDestroy()
 {
     for (int i = 0; i < _tinyNetObjects.Length; i++)
     {
         TinyNetScene.RemoveTinyNetObjectFromList(_tinyNetObjects[i]);
         _tinyNetObjects[i].OnNetworkDestroy();
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Called when an object is spawned on the server.
        /// </summary>
        /// <param name="allowNonZeroNetId">If the object already have a NetworkId, it was probably recycled.</param>
        public void OnStartServer(bool allowNonZeroNetId)
        {
            if (_localPlayerAuthority)
            {
                // local player on server has NO authority
                _hasAuthority = false;
            }
            else
            {
                // enemy on server has authority
                _hasAuthority = true;
            }

            // If the instance/net ID is invalid here then this is an object instantiated from a prefab and the server should assign a valid ID
            if (NetworkID == 0)
            {
                NetworkID = TinyNetGameManager.instance.NextNetworkID;

                for (int i = 0; i < _tinyNetObjects.Length; i++)
                {
                    _tinyNetObjects[i].ReceiveNetworkID(TinyNetGameManager.instance.NextNetworkID);
                }
            }
            else
            {
                if (allowNonZeroNetId)
                {
                    //allowed
                }
                else
                {
                    if (TinyNetLogLevel.logError)
                    {
                        TinyLogger.LogError("Object has non-zero netId " + NetworkID + " for " + gameObject);
                    }
                    return;
                }
            }

            for (int i = 0; i < _tinyNetObjects.Length; i++)
            {
                TinyNetScene.AddTinyNetObjectToList(_tinyNetObjects[i]);
                _tinyNetObjects[i].OnStartServer();
            }

            if (TinyNetLogLevel.logDev)
            {
                TinyLogger.Log("OnStartServer " + gameObject + " netId:" + NetworkID);
            }

            if (_hasAuthority)
            {
                OnStartAuthority();
            }
        }