public void RpcAddMerge(GameObject ownerObject, GameObject mergingObject, bool hasAuthority, GameObject manager) { Debug.Log("This is triggered: " + this.hasAuthority + " " + hasAuthority); GameUnit ownerUnit = ownerObject.GetComponent <GameUnit>(); GameUnit mergingUnit = mergingObject.GetComponent <GameUnit>(); if (ownerUnit != null && mergingUnit != null) { //Update the previous level to be the current unit's level before the merge. ownerUnit.previousLevel = ownerUnit.level; ownerUnit.isMerging = mergingUnit.isMerging = true; if (ownerUnit.unitAttributes != null) { float mergeSpeedFactor = ownerUnit.unitAttributes.mergePrefabList[ownerUnit.level]; NavMeshAgent ownerAgent = ownerObject.GetComponent <NavMeshAgent>(); ownerAgent.Stop(); NavMeshAgent mergingAgent = mergingObject.GetComponent <NavMeshAgent>(); mergingAgent.Stop(); if (manager != null) { Debug.Log("Manager has been found."); MergeManager mergeManager = manager.GetComponent <MergeManager>(); if (mergeManager != null) { Debug.Log("Adding new merge group..."); mergeManager.mergeList.Add(new MergeGroup(ownerUnit, mergingUnit, mergeSpeedFactor)); } } } } }
public void ServerInitialize() { //Server code //This is run for spawning new non-player objects. Since it is a server calling to all clients (local and remote), it needs to pass in a //NetworkConnection that connects from server to THAT PARTICULAR client, who is going to own client authority on the spawned object. //Checking if global manager exists; GlobalManager globalManagerObject = GameObject.FindObjectOfType <GlobalManager>(); if (globalManagerObject != null) { this.doesGlobalManagerExist = true; } else { this.doesGlobalManagerExist = false; } //Setting up Player GameObject playerUmbrellaObject = new GameObject("Player"); GameObject playerUnitUmbrellaObject = new GameObject("Units"); playerUnitUmbrellaObject.transform.SetParent(playerUmbrellaObject.transform); playerUmbrellaObject.tag = "Player"; //Player unit GameObject playerObject = MonoBehaviour.Instantiate(this.spawnPrefab) as GameObject; playerObject.transform.SetParent(playerUnitUmbrellaObject.transform); playerObject.transform.position = this.transform.position; NetworkIdentity objIdentity = playerObject.GetComponent <NetworkIdentity>(); NetworkServer.SpawnWithClientAuthority(playerObject, this.connectionToClient); //Player selection manager GameObject manager = MonoBehaviour.Instantiate(this.selectionManagerPrefab) as GameObject; manager.transform.SetParent(playerUmbrellaObject.transform); SelectionManager selectionManager = manager.GetComponent <SelectionManager>(); if (selectionManager != null) { selectionManager.allObjects.Add(playerObject); selectionManager.authorityOwner = objIdentity.clientAuthorityOwner; } NetworkServer.SpawnWithClientAuthority(manager, this.connectionToClient); //Player split manager manager = MonoBehaviour.Instantiate(this.splitManagerPrefab) as GameObject; manager.transform.SetParent(playerUmbrellaObject.transform); SplitManager splitManager = manager.GetComponent <SplitManager>(); if (splitManager != null) { splitManager.selectionManager = selectionManager; splitManager.unitParent = playerUnitUmbrellaObject.transform; if (this.doesGlobalManagerExist && globalManagerObject != null) { splitManager.globalManagerObject = globalManagerObject; splitManager.maxUnitCount = globalManagerObject.playerMaxUnitCount; } } NetworkServer.SpawnWithClientAuthority(manager, this.connectionToClient); //Player merge manager manager = MonoBehaviour.Instantiate(this.mergeManagerPrefab) as GameObject; manager.transform.SetParent(playerUmbrellaObject.transform); MergeManager mergeManager = manager.GetComponent <MergeManager>(); if (mergeManager != null) { mergeManager.selectionManager = selectionManager; } NetworkServer.SpawnWithClientAuthority(manager, this.connectionToClient); //Unit Attributes Tracker manager = MonoBehaviour.Instantiate(this.unitAttributesPrefab) as GameObject; manager.transform.SetParent(playerUmbrellaObject.transform); UnitAttributes attributes = manager.GetComponent <UnitAttributes>(); if (attributes != null) { splitManager.unitAttributes = attributes; mergeManager.unitAttributes = attributes; } NetworkServer.SpawnWithClientAuthority(manager, this.connectionToClient); RpcCameraSetup(playerObject); int colorValue; switch (Spawner.colorCode) { default: colorValue = -1; break; case 0: colorValue = 0; break; case 1: colorValue = 1; break; case 2: colorValue = 2; break; } Spawner.colorCode++; if (Spawner.colorCode > 2) { Spawner.colorCode = 0; } RpcUnitAttributesSetup(manager, playerObject, colorValue); NetworkServer.SpawnWithClientAuthority(this.remotePrefab, this.connectionToClient); }