Esempio n. 1
0
 public static GameObject FindLocalObject(NetworkInstanceId netId)
 {
     return(s_NetworkScene.FindLocalObject(netId));
 }
Esempio n. 2
0
 public void Write(NetworkInstanceId value)
 {
     WritePackedUInt32(value.Value);
 }
Esempio n. 3
0
        internal void OnStartServer(bool allowNonZeroNetId)
        {
            if (m_IsServer)
            {
                return;
            }
            m_IsServer     = true;
            m_HasAuthority = !m_LocalPlayerAuthority;

            m_Observers           = new List <NetworkConnection>();
            m_ObserverConnections = new HashSet <int>();
            CacheBehaviours();

            // 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 (netId.IsEmpty())
            {
                m_NetId = GetNextNetworkId();
            }
            else
            {
                if (!allowNonZeroNetId)
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("Object has non-zero netId " + netId + " for " + gameObject);
                    }
                    return;
                }
            }

            if (LogFilter.logDev)
            {
                Debug.Log("OnStartServer " + gameObject + " GUID:" + netId);
            }
            NetworkServer.SetLocalObjectOnServer(netId, gameObject);

            for (int i = 0; i < m_NetworkBehaviours.Length; i++)
            {
                NetworkBehaviour comp = m_NetworkBehaviours[i];
                try
                {
                    comp.OnStartServer();
                }
                catch (Exception e)
                {
                    Debug.LogError("Exception in OnStartServer:" + e.Message + " " + e.StackTrace);
                }
            }

            if (NetworkClient.active && NetworkServer.localClientActive)
            {
                // there will be no spawn message, so start the client here too
                ClientScene.SetLocalObject(netId, gameObject);
                OnStartClient();
            }

            if (m_HasAuthority)
            {
                OnStartAuthority();
            }
        }
Esempio n. 4
0
 internal bool RemoveLocalObject(NetworkInstanceId netId)
 {
     return(m_LocalObjects.Remove(netId));
 }
Esempio n. 5
0
 internal bool GetNetworkIdentity(NetworkInstanceId netId, out NetworkIdentity uv)
 {
     return(m_LocalObjects.TryGetValue(netId, out uv) && uv != null);
 }
Esempio n. 6
0
        protected void SetSyncVarGameObject(GameObject newGameObject, ref GameObject gameObjectField, ulong dirtyBit, ref NetworkInstanceId netIdField)
        {
            if (m_SyncVarGuard)
            {
                return;
            }

            NetworkInstanceId newGameObjectNetId = new NetworkInstanceId();

            if (newGameObject != null)
            {
                var uv = newGameObject.GetComponent <NetworkIdentity>();
                if (uv != null)
                {
                    newGameObjectNetId = uv.netId;
                    if (newGameObjectNetId.IsEmpty())
                    {
                        if (LogFilter.logWarn)
                        {
                            Debug.LogWarning("SetSyncVarGameObject GameObject " + newGameObject + " has a zero netId. Maybe it is not spawned yet?");
                        }
                    }
                }
            }

            NetworkInstanceId oldGameObjectNetId = new NetworkInstanceId();

            if (gameObjectField != null)
            {
                oldGameObjectNetId = gameObjectField.GetComponent <NetworkIdentity>().netId;
            }

            if (newGameObjectNetId != oldGameObjectNetId)
            {
                if (LogFilter.logDev)
                {
                    Debug.Log("SetSyncVar GameObject " + GetType().Name + " bit [" + dirtyBit + "] netfieldId:" + oldGameObjectNetId + "->" + newGameObjectNetId);
                }
                SetDirtyBit(dirtyBit);
                gameObjectField = newGameObject;
                netIdField      = newGameObjectNetId;
            }
        }