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; } } }
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); } } } } }
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 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 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 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; } } } }
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(); } }