public static GameObject FindLocalObject(NetworkInstanceId netId) { return(s_NetworkScene.FindLocalObject(netId)); }
public void Write(NetworkInstanceId value) { WritePackedUInt32(value.Value); }
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(); } }
internal bool RemoveLocalObject(NetworkInstanceId netId) { return(m_LocalObjects.Remove(netId)); }
internal bool GetNetworkIdentity(NetworkInstanceId netId, out NetworkIdentity uv) { return(m_LocalObjects.TryGetValue(netId, out uv) && uv != null); }
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; } }