public void CmdAttack(bool hasAuthority, GameObject attacker, GameObject victim, int damage) { if (victim != null && attacker != null) { NewGameUnit victimUnit = victim.GetComponent <NewGameUnit>(); NewGameUnit attackerUnit = attacker.GetComponent <NewGameUnit>(); if (!(NetworkServer.FindLocalObject(victimUnit.netId) || NetworkServer.FindLocalObject(attackerUnit.netId))) { return; } if (victimUnit != null && attackerUnit != null && !attackerUnit.properties.isAttackCooldownEnabled && NetworkServer.FindLocalObject(victimUnit.netId) != null && NetworkServer.FindLocalObject(attackerUnit.netId) != null) { NewChanges changes = victimUnit.CurrentProperty(); changes.damage = damage; changes.isRecoveryEnabled = true; victimUnit.NewProperty(changes); RpcTakeDamageColor(victimUnit.netId); if (victimUnit.properties.currentHealth == 0 && attackerUnit.hasAuthority == hasAuthority) { //TODO(Thompson): See if removing the authority check helps fixing the kill counter being //only the server side can take kill counts, while client side sometimes not taking kill counts. attackerUnit.LogKill(); } } } }
public void CmdDestroy(GameObject targetUnit) { if (targetUnit != null) { NewGameUnit unit = targetUnit.GetComponent <NewGameUnit>(); if (unit != null && NetworkServer.FindLocalObject(unit.netId)) { if (targetUnit != null) { NewChanges changes = unit.CurrentProperty(); if (changes.targetUnit != null && changes.targetUnit.Equals(this.gameObject)) { changes.targetUnit = null; unit.NewProperty(changes); } } NewLOS los = this.GetComponentInChildren <NewLOS>(); if (los != null) { los.parent = null; } NewAtkRange range = this.GetComponentInChildren <NewAtkRange>(); if (range != null) { range.parent = null; } NetworkServer.Destroy(this.gameObject); } } }
private void CastRay(NewGameUnit unit, bool isMinimap, Vector3 mousePosition, Camera minimapCamera) { Ray ray; if (isMinimap) { ray = this.minimapCamera.ViewportPointToRay(mousePosition); } else { ray = Camera.main.ScreenPointToRay(mousePosition); } RaycastHit[] hits = Physics.RaycastAll(ray, 500f); foreach (RaycastHit hit in hits) { if (hit.collider.gameObject.tag.Equals("Floor")) { this.changes = unit.CurrentProperty(); this.changes.mousePosition = hit.point; this.changes.isCommanded = true; CmdUpdateUnitProperty(unit.gameObject, this.changes); break; } } }
private void TempRectSelectObjects() { for (int i = this.unitList.Count - 1; i >= 0; i--) { NewUnitStruct temp = this.unitList[i]; if (temp.unit == null) { CmdRemoveUnitList(this.unitList[i].unit); continue; } Vector3 projectedPosition = Camera.main.WorldToScreenPoint(temp.unit.transform.position); projectedPosition.y = Screen.height - projectedPosition.y; if (this.selectionBox.Contains(projectedPosition)) { NewGameUnit unit = temp.unit.GetComponent <NewGameUnit>(); if (unit.properties.isSelected || !unit.hasAuthority) { continue; } if (temp.unit == null) { CmdRemoveUnitList(this.unitList[i].unit); continue; } this.changes = unit.CurrentProperty(); this.changes.isSelected = true; CmdUpdateUnitProperty(unit.gameObject, this.changes); } else { continue; } } }
public NewChanges CurrentProperty() { NewChanges changes = new NewChanges().Clear(); changes.isInitialized = this.properties.isInitialized; changes.isSelected = this.properties.isSelected; changes.isMerging = this.properties.isMerging; changes.isSplitting = this.properties.isSplitting; changes.isCommanded = this.properties.isCommanded; changes.isAttackCooldownEnabled = this.properties.isAttackCooldownEnabled; changes.isRecoveryEnabled = this.properties.isRecoveryEnabled; changes.newLevel = this.properties.level; changes.newCurrentHealth = this.properties.currentHealth; changes.newMaxHealth = this.properties.maxHealth; changes.newAttack = this.properties.attackFactor; changes.newSpeed = this.properties.speedFactor; changes.newSplit = this.properties.splitFactor; changes.newMerge = this.properties.mergeFactor; changes.newAttackCooldown = this.properties.attackCooldownFactor; changes.mousePosition = this.properties.mouseTargetPosition; changes.enemySeenPosition = this.properties.enemySeenTargetPosition; changes.targetUnit = this.properties.targetUnit; changes.damage = 0; changes.heal = 0; changes.teamFactionID = this.properties.teamFactionID; changes.teamColor = this.properties.teamColor; return(changes); }
public void CmdUpdateUnitProperty(GameObject unit, NewChanges changes) { if (unit != null) { NewGameUnit gameUnit = unit.GetComponent <NewGameUnit>(); if (gameUnit != null) { gameUnit.NewProperty(changes); } } }
public void RpcAddMerge(GameObject owner, GameObject merge, NewChanges changes) { if (owner != null && merge != null) { NewGameUnit ownerUnit = owner.GetComponent <NewGameUnit>(); if (ownerUnit != null) { this.mergeList.Add(new Merge(owner.transform, merge.transform, ownerUnit.properties.scalingFactor)); } } }
public void CmdUpdateProperty(GameObject obj, NewChanges changes) { if (obj != null) { NewGameUnit unit = obj.GetComponent <NewGameUnit>(); if (unit != null) { unit.NewProperty(changes); } } }
public Color SetTeamColor(Color color) { NewChanges changes = this.CurrentProperty(); changes.teamColor = color; this.NewProperty(changes); Renderer renderer = this.GetComponent <Renderer>(); renderer.material.SetColor("_TeamColor", color); return(color); }
public void NewProperty(NewChanges changes) { UnitProperties pro = new UnitProperties(); pro = this.properties; pro.isInitialized = changes.isInitialized; pro.teamFactionID = changes.teamFactionID; if (changes.heal > 0) { pro.currentHealth += changes.heal; } if (changes.damage > 0) { pro.currentHealth -= changes.damage; } if (pro.mouseTargetPosition != changes.mousePosition) { pro.oldMouseTargetPosition = pro.mouseTargetPosition; pro.mouseTargetPosition = changes.mousePosition; } if (pro.enemySeenTargetPosition != changes.enemySeenPosition) { pro.oldEnemySeenTargetPosition = pro.enemySeenTargetPosition; pro.enemySeenTargetPosition = changes.enemySeenPosition; } pro.isSelected = changes.isSelected; pro.isSplitting = changes.isSplitting; pro.isMerging = changes.isMerging; pro.level = changes.newLevel; pro.isCommanded = changes.isCommanded; pro.isRecoveryEnabled = changes.isRecoveryEnabled; pro.targetUnit = changes.targetUnit; //pro.currentHealth = (int) changes.newCurrentHealth; pro.maxHealth = (int)changes.newMaxHealth; pro.attackFactor = changes.newAttack; pro.speedFactor = changes.newSpeed; pro.splitFactor = changes.newSplit; pro.mergeFactor = changes.newMerge; pro.attackCooldownFactor = changes.newAttackCooldown; pro.teamColor = changes.teamColor; Renderer renderer = this.GetComponent <Renderer>(); renderer.material.SetColor("_TeamColor", changes.teamColor); pro.isAttackCooldownEnabled = changes.isAttackCooldownEnabled; OnPropertiesChanged(pro); }
private void SelectObjectAtPoint() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit[] hits = Physics.RaycastAll(ray); foreach (RaycastHit hit in hits) { GameObject obj = hit.collider.gameObject; //NOTE(Thompson): If all fails, change "tag" to "name", and "Unit" to "NewGameUnit". //This is now fixed, so we have two options here. if (obj.tag.Equals("Unit")) { NewUnitStruct temp = new NewUnitStruct(obj); NewGameUnit unit = temp.unit.GetComponent <NewGameUnit>(); if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) { if (this.unitList.Contains(temp) && unit.hasAuthority) { if (!this.selectedList.Contains(temp)) { this.changes = unit.CurrentProperty(); changes.isSelected = true; unit.NewProperty(changes); CmdUpdateUnitProperty(unit.gameObject, this.changes); this.selectedList.Add(temp); } else if (this.selectedList.Contains(temp)) { this.changes = unit.CurrentProperty(); this.changes.isSelected = false; unit.NewProperty(changes); CmdUpdateUnitProperty(unit.gameObject, this.changes); this.selectedList.Remove(temp); } } } else { if (unit != null && unit.hasAuthority) { this.changes = unit.CurrentProperty(); changes.isSelected = true; unit.NewProperty(changes); CmdUpdateUnitProperty(unit.gameObject, this.changes); this.selectedList.Add(temp); } } } } }
public void CmdInitialize(GameObject spawner) { NetworkIdentity spawnerID = spawner.GetComponent <NetworkIdentity>(); //Only the server choose what color values to use. Client values do not matter. int colorValue = NewSpawner.colorCode; NewSpawner.colorCode = (++NewSpawner.colorCode) % 3; Color color; switch (colorValue) { default: color = Color.gray; break; case 0: color = Color.yellow; break; case 1: color = Color.blue; break; case 2: color = Color.green; break; } GameObject gameUnit = MonoBehaviour.Instantiate <GameObject>(this.newGameUnitPrefab); gameUnit.name = gameUnit.name.Substring(0, gameUnit.name.Length - "(Clone)".Length); gameUnit.transform.SetParent(this.transform); gameUnit.transform.position = this.transform.position; NewGameUnit b = gameUnit.GetComponent <NewGameUnit>(); NewChanges changes = b.CurrentProperty(); if (!changes.isInitialized) { changes.isInitialized = false; changes.teamColor = color; changes.teamFactionID = (int)(Random.value * 100f); //This is never to be changed. } b.NewProperty(changes); NetworkServer.SpawnWithClientAuthority(b.gameObject, spawnerID.clientAuthorityOwner); RpcAdd(gameUnit, spawner); RpcFilter(b.netId, spawnerID.netId); }
public void OnTriggerExit(Collider other) { NewGameUnit unit = other.GetComponent <NewGameUnit>(); if (unit != null && !unit.hasAuthority && unit.properties.teamFactionID != this.parent.properties.teamFactionID) { this.detectedUnits.Remove(unit); } if (this.detectedUnits.Count <= 0) { NewChanges changes = this.parent.CurrentProperty(); changes.enemyHitPosition = changes.mousePosition; this.parent.CallCmdupdateProperty(changes); } }
private void HandleRecovering() { if (this.properties.isRecoveryEnabled && this.recoveryCounter <= 0) { CmdRecover(this.gameObject, 1); this.recoveryCounter = 1f; if (this.properties.currentHealth >= this.properties.maxHealth) { this.properties.currentHealth = this.properties.maxHealth; NewChanges changes = this.CurrentProperty(); changes.isRecoveryEnabled = false; this.NewProperty(changes); } } }
public void CmdRecover(GameObject recoveringObject, int healValue) { if (recoveringObject != null) { NewGameUnit unit = recoveringObject.GetComponent <NewGameUnit>(); if (unit != null && NetworkServer.FindLocalObject(unit.netId)) { if (unit.properties.currentHealth < unit.properties.maxHealth && unit.properties.isRecoveryEnabled) { NewChanges changes = unit.CurrentProperty(); changes.heal = healValue; unit.NewProperty(changes); } } } }
public void FixedUpdate() { this.colliderBody.WakeUp(); if (this.parent != null) { if (this.detectedUnits.Count > 0) { NewChanges changes = this.parent.CurrentProperty(); if (this.detectedUnits[0] != null) { changes.enemySeenPosition = this.detectedUnits[0].transform.position; this.parent.CallCmdupdateProperty(changes); } } } }
private bool HandleStatus() { //Returns TRUE if the game unit is destroyed, preventing all other actions from executing. //Returns FALSE if game unit is alive. if (this.properties.currentHealth <= 0 && !this.isDead) { this.isDead = true; GameMetricLogger.Increment(GameMetricOptions.Death); CmdDestroy(this.gameObject); return(true); } if (this.properties.isAttackCooldownEnabled) { if (this.attackCooldownCounter > 0) { this.attackCooldownCounter -= Time.deltaTime; GameMetricLogger.Increment(GameMetricOptions.BattleEngagementTime); } else { NewChanges changes = this.CurrentProperty(); changes.isAttackCooldownEnabled = false; this.NewProperty(changes); } } if (this.properties.isRecoveryEnabled) { if (this.recoveryCounter > 0f) { this.recoveryCounter -= Time.deltaTime / 5f; } else { NewChanges changes = this.CurrentProperty(); changes.isRecoveryEnabled = false; this.NewProperty(changes); } } return(false); }
//*** ---------------------------- PRIVATE METHODS ------------------------- private void HandleMovement() { if (this.properties.isCommanded) { if (this.properties.mouseTargetPosition != this.properties.oldMouseTargetPosition) { //Client side nav mesh agent CmdSetDestination(this.gameObject, this.properties.mouseTargetPosition); } } if (this.agent.ReachedDestination()) { if (this.properties.isCommanded) { NewChanges changes = this.CurrentProperty(); changes.isCommanded = false; this.CmdUpdateProperty(this.gameObject, changes); return; } } if (!this.properties.isCommanded) { if (this.properties.targetUnit == null) { if (this.properties.mouseTargetPosition != this.properties.oldMouseTargetPosition) { CmdSetDestination(this.gameObject, this.properties.mouseTargetPosition); } else { CmdSetDestination(this.gameObject, this.properties.enemySeenTargetPosition); } } else { Vector3 agentDestination = this.properties.targetUnit.transform.position; agentDestination.y = 0f; //May or may not need this. CmdSetDestination(this.gameObject, agentDestination); } } }
private void HandleAttacking() { if (this.properties.targetUnit != null && this.attackCooldownCounter <= 0 && !this.properties.isAttackCooldownEnabled) { CmdAttack(this.hasAuthority, this.gameObject, this.properties.targetUnit, 1); this.attackCooldownCounter = 1f; NewChanges changes = this.CurrentProperty(); changes.isAttackCooldownEnabled = true; this.NewProperty(changes); GameMetricLogger.Increment(GameMetricOptions.Attacks); } else if (this.attackCooldownCounter > 0f) { NewChanges changes = this.CurrentProperty(); changes.isAttackCooldownEnabled = true; this.NewProperty(changes); GameMetricLogger.Increment(GameMetricOptions.AttackTime); } }
public void CmdSplitSpawn(GameObject owner, NetworkIdentity ownerIdentity) { NewGameUnit unit = owner.GetComponent <NewGameUnit>(); NewChanges changes = unit.CurrentProperty(); changes.isSelected = false; changes.isSplitting = true; changes.teamColor = unit.GetTeamColor(); unit.NewProperty(changes); GameObject split = MonoBehaviour.Instantiate <GameObject>(owner); split.name = "NewGameUnit"; split.transform.SetParent(this.transform); split.transform.position = unit.transform.position; unit = split.GetComponent <NewGameUnit>(); unit.NewProperty(changes); NetworkServer.SpawnWithClientAuthority(split, ownerIdentity.clientAuthorityOwner); RpcAddSplit(owner, split, changes, Random.Range(-180f, 180f)); //this.splitList.Add(new Split(temp.transform, unit.transform)); RpcOrganizeUnit(owner, split); }
public void RpcAddSplit(GameObject owner, GameObject split, NewChanges changes, float angle) { if (owner != null && split != null) { NewGameUnit splitUnit = split.GetComponent <NewGameUnit>(); if (splitUnit != null) { splitUnit.NewProperty(changes); } else { Debug.LogWarning("SplitUnit does not exist."); } this.splitList.Add(new Split(owner.transform, split.transform, angle)); } else { string value1 = (owner == null) ? " Owner is null." : ""; string value2 = (split == null) ? " Split is null." : ""; Debug.LogWarning(value1 + value2); } }
private void ClearSelectObjects() { for (int i = this.unitList.Count - 1; i >= 0; i--) { NewUnitStruct temp = this.unitList[i]; if (temp.unit == null) { CmdRemoveUnitList(this.unitList[i].unit); continue; } GameObject obj = temp.unit.gameObject; if (obj == null) { CmdRemoveUnitList(this.unitList[i].unit); continue; } NewGameUnit unit = obj.GetComponent <NewGameUnit>(); changes = unit.CurrentProperty(); changes.isSelected = false; CmdUpdateUnitProperty(unit.gameObject, this.changes); } this.selectedList.Clear(); }
private void SelectObjects() { for (int i = this.unitList.Count - 1; i >= 0; i--) { NewUnitStruct temp = this.unitList[i]; GameObject obj = temp.unit.gameObject; if (obj == null) { this.unitList.Remove(temp); continue; } if (this.selectedList.Contains(temp)) { NewGameUnit unit = obj.GetComponent <NewGameUnit>(); if (unit != null && unit.hasAuthority) { this.changes = unit.CurrentProperty(); changes.isSelected = true; CmdUpdateUnitProperty(unit.gameObject, this.changes); } } } }
private void ManageNonAuthorityLists() { if (this.splitList.Count > 0) { for (int i = this.splitList.Count - 1; i >= 0; i--) { Split splitGroup = this.splitList[i]; if (splitGroup.owner == null || splitGroup.split == null) { this.splitList.Remove(splitGroup); } if (splitGroup.elapsedTime > 1f) { NewGameUnit unit = splitGroup.owner.GetComponent <NewGameUnit>(); NewChanges changes = unit.CurrentProperty(); changes.isSelected = false; changes.isSplitting = false; //CmdUpdateUnitProperty(splitGroup.owner.gameObject, changes); unit.NewProperty(changes); unit = splitGroup.split.GetComponent <NewGameUnit>(); unit.NewProperty(changes); //CmdUpdateUnitProperty(splitGroup.split.gameObject, changes); //this.unitList.Add(new NewUnitStruct(splitGroup.split.gameObject)); this.splitList.Remove(splitGroup); //GameMetricLogger.Increment(GameMetricOptions.Splits); } else { splitGroup.Update(); this.splitList[i] = splitGroup; } } } if (this.mergeList.Count > 0) { for (int i = this.mergeList.Count - 1; i >= 0; i--) { Merge mergeGroup = this.mergeList[i]; if (mergeGroup.elapsedTime > 1f) { if (mergeGroup.merge != null) { NewGameUnit unit = mergeGroup.merge.GetComponent <NewGameUnit>(); if (unit != null) { NewChanges changes = unit.CurrentProperty(); changes.damage = unit.properties.maxHealth; unit.NewProperty(changes); } NewUnitStruct temp = new NewUnitStruct(); temp.unit = unit.gameObject; this.unitList.Remove(temp); //CmdDestroy(temp.unit); } this.mergeList.RemoveAt(i); //GameMetricLogger.Increment(GameMetricOptions.Merges); } else { mergeGroup.Update(); this.mergeList[i] = mergeGroup; } } } }
public NewChanges CurrentProperty() { NewChanges changes = new NewChanges().Clear(); changes.isInitialized = this.properties.isInitialized; changes.isSelected = this.properties.isSelected; changes.isMerging = this.properties.isMerging; changes.isSplitting = this.properties.isSplitting; changes.isCommanded = this.properties.isCommanded; changes.isAttackCooldownEnabled = this.properties.isAttackCooldownEnabled; changes.isRecoveryEnabled = this.properties.isRecoveryEnabled; changes.newLevel = this.properties.level; changes.newCurrentHealth = this.properties.currentHealth; changes.newMaxHealth = this.properties.maxHealth; changes.newAttack = this.properties.attackFactor; changes.newSpeed = this.properties.speedFactor; changes.newSplit = this.properties.splitFactor; changes.newMerge = this.properties.mergeFactor; changes.newAttackCooldown = this.properties.attackCooldownFactor; changes.mousePosition = this.properties.mouseTargetPosition; changes.enemySeenPosition = this.properties.enemySeenTargetPosition; changes.targetUnit = this.properties.targetUnit; changes.damage = 0; changes.heal = 0; changes.teamFactionID = this.properties.teamFactionID; changes.teamColor = this.properties.teamColor; return changes; }
public void NewProperty(NewChanges changes) { UnitProperties pro = new UnitProperties(); pro = this.properties; pro.isInitialized = changes.isInitialized; pro.teamFactionID = changes.teamFactionID; if (changes.heal > 0) { pro.currentHealth += changes.heal; } if (changes.damage > 0) { pro.currentHealth -= changes.damage; } if (pro.mouseTargetPosition != changes.mousePosition) { pro.oldMouseTargetPosition = pro.mouseTargetPosition; pro.mouseTargetPosition = changes.mousePosition; } if (pro.enemySeenTargetPosition != changes.enemySeenPosition) { pro.oldEnemySeenTargetPosition = pro.enemySeenTargetPosition; pro.enemySeenTargetPosition = changes.enemySeenPosition; } pro.isSelected = changes.isSelected; pro.isSplitting = changes.isSplitting; pro.isMerging = changes.isMerging; pro.level = changes.newLevel; pro.isCommanded = changes.isCommanded; pro.isRecoveryEnabled = changes.isRecoveryEnabled; pro.targetUnit = changes.targetUnit; //pro.currentHealth = (int) changes.newCurrentHealth; pro.maxHealth = (int) changes.newMaxHealth; pro.attackFactor = changes.newAttack; pro.speedFactor = changes.newSpeed; pro.splitFactor = changes.newSplit; pro.mergeFactor = changes.newMerge; pro.attackCooldownFactor = changes.newAttackCooldown; pro.teamColor = changes.teamColor; Renderer renderer = this.GetComponent<Renderer>(); renderer.material.SetColor("_TeamColor", changes.teamColor); pro.isAttackCooldownEnabled = changes.isAttackCooldownEnabled; OnPropertiesChanged(pro); }
public void CallCmdupdateProperty(NewChanges changes) { this.CmdUpdateProperty(this.gameObject, changes); }
public void CmdUpdateProperty(GameObject obj, NewChanges changes) { if (obj != null) { NewGameUnit unit = obj.GetComponent<NewGameUnit>(); if (unit != null) { unit.NewProperty(changes); } } }
private void ManageLists() { if (this.splitList.Count > 0) { for (int i = this.splitList.Count - 1; i >= 0; i--) { Split splitGroup = this.splitList[i]; if (splitGroup.owner == null || splitGroup.split == null) { this.splitList.Remove(splitGroup); } if (splitGroup.elapsedTime > 1f) { NewGameUnit unit = splitGroup.owner.GetComponent <NewGameUnit>(); this.changes = unit.CurrentProperty(); this.changes.isSelected = false; this.changes.isSplitting = false; CmdUpdateUnitProperty(splitGroup.owner.gameObject, this.changes); unit = splitGroup.split.GetComponent <NewGameUnit>(); CmdUpdateUnitProperty(splitGroup.split.gameObject, this.changes); this.unitList.Add(new NewUnitStruct(splitGroup.split.gameObject)); this.splitList.Remove(splitGroup); GameMetricLogger.Increment(GameMetricOptions.Splits); } else { splitGroup.Update(); this.splitList[i] = splitGroup; } } } if (this.mergeList.Count > 0) { for (int i = this.mergeList.Count - 1; i >= 0; i--) { Merge mergeGroup = this.mergeList[i]; if (mergeGroup.elapsedTime > 1f) { if (mergeGroup.owner != null) { NewGameUnit unit = mergeGroup.owner.gameObject.GetComponent <NewGameUnit>(); this.changes = unit.CurrentProperty(); this.changes.isMerging = false; this.changes.isSelected = false; //changes.newLevel = unit.properties.level + 1; CmdUpdateUnitProperty(mergeGroup.owner.gameObject, this.changes); } if (mergeGroup.merge != null) { NewUnitStruct temp = new NewUnitStruct(); temp.unit = mergeGroup.merge.gameObject; this.unitList.Remove(temp); CmdDestroy(temp.unit); } this.mergeList.RemoveAt(i); GameMetricLogger.Increment(GameMetricOptions.Merges); } else { mergeGroup.Update(); this.mergeList[i] = mergeGroup; } } } this.isUnitListEmpty = this.unitList.Count <= 0; if (!this.isUnitListEmpty) { for (int i = this.unitList.Count - 1; i >= 0; i--) { if (this.unitList[i].unit == null) { this.unitList.RemoveAt(i); continue; } NetworkIdentity id = this.unitList[i].unit.GetComponent <NetworkIdentity>(); if (!id.hasAuthority) { CmdRemoveUnitList(this.unitList[i].unit); } } } else { CmdShowReport(); } }
public void CmdMergeUpdate(GameObject owner, GameObject merge, NewChanges changes) { RpcAddMerge(owner, merge, changes); }
private void SelectObjectsInRect() { for (int i = this.unitList.Count - 1; i >= 0; i--) { NewUnitStruct temp = this.unitList[i]; GameObject obj = temp.unit.gameObject; if (obj == null) { this.unitList.Remove(temp); continue; } NewGameUnit unit = obj.GetComponent <NewGameUnit>(); Vector3 projectedPosition = Camera.main.WorldToScreenPoint(obj.transform.position); projectedPosition.y = Screen.height - projectedPosition.y; if (unit != null && unit.hasAuthority) { if (this.isBoxSelecting) { if (this.selectionBox.Contains(projectedPosition)) { if (this.selectedList.Contains(temp)) { this.changes = unit.CurrentProperty(); this.changes.isSelected = false; CmdUpdateUnitProperty(unit.gameObject, this.changes); this.selectedList.Remove(temp); } else { this.changes = unit.CurrentProperty(); changes.isSelected = true; CmdUpdateUnitProperty(unit.gameObject, this.changes); this.selectedList.Add(temp); } } } else { if (unit.properties.isSelected) { if (!this.selectedList.Contains(temp)) { this.selectedList.Add(temp); } } else { if (!this.selectionBox.Contains(projectedPosition)) { if (this.selectedList.Contains(temp)) { this.changes = unit.CurrentProperty(); this.changes.isSelected = false; CmdUpdateUnitProperty(unit.gameObject, this.changes); this.selectedList.Remove(temp); } } else { if (!this.selectedList.Contains(temp)) { this.changes = unit.CurrentProperty(); ; changes.isSelected = true; CmdUpdateUnitProperty(unit.gameObject, this.changes); this.selectedList.Add(temp); } } } } } } }
//----------- Private class methods may all need refactoring -------------------- private void HandleInputs() { if (Input.GetKeyUp(KeyCode.S)) { foreach (NewUnitStruct temp in this.selectedList) { NewGameUnit newUnit = temp.unit.GetComponent <NewGameUnit>(); if (!newUnit.properties.isSplitting && this.unitList.Count < NewSpawner.MAX_UNIT_LIMIT && newUnit.properties.level == 1) { CmdSplitSpawn(temp.unit, temp.unit.GetComponent <NetworkIdentity>()); } else { if (newUnit != null) { this.changes = newUnit.CurrentProperty(); this.changes.isSelected = false; this.changes.isSplitting = false; newUnit.NewProperty(this.changes); } } } this.selectedList.Clear(); } else if (Input.GetKeyUp(KeyCode.D)) { NewGameUnit owner = null, merge = null; if (this.selectedList.Count == 1) { owner = this.selectedList[0].unit.GetComponent <NewGameUnit>(); this.changes = owner.CurrentProperty(); this.changes.isSelected = false; owner.NewProperty(this.changes); } else { for (int i = this.selectedList.Count - 1; i >= 1; i--) { owner = this.selectedList[i].unit.GetComponent <NewGameUnit>(); if (owner != null && !owner.properties.isMerging) { for (int j = i - 1; j >= 0; j--) { merge = this.selectedList[j].unit.GetComponent <NewGameUnit>(); this.doNotAllowMerging = false; if (owner.properties.level == 1 && merge.properties.level == 1) { CheckAvailableResource(); } if (merge != null && !merge.properties.isMerging && merge.properties.level == owner.properties.level && !this.doNotAllowMerging) { this.changes = owner.CurrentProperty(); changes.isMerging = true; changes.isSelected = false; changes.newLevel++; changes.newMaxHealth = this.unitAttributesManager.healthPrefabList[changes.newLevel]; changes.newAttack = this.unitAttributesManager.attackPrefabList[changes.newLevel]; changes.newSpeed = this.unitAttributesManager.speedPrefabList[changes.newLevel]; changes.newSplit = this.unitAttributesManager.splitPrefabFactor; changes.newMerge = this.unitAttributesManager.mergePrefabList[changes.newLevel]; changes.newAttackCooldown = this.unitAttributesManager.attackCooldownPrefabList[changes.newLevel]; CmdUpdateUnitProperty(owner.gameObject, this.changes); CmdUpdateUnitProperty(merge.gameObject, this.changes); CmdMergeUpdate(owner.gameObject, merge.gameObject, this.changes); this.selectedList.RemoveAt(i); i--; this.selectedList.RemoveAt(j); j--; break; } else { if (merge != null) { this.changes = merge.CurrentProperty(); this.changes.isSelected = false; this.changes.isMerging = false; merge.NewProperty(this.changes); //this.selectedList.RemoveAt(j); //i--; //j--; } } } if (merge == null) { this.changes = owner.CurrentProperty(); this.changes.isSelected = false; this.changes.isMerging = false; owner.NewProperty(this.changes); //this.selectedList.RemoveAt(i); //i--; } } else if (owner != null) { this.changes = owner.CurrentProperty(); this.changes.isSelected = false; this.changes.isMerging = false; owner.NewProperty(this.changes); //this.selectedList.RemoveAt(i); //i--; } } } } if (Input.GetMouseButtonUp(1) && !this.minimapCamera.rect.Contains(this.screenPoint)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit[] hits = Physics.RaycastAll(ray); foreach (RaycastHit hit in hits) { if (hit.collider.gameObject.tag.Equals("Floor")) { foreach (NewUnitStruct temp in this.selectedList) { if (temp.unit == null) { continue; } NewGameUnit unit = temp.unit.GetComponent <NewGameUnit>(); this.changes = unit.CurrentProperty(); this.changes.mousePosition = hit.point; this.changes.isCommanded = true; CmdUpdateUnitProperty(temp.unit, this.changes); } } } } }