public void RpcUnitAttributesSetup(GameObject manager, GameObject playerObject, int colorValue) { Debug.Log("Setting up unit attributes."); GameUnit playerUnit = playerObject.GetComponent <GameUnit>(); if (playerUnit != null) { playerUnit.SetTeamColor(colorValue); } UnitAttributes attributes = manager.GetComponent <UnitAttributes>(); if (attributes != null && attributes.hasAuthority) { //CanvasSwitch canvasSwitch = GameObject.FindObjectOfType<CanvasSwitch>() as CanvasSwitch; //if (canvasSwitch != null) { // canvasSwitch.unitAttributes = attributes; //} GameObject content = GameObject.FindGameObjectWithTag("Content"); if (content != null) { Attributes attr = content.GetComponent <Attributes>(); if (attr != null) { attr.unitAttributes = attributes; } } if (playerUnit != null) { playerUnit.unitAttributes = attributes; } } }
public void CopyFrom(UnitAttributes tempAttr) { this.maxLevelCount = tempAttr.maxLevelCount; for (int i = 0; i < Attributes.MAX_NUM_OF_LEVELS; i++) { this.healthPrefabList.Add(tempAttr.healthPrefabList[i]); this.attackPrefabList.Add(tempAttr.attackPrefabList[i]); this.attackCooldownPrefabList.Add(tempAttr.attackCooldownPrefabList[i]); this.speedPrefabList.Add(tempAttr.speedPrefabList[i]); this.mergePrefabList.Add(tempAttr.mergePrefabList[i]); } this.splitPrefabFactor = tempAttr.splitPrefabFactor; }
void Start() { if (!this.hasAuthority) { return; } this.doNotAllowMerging = false; if (this.mergeList == null) { this.mergeList = new List <MergeGroup>(); } if (this.removeList == null) { this.removeList = new List <MergeGroup>(); } if (this.selectionManager == null) { GameObject[] managers = GameObject.FindGameObjectsWithTag("SelectionManager"); foreach (GameObject select in managers) { SelectionManager selectManager = select.GetComponent <SelectionManager>(); if (selectManager != null && selectManager.hasAuthority) { this.selectionManager = selectManager; break; } } if (this.selectionManager == null) { Debug.LogError("Merge Manager: Selection Manager is null. Please check."); } } if (this.unitAttributes == null) { GameObject[] attributes = GameObject.FindGameObjectsWithTag("UnitAttributes"); foreach (GameObject attribute in attributes) { UnitAttributes attr = attribute.GetComponent <UnitAttributes>(); if (attr != null && attr.hasAuthority) { this.unitAttributes = attr; break; } } if (this.unitAttributes == null) { Debug.LogError("Merge Manager: Unit Attributes Tracker is null. Please check."); } } }
public void RpcUpdateAnswer(float answer, int level, int propertyValue, NetworkInstanceId id) { //Debug.Log("I'm updating answers."); GameObject obj = ClientScene.FindLocalObject(id); UnitAttributes attr = obj.GetComponent <UnitAttributes>(); if (attr != null) { switch (propertyValue) { default: case 0: attr.healthPrefabList[level] = answer; break; case 1: attr.attackPrefabList[level] = answer; break; case 2: attr.speedPrefabList[level] = answer; break; case 3: attr.mergePrefabList[level] = answer; break; case 4: attr.attackCooldownPrefabList[level] = answer; break; case 5: attr.splitPrefabFactor = answer; break; } } //Debug.Log("I finished updating answers."); }
//Split Manager is designed to streamline the creation of new game units. //To achieve this, there needs to be two different array list that keeps track of all the creations, called Split Groups. //One keeps track of the Split Groups, the other removes them from the tracking list. public void Start() { if (!this.hasAuthority) { return; } if (this.splitGroupList == null) { this.splitGroupList = new List <SplitGroup>(); } if (this.selectionManager == null) { GameObject[] managers = GameObject.FindGameObjectsWithTag("SelectionManager"); foreach (GameObject manager in managers) { SelectionManager select = manager.GetComponent <SelectionManager>(); if (select != null && select.hasAuthority) { this.selectionManager = select; break; } } if (this.selectionManager == null) { Debug.LogError("Cannot find Selection Manager. Aborting"); } } if (this.unitAttributes == null) { GameObject[] attributes = GameObject.FindGameObjectsWithTag("UnitAttributes"); foreach (GameObject attribute in attributes) { UnitAttributes attr = attribute.GetComponent <UnitAttributes>(); if (attr != null && attr.hasAuthority) { this.unitAttributes = attr; break; } } if (this.unitAttributes == null) { Debug.LogError("Split Manager: Unit Attributes Tracker is null. Please check."); } } if (this.spawner == null) { GameObject[] spawners = GameObject.FindGameObjectsWithTag("Spawner"); foreach (GameObject obj in spawners) { Spawner spawner = obj.GetComponent <Spawner>(); if (spawner != null && spawner.hasAuthority) { this.spawner = spawner; break; } } if (this.spawner == null) { Debug.LogError("Spawner is never set. Please check."); } } if (this.unitParent == null) { this.unitParent = new GameObject("Units Parent").transform; NetworkIdentity identity = this.unitParent.gameObject.AddComponent <NetworkIdentity>(); identity.localPlayerAuthority = true; ClientScene.RegisterPrefab(this.unitParent.gameObject); this.unitParent.SetParent(this.transform); if (this.selectionManager != null) { foreach (GameObject obj in this.selectionManager.allObjects) { obj.transform.SetParent(this.unitParent); } } NetworkIdentity ident = this.GetComponent <NetworkIdentity>(); if (ident != null) { ident.localPlayerAuthority = true; CmdSpawn(this.unitParent.gameObject); Debug.Log("Spawning a new unit parent with client authority owner."); } else { Debug.LogError("Check to make sure this is created in the spawner."); } } }
//Split Manager is designed to streamline the creation of new game units. //To achieve this, there needs to be two different array list that keeps track of all the creations, called Split Groups. //One keeps track of the Split Groups, the other removes them from the tracking list. public void Start() { if (!this.hasAuthority) { return; } if (this.splitGroupList == null) { this.splitGroupList = new List<SplitGroup>(); } if (this.selectionManager == null) { GameObject[] managers = GameObject.FindGameObjectsWithTag("SelectionManager"); foreach (GameObject manager in managers) { SelectionManager select = manager.GetComponent<SelectionManager>(); if (select != null && select.hasAuthority) { this.selectionManager = select; break; } } if (this.selectionManager == null) { Debug.LogError("Cannot find Selection Manager. Aborting"); } } if (this.unitAttributes == null) { GameObject[] attributes = GameObject.FindGameObjectsWithTag("UnitAttributes"); foreach (GameObject attribute in attributes) { UnitAttributes attr = attribute.GetComponent<UnitAttributes>(); if (attr != null && attr.hasAuthority) { this.unitAttributes = attr; break; } } if (this.unitAttributes == null) { Debug.LogError("Split Manager: Unit Attributes Tracker is null. Please check."); } } if (this.spawner == null) { GameObject[] spawners = GameObject.FindGameObjectsWithTag("Spawner"); foreach (GameObject obj in spawners) { Spawner spawner = obj.GetComponent<Spawner>(); if (spawner != null && spawner.hasAuthority) { this.spawner = spawner; break; } } if (this.spawner == null) { Debug.LogError("Spawner is never set. Please check."); } } if (this.unitParent == null) { this.unitParent = new GameObject("Units Parent").transform; NetworkIdentity identity = this.unitParent.gameObject.AddComponent<NetworkIdentity>(); identity.localPlayerAuthority = true; ClientScene.RegisterPrefab(this.unitParent.gameObject); this.unitParent.SetParent(this.transform); if (this.selectionManager != null) { foreach (GameObject obj in this.selectionManager.allObjects) { obj.transform.SetParent(this.unitParent); } } NetworkIdentity ident = this.GetComponent<NetworkIdentity>(); if (ident != null) { ident.localPlayerAuthority = true; CmdSpawn(this.unitParent.gameObject); Debug.Log("Spawning a new unit parent with client authority owner."); } else { Debug.LogError("Check to make sure this is created in the spawner."); } } }
public void RpcUnitAttributesSetup(GameObject manager, GameObject playerObject, int colorValue) { Debug.Log("Setting up unit attributes."); GameUnit playerUnit = playerObject.GetComponent <GameUnit>(); if (playerUnit != null) { playerUnit.SetTeamColor(colorValue); } UnitAttributes attributes = manager.GetComponent <UnitAttributes>(); if (attributes != null && attributes.hasAuthority) { //CanvasSwitch canvasSwitch = GameObject.FindObjectOfType<CanvasSwitch>() as CanvasSwitch; //if (canvasSwitch != null) { // canvasSwitch.unitAttributes = attributes; //} GameObject content = GameObject.FindGameObjectWithTag("Content"); if (content != null) { Attributes attr = content.GetComponent <Attributes>(); if (attr != null) { attr.unitAttributes = attributes; } } if (playerUnit != null) { playerUnit.unitAttributes = attributes; AttributePanelUI attributePanelUI = GameObject.FindObjectOfType <AttributePanelUI>(); if (attributePanelUI != null) { foreach (Category cat in Category.Values) { List <LevelRate> levelRate = attributePanelUI.levelingRatesObject.allAttributes[cat.value]; switch (cat.value) { case 0: for (int i = 0; i < Attributes.MAX_NUM_OF_LEVELS; i++) { playerUnit.unitAttributes.healthPrefabList[i] = levelRate[i].rate; } break; case 1: for (int i = 0; i < Attributes.MAX_NUM_OF_LEVELS; i++) { playerUnit.unitAttributes.attackPrefabList[i] = levelRate[i].rate; } break; case 2: for (int i = 0; i < Attributes.MAX_NUM_OF_LEVELS; i++) { playerUnit.unitAttributes.speedPrefabList[i] = levelRate[i].rate; } break; case 3: playerUnit.unitAttributes.splitPrefabFactor = levelRate[0].rate; break; case 4: for (int i = 0; i < Attributes.MAX_NUM_OF_LEVELS; i++) { playerUnit.unitAttributes.mergePrefabList[i] = levelRate[i].rate; } break; case 5: for (int i = 0; i < Attributes.MAX_NUM_OF_LEVELS; i++) { playerUnit.unitAttributes.attackCooldownPrefabList[i] = levelRate[i].rate; } break; default: Debug.LogError("Cannot process what's going on. Please check code execution flow using debugger and breakpoints set to here."); break; } } playerUnit.UpdateUnitAttributes(); } } } }
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); }
public void SetAttributes() { DropdownFix[] fixes = GameObject.FindObjectsOfType<DropdownFix>(); int values = 0; for (int i = 0; i < fixes.Length; i++) { values += fixes[i].value; } if (values <= 0) { //TODO(Thompson): Need to create some sort of message box alerting the player to set the player presets first. return; } if (this.unitAttributes == null) { GameObject obj = GameObject.FindGameObjectWithTag("UnitAttributes"); if (obj != null) { this.unitAttributes = obj.GetComponent<UnitAttributes>(); } } if (this.unitAttributes != null && this.dropdown != null && this.attributePanelUI != null) { //TODO: Make complex presets. int itemValue = this.dropdown.value; switch (itemValue) { default: case 0: string zero1 = "y=0"; unitAttributes.SetHealthAttributes(zero1); unitAttributes.SetAttackAttributes(zero1); unitAttributes.SetSpeedAttributes(zero1); unitAttributes.SetSplitAttributes(zero1); unitAttributes.SetMergeAttributes(zero1); unitAttributes.SetAttackCooldownAttributes(zero1); this.attributePanelUI.DisableCustomEquations(); break; case 1: case 2: case 3: Debug.Log("Setting expression: " + this.dropdown.options[itemValue].text); string expression = this.dropdown.options[itemValue].text; unitAttributes.SetHealthAttributes(expression); unitAttributes.SetAttackAttributes(expression); unitAttributes.SetSpeedAttributes(expression); unitAttributes.SetSplitAttributes(expression); unitAttributes.SetMergeAttributes(expression); unitAttributes.SetAttackCooldownAttributes(expression); this.attributePanelUI.DisableCustomEquations(); break; case 4: unitAttributes.SetHealthAttributes("y=2*x"); string otherExpression = "y=1.414*x"; unitAttributes.SetAttackAttributes(otherExpression); unitAttributes.SetSpeedAttributes(otherExpression); unitAttributes.SetSplitAttributes(otherExpression); unitAttributes.SetMergeAttributes(otherExpression); unitAttributes.SetAttackCooldownAttributes(otherExpression); this.attributePanelUI.DisableCustomEquations(); break; case 5: string one = "y=1"; unitAttributes.SetHealthAttributes(one); unitAttributes.SetAttackAttributes(one); unitAttributes.SetSpeedAttributes(one); unitAttributes.SetSplitAttributes(one); unitAttributes.SetMergeAttributes(one); unitAttributes.SetAttackCooldownAttributes(one); this.attributePanelUI.EnableCustomEquations(); break; } this.attributePanelUI.RefreshAttributes(this.unitAttributes); } }
void Start() { if (!this.hasAuthority) { return; } this.doNotAllowMerging = false; if (this.mergeList == null) { this.mergeList = new List<MergeGroup>(); } if (this.removeList == null) { this.removeList = new List<MergeGroup>(); } if (this.selectionManager == null) { GameObject[] managers = GameObject.FindGameObjectsWithTag("SelectionManager"); foreach (GameObject select in managers) { SelectionManager selectManager = select.GetComponent<SelectionManager>(); if (selectManager != null && selectManager.hasAuthority) { this.selectionManager = selectManager; break; } } if (this.selectionManager == null) { Debug.LogError("Merge Manager: Selection Manager is null. Please check."); } } if (this.unitAttributes == null) { GameObject[] attributes = GameObject.FindGameObjectsWithTag("UnitAttributes"); foreach (GameObject attribute in attributes) { UnitAttributes attr = attribute.GetComponent<UnitAttributes>(); if (attr != null && attr.hasAuthority) { this.unitAttributes = attr; break; } } if (this.unitAttributes == null) { Debug.LogError("Merge Manager: Unit Attributes Tracker is null. Please check."); } } }
public void RefreshAttributes(UnitAttributes unitAttributes) { foreach (Category cat in this.categoryContentObject.items) { List<LevelRate> tempList = this.levelingRatesObject.allAttributes[cat.value]; for (int i = 0; i < tempList.Count; i++) { LevelRate rate = tempList[i]; if (!this.enablePlayerCustomEquations) { rate.isIncreasing = 0; } switch (cat.value) { default: break; case 0: rate.rate = unitAttributes.healthPrefabList[i]; break; case 1: rate.rate = unitAttributes.attackPrefabList[i]; break; case 2: rate.rate = unitAttributes.attackCooldownPrefabList[i]; break; case 3: rate.rate = unitAttributes.speedPrefabList[i]; break; case 4: if (i == 0) { rate.rate = unitAttributes.splitPrefabFactor; } else { rate.rate = 0f; } break; case 5: rate.rate = unitAttributes.mergePrefabList[i]; break; } tempList[i] = rate; } this.levelingRatesObject.allAttributes[cat.value] = tempList; } this.levelingRatesObject.UpdateAllPanelItems(this.categoryContentObject.selectedToggle); }
public void Start() { //This is used to obtain inactive start locations. Start locations can randomly //be set to inactive, so I need a way to obtain these inactive game objects. this.starterObjects = GameObject.FindGameObjectWithTag("Respawn"); if (this.starterObjects == null) { Debug.LogError("Cannot find starter object in scene."); } if (!this.hasAuthority) { return; } NetworkIdentity spawnerIdentity = this.GetComponent <NetworkIdentity>(); if (!spawnerIdentity.localPlayerAuthority) { spawnerIdentity.localPlayerAuthority = true; } this.owner = this.isServer ? spawnerIdentity.connectionToClient : spawnerIdentity.connectionToServer; this.isPaused = false; if (this.minimapCamera == null) { GameObject obj = GameObject.FindGameObjectWithTag("Minimap"); if (obj != null) { this.minimapCamera = obj.GetComponent <Camera>(); if (this.minimapCamera == null) { Debug.LogError("Failure to obtain minimap camera."); } } } if (Camera.main.gameObject.GetComponent <PostRenderer>() == null) { PostRenderer renderer = Camera.main.gameObject.AddComponent <PostRenderer>(); renderer.minimapCamera = this.minimapCamera; //NOTE(Thompson): See NOTE in NetworkManagerActions.StartLANClient(). renderer.enabled = false; //NOTE(Thompson): Setting the renderer to a variable, so I can later on check to see //if the renderer is disabled or not. If disabled, disallow unit selection. this.selectionBoxRenderer = renderer; } if (this.unitAttributesManager == null) { this.unitAttributesManager = GameObject.FindObjectOfType <UnitAttributes>(); if (this.unitAttributesManager == null) { Debug.LogError("Unable to get unit attributes manager."); } } this.selectionBox = new Rect(); this.initialClick = Vector3.one * -9999f; this.screenPoint = this.initialClick; this.isGameStart = false; this.isUnitListEmpty = true; //NOTE(Thompson): This means you are allowed to merge. This checks if there exists one or more LV1 game unit available. this.doNotAllowMerging = false; //NOTE(Thompson): NewSpawner needs to keep track of where the first game unit is spawned at. This is set in CmdInitialize(). this.changes.Clear(); CmdInitialize(this.gameObject); }