/// <summary> /// Calculate / Check position updates for selected unit(s) /// </summary> void UpdatePositionCalculations() { GenericUnit gu = null; // if a unit is selected if (selectedUnit) { // make camera follow! Vector3 x = selectedUnit.transform.position; x.y = x.y + 5f; x.z = x.z - 20f; guiManagerInstance.UI_UnitFollowerCamera.transform.position = x; gu = selectedUnit.GetComponent <GenericUnit>(); } // check Left Mouse Button if (Input.GetMouseButtonDown(0) && selectedUnit) { //if (GUI._selectedUnitGeneric && GUI._selectedUnitGeneric.AudioSettings.moveQuotes.Length > 0) //playRandomQuote(GUI._selectedUnitGeneric.AudioSettings.moveQuotes, Audio.quoteAudioSource); if (gu && gu.canMove) { calculateTargetPosition(); gu.movementSpeed = gu.maxMovementSpeed; } } }
private void SpawnEnemy() { GameObject go = Instantiate(m_Enemies[Random.Range(0, m_Enemies.Count)], m_SpawnPoint.transform.position, Quaternion.identity); GenericUnit unit = go.GetComponent <GenericUnit>(); go.transform.parent = GameObject.Find("_Units").transform; unit.Initialize(Team.Team2, unit.GetUnitData()); }
// Update is called once per frame void Update() { if (Input.GetKeyDown(m_Key)) { GameObject unitObject = Instantiate(m_Prefab, transform.position, Quaternion.identity); GenericUnit unit = unitObject.GetComponent <GenericUnit>(); unit.Initialize(m_Team, m_Data); } }
//keep the info panel up if a character is selected private void OnUnitSelected(object sender, EventArgs e) { print("unitselected"); var unit = sender as GenericUnit; if (unit.UnitName != currentUnit.UnitName) { currentUnit = unit; LoadInfoPanel(unit); } }
protected void ToString(List <string> toStringOutput) { toStringOutput.Add($"CustomUnit = {(CustomUnit == null ? "null" : CustomUnit.ToString())}"); toStringOutput.Add($"AreaUnit = {(AreaUnit == null ? "null" : AreaUnit.ToString())}"); toStringOutput.Add($"LengthUnit = {(LengthUnit == null ? "null" : LengthUnit.ToString())}"); toStringOutput.Add($"VolumeUnit = {(VolumeUnit == null ? "null" : VolumeUnit.ToString())}"); toStringOutput.Add($"WeightUnit = {(WeightUnit == null ? "null" : WeightUnit.ToString())}"); toStringOutput.Add($"GenericUnit = {(GenericUnit == null ? "null" : GenericUnit.ToString())}"); toStringOutput.Add($"TimeUnit = {(TimeUnit == null ? "null" : TimeUnit.ToString())}"); toStringOutput.Add($"Type = {(Type == null ? "null" : Type.ToString())}"); }
//function for loading the stats of the current highlighted/selected unit on the infopanel //this is to make sure that unit information is up to date private void LoadInfoPanel(GenericUnit unit) { _infoPanel = Instantiate(InfoPanel); float hpScale = (float)((float)(unit).HitPoints / (float)(unit).TotalHitPoints); _infoPanel.transform.Find("Name").GetComponent <Text>().text = unit.UnitName; _infoPanel.transform.Find("Health").Find("Text").GetComponent <Text>().text = unit.HitPoints.ToString() + "/" + unit.TotalHitPoints.ToString(); _infoPanel.transform.Find("Attack").Find("Text").GetComponent <Text>().text = unit.AttackFactor.ToString(); _infoPanel.transform.Find("Armor").Find("Text").GetComponent <Text>().text = unit.Armor.ToString() + "/" + unit.TotalArmor; _infoPanel.transform.Find("Range").Find("Text").GetComponent <Text>().text = unit.AttackRange.ToString(); _infoPanel.transform.Find("Speed").Find("Text").GetComponent <Text>().text = unit.Speed.ToString(); _infoPanel.GetComponent <RectTransform>().SetParent(Canvas.GetComponent <RectTransform>(), false); }
public override int GetHashCode() { int hashCode = -1167462471; if (CustomUnit != null) { hashCode += CustomUnit.GetHashCode(); } if (AreaUnit != null) { hashCode += AreaUnit.GetHashCode(); } if (LengthUnit != null) { hashCode += LengthUnit.GetHashCode(); } if (VolumeUnit != null) { hashCode += VolumeUnit.GetHashCode(); } if (WeightUnit != null) { hashCode += WeightUnit.GetHashCode(); } if (GenericUnit != null) { hashCode += GenericUnit.GetHashCode(); } if (TimeUnit != null) { hashCode += TimeUnit.GetHashCode(); } if (Type != null) { hashCode += Type.GetHashCode(); } return(hashCode); }
private void OnTriggerStay(Collider other) { //Found Unit if (other.tag.Contains("Unit")) { GenericUnit unit = other.GetComponent <GenericUnit>(); if (unit.GetTeam() == m_Team) { m_FocussedUnit = unit; } } if (other.tag.Contains("Waypoint")) { m_Target = (other.GetComponent <Waypoints>().GetTarget(m_Direciton) - transform.position).normalized; } }
// Update is called once per frame public virtual void Update() { if (m_Health <= 0) { Destroy(this.gameObject); } if (m_Walking == true) { Walk(); } RaycastHit info; string name = ""; if (m_Team == Team.Team1) { name = "Team2"; } else if (m_Team == Team.Team2) { name = "Team1"; } Ray ray = new Ray(transform.position, transform.position + m_Target); if (Physics.Raycast(ray, out info, m_Range, LayerMask.NameToLayer(name))) { if (info.collider.GetComponent <GenericUnit>().GetTeam() != m_Team) { m_FocussedUnit = info.collider.GetComponent <GenericUnit>(); m_Attacking = true; m_Walking = false; AttackUnit(m_FocussedUnit); } } if (m_FocussedUnit != null) { AttackUnit(m_FocussedUnit); } m_Animator.SetBool("Walk", m_Walking); m_Animator.SetBool("Attacking", m_Attacking); }
/// <summary> /// Calculate the target position of a selected unit /// </summary> void calculateTargetPosition() { if (!selectedUnit) { return; } GenericUnit gu = selectedUnit.GetComponent <GenericUnit>(); RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { gu.moveTargetPoint.Set(hit.point.x, transform.position.y, hit.point.z); gu.isMoving = true; } }
private void OnUnitClicked(object sender, EventArgs e) { if (!EventSystem.current.IsPointerOverGameObject()) { GenericUnit unit = sender as GenericUnit; CellGridStateUnitSelected selected = CellGridState as CellGridStateUnitSelected; if (unit.PlayerNumber == 0) { } else { CellGridState.OnUnitClicked(sender as Unit); if (!isActionDone && selected.IsUnitInRange(sender as Unit)) { EndTurn(); } } } }
//Unit Attack Phase public virtual void AttackUnit(GenericUnit unit) { //If Focus is not destoryed. if (unit != null) { if (m_Attacking == true) { m_Rigidbody.velocity = Vector3.zero; m_Walking = false; m_AttackDelay -= Time.deltaTime; unit.FocussedUnit = this; if (m_AttackDelay <= 0) { unit.DealDamage(m_Data.Damage); m_Attacking = true; m_AttackDelay = m_Data.AttackSpeed; } } //Check if focus unit is inrange. else { if (Vector3.Distance(transform.position, unit.transform.position) <= m_Range) { m_Attacking = true; m_AttackDelay = m_Data.AttackSpeed; } else { m_Attacking = false; m_Walking = true; } } } //Focus died. else { m_Attacking = false; m_Walking = true; } }
public override bool Equals(object obj) { if (obj == null) { return(false); } if (obj == this) { return(true); } return(obj is MeasurementUnit other && ((CustomUnit == null && other.CustomUnit == null) || (CustomUnit?.Equals(other.CustomUnit) == true)) && ((AreaUnit == null && other.AreaUnit == null) || (AreaUnit?.Equals(other.AreaUnit) == true)) && ((LengthUnit == null && other.LengthUnit == null) || (LengthUnit?.Equals(other.LengthUnit) == true)) && ((VolumeUnit == null && other.VolumeUnit == null) || (VolumeUnit?.Equals(other.VolumeUnit) == true)) && ((WeightUnit == null && other.WeightUnit == null) || (WeightUnit?.Equals(other.WeightUnit) == true)) && ((GenericUnit == null && other.GenericUnit == null) || (GenericUnit?.Equals(other.GenericUnit) == true)) && ((TimeUnit == null && other.TimeUnit == null) || (TimeUnit?.Equals(other.TimeUnit) == true)) && ((Type == null && other.Type == null) || (Type?.Equals(other.Type) == true))); }
public override void AttackUnit(GenericUnit unit) { //If Focus is not destoryed. if (unit != null) { if (m_Attacking == true) { m_AttackDelay -= Time.deltaTime; if (m_AttackDelay <= 0) { GameObject arrow = m_ArrowPool.GetObject(); Arrow arrowScript = arrow.GetComponent <Arrow>(); arrowScript.Damage = m_Data.Damage; m_Bow.Initialize(unit.transform, arrow); m_Bow.SimulateProjectile(); m_Attacking = false; Walk(); } } //Check if focus unit is inrange. else { if (Vector3.Distance(transform.position, unit.transform.position) <= m_Range) { m_Attacking = true; } m_AttackDelay = m_Data.AttackSpeed; } } //Focus died. else { m_Attacking = false; m_Walking = true; } }
/// <summary> /// Creates a new unit for jerk. /// </summary> /// <param name="units"></param> /// <param name="time"></param> public GenericJerkUnit(GenericUnit units, TimeUnit time) : base(new UnitCompositeCollection() { new MultipliedByUnit(units, 1), new DividedByUnit(time, 3) }) { }
public override void AttackUnit(GenericUnit unit) { base.AttackUnit(unit); }
/// <summary> /// Creates a new angular feed constant unit based on units per rotation. /// </summary> /// <param name="genericUnit">The angle feed per rotation</param> /// <param name="rotations">The rotations the angle feed is based on.</param> public GenericFeedConstantUnit(GenericUnit genericUnit, RotationUnit rotations) : base(new UnitCompositeCollection() { new MultipliedByUnit(genericUnit, 1), new DividedByUnit(rotations, 1) }) { }
/// <summary> /// Creates a new instance of an acceleration unit. /// </summary> /// <param name="unit">The generic unit</param> /// <param name="time">The time unit</param> public GenericAccelerationUnit(GenericUnit unit, TimeUnit time) : base(new UnitCompositeCollection() { new MultipliedByUnit(unit, 1), new DividedByUnit(time, 2) }) { }
// ======================================= // For modifying roster in-game // ======================================= /** * Adds new unit to roster */ public void AddUnit(GenericUnit gu) { roster.add(gu); }
/// <summary> /// Creates a new instance of a speed unit. /// </summary> /// <param name="unit">The unit for the distance travelled.</param> /// <param name="time">The timeframe for the distance travelled</param> public GenericSpeedUnit(GenericUnit unit, TimeUnit time) : base(new UnitCompositeCollection() { new MultipliedByUnit(unit, 1), new DividedByUnit(time, 1) }) { // speed is always distance (length) over time. }