public override void OnStartClient() { if (!parentNetId.IsEmpty()) { SetParent(parentNetId); } }
protected void SetSyncVarGameObject(GameObject newGameObject, ref GameObject gameObjectField, uint dirtyBit, ref NetworkInstanceId netIdField) { if (!SyncVarHookGuard) { NetworkInstanceId networkInstanceId = default; if (newGameObject != null) { var component = newGameObject.GetComponent <QNetworkIdentity>(); if (component != null) { networkInstanceId = component.NetId; if (networkInstanceId.IsEmpty()) { QLog.Warning( $"SetSyncVarGameObject GameObject {newGameObject} has a zero netId. Maybe it is not spawned yet?"); } } } NetworkInstanceId networkInstanceId2 = default; if (gameObjectField != null) { networkInstanceId2 = gameObjectField.GetComponent <QNetworkIdentity>().NetId; } if (networkInstanceId != networkInstanceId2) { QLog.Log( $"SetSyncVar GameObject {GetType().Name} bit [{dirtyBit}] netfieldId:{networkInstanceId2}->{networkInstanceId}"); SetDirtyBit(dirtyBit); gameObjectField = newGameObject; netIdField = networkInstanceId; } } }
public virtual bool validLot() { bool isValid = false; if (!lot.IsEmpty() && (lot != NetworkInstanceId.Invalid) && (getLocalInstance(lot) != null)) { isValid = true; } return(isValid); }
protected bool isValidNetId(NetworkInstanceId netId) { bool b = false; if (!netId.IsEmpty() && netId != NetworkInstanceId.Invalid) { b = true; } return(b); }
public virtual bool validOwner() { bool isValid = false; if (!owner.IsEmpty() && (owner != NetworkInstanceId.Invalid) && (getLocalInstance(owner) != null)) { isValid = true; } return(isValid); }
/// <summary> /// checks if the building is contained within a neighborhood /// </summary> /// <returns><c>true</c>, if part of a neighborhood, <c>false</c> otherwise.</returns> public override bool inNeighborhood() { bool b = false; if (!neighborhood.IsEmpty() && !(neighborhood == NetworkInstanceId.Invalid)) { b = true; } return(b); }
/// <summary> /// hook used when the job is set /// </summary> /// <param name="netId">Net identifier.</param> protected void setJob(NetworkInstanceId netId) { job = netId; if (netId.IsEmpty() || netId == NetworkInstanceId.Invalid) { jobBuilding = null; } else { jobBuilding = getBuilding(netId); } }
public void CmdSelectPlayerObject(GameObject currentObj, string playerType) { //Store the NetworkConnection of local player NetworkConnection conn = currentObj.GetComponent <NetworkIdentity>().connectionToClient; //Instantiate prefab from Resource Folder GameObject go = NewPlayerObject(playerType, currentObj.transform.position, currentObj.transform.rotation); if (parentNetId.IsEmpty()) { //First time selecting a player object so we need to store the player netID go.GetComponent <Player>().parentNetId = currentObj.GetComponent <NetworkIdentity>().netId; } else { //Switching player object, so we need to pass the stored player NetID go.GetComponent <Player>().parentNetId = currentObj.GetComponent <Player>().parentNetId; NetworkServer.Destroy(currentObj); } //Assign local authority NetworkServer.ReplacePlayerForConnection(conn, go, 0); }
/// <summary> /// hook used when the residence is set /// </summary> /// <param name="netId">Net identifier.</param> public void setResidence(NetworkInstanceId netId) { residence = netId; if (netId.IsEmpty() || netId == NetworkInstanceId.Invalid) { residenceBuilding = null; } else { residenceBuilding = getBuilding(netId); oldRent = residenceBuilding.playerSetRent; } }
public virtual bool validRegion() { bool isValid = false; if (!region.IsEmpty() && (region != NetworkInstanceId.Invalid) && (getLocalInstance(region) != null)) { isValid = true; } else if (validLot() && getLocalInstance(lot).GetComponent <Lot> ().validRegion()) { isValid = true; } return(isValid); }
/// <summary> /// Sets the player as parent and initialize. /// </summary> /// <param name="id">The NetworkInstaceId of the player.</param> public void SetActor(NetworkInstanceId id) { actorId = id; if (!id.IsEmpty()) { // Set new Player GameObject actorObject = NetworkServer.FindLocalObject(id); if (!actorObject) { actorObject = ClientScene.FindLocalObject(id); } actor = actorObject.GetComponent <Actor>(); actor.footCharacter = this; transform.SetParent(actor.transform); transform.localPosition = Vector3.zero; transform.localRotation = Quaternion.identity; } }
protected IEnumerator WaitFor(NetworkInstanceId id) { if (id.IsEmpty()) { Debug.LogWarning($"{this} tried to wait on an empty (0) id"); yield break; } int tries = 0; while ((NetworkObject = ClientScene.FindLocalObject(id)) == null) { if (tries++ > 10) { Debug.LogWarning($"{this} could not find object with id {id}"); yield break; } yield return(YieldHelper.EndOfFrame); } }
protected IEnumerator WaitFor(NetworkInstanceId id) { if (id.IsEmpty()) { Logger.LogWarningFormat("{0} tried to wait on an empty (0) id", Category.NetMessage, this.GetType().Name); yield break; } int tries = 0; while ((NetworkObject = ClientScene.FindLocalObject(id)) == null) { if (tries++ > 10) { Logger.LogWarningFormat("{0} could not find object with id {1}", Category.NetMessage, this.GetType().Name, id); yield break; } yield return(global::WaitFor.EndOfFrame); } }
private void LogCollider(EventType type, Collider other) { if (netId.IsEmpty()) { if (GetComponent <NetworkIdentity>() != null) { netId = GetComponent <NetworkIdentity>().netId; } else { throw new MissingComponentException("CollisionSynchronization cannot be used without a NetworkIdentity component!"); } } NetworkIdentity networkIdentity = other.gameObject.GetComponent <NetworkIdentity>(); if (networkIdentity != null) { EventSynchronizer.LogEvent(type, netId, networkIdentity.netId.Value); } }
public override void OnStartClient() { if (parentNetId.IsEmpty()) { return; } GameObject parentObject = ClientScene.FindLocalObject(parentNetId); Transform parent = parentObject.transform; if (parentObject.GetComponent <ItemManager>()) { parent = parentObject.GetComponent <ItemManager>().hand; } // Set parent and position transform.SetParent(parent); transform.localPosition = Vector3.zero; transform.localRotation = Quaternion.identity; DisablePhysics(); }
// Update is called once per frame void Update() { if (gmObject == null) { gmObject = GameObject.Find("GameManager"); buildButton = GameObject.Find("BuildButtonText").GetComponent <BuildButtonPress>(); sendButton = GameObject.Find("SendButtonText").GetComponent <SendButtonPress>(); } else if (gm == null) { gm = gmObject.GetComponent <GameManager>(); } if (myID == "" || myID == "Player(Clone)") { myID = myPN.playerUniqueIdentity; Debug.Log(myID); } else if (mySpawner == null) { if (gm != null) { int myIdx = gm.MyPlayerIndex(myID); if (myIdx == -1) { Debug.Log("My index is not found yet"); } else { if (myIdx == 1) { Debug.Log("Set Spawner"); mySpawner = GameObject.Find("EnemySpawn2").GetComponent <SpawnUnit>(); enemySpawner = GameObject.Find("EnemySpawn1").GetComponent <SpawnUnit>(); myFinish = GameObject.Find("FinishLine1").GetComponent <FinishLine> (); enemyFinish = GameObject.Find("FinishLine2").GetComponent <FinishLine> (); } else if (myIdx == 0) { Debug.Log("Set Spawner"); mySpawner = GameObject.Find("EnemySpawn1").GetComponent <SpawnUnit>(); enemySpawner = GameObject.Find("EnemySpawn2").GetComponent <SpawnUnit>(); myFinish = GameObject.Find("FinishLine2").GetComponent <FinishLine> (); enemyFinish = GameObject.Find("FinishLine1").GetComponent <FinishLine> (); } } } } if (mySpawnID.IsEmpty()) { if (mySpawner != null) { Debug.Log("Set Spawn ID"); mySpawnID = mySpawner.GetComponent <NetworkIdentity> ().netId; mySpawner.sendPlayer = gameObject; enemySpawner.attackPlayer = gameObject; myFinish.SetPlayerToHurt(gameObject, myID); myFinish.SetMyPlayer(myID); enemyFinish.setOtherPlayer(gameObject, myID); } } if (!isLocalPlayer) { return; } else if (gm != null) { if (gm.gameRunning) { if (cursorReset == true) { cursorReset = false; } CheckButtons(); //Checks if any buttons are pressed } else { if (cursorReset == false) { cursorReset = true; Cursor.SetCursor(normalCursor, hotSpot, CursorMode.Auto); Cursor.visible = true; } } } }