//Assign a minimap icon: public void AssignIcon(SelectionObj Selection) { //assign the minimap icon to the selection obj component Selection.MinimapIcon = GetNewMinimapIcon(Selection.MainObj.transform, Selection.MinimapIconSize); AssignIconColor(Selection); }
//Selection Obj collision: public void OnSelectionObjEnter(SelectionObj Source, SelectionObj Target) { if (DebugEnabled == true) { Debug.Log("Collision detected between a " + Source.ObjType + " and a " + Target.ObjType); } SelectionObjEnter(Source, Target); }
public void RemoveMinimapIcon(SelectionObj Selection) { //only proceed if there's a valid selection if (Selection.MinimapIcon == null) { return; } //remove it and add it to the unused list: Selection.MinimapIcon.SetActive(false); Selection.MinimapIcon.transform.SetParent(null, true); UnusedMinimapIcons.Add(Selection.MinimapIcon); Selection.MinimapIcon = null; }
//method to assign the correct color to the minimap icon: public void AssignIconColor(SelectionObj Selection) { MeshRenderer IconRenderer = Selection.MinimapIcon.gameObject.GetComponent <MeshRenderer>(); //set the color of the minimap icon depending on the object type switch (Selection.ObjType) { case SelectionObj.ObjTypes.Unit: //in case it's a unit if (Selection.UnitComp.FreeUnit == false) //if the unit belongs to a faction { //set the faction color IconRenderer.material.color = GameManager.Instance.Factions[Selection.UnitComp.FactionID].FactionColor; } else //if it's a free unit { //set the free faction color IconRenderer.material.color = FreeFactionIconColor; } break; case SelectionObj.ObjTypes.Building: //If the object to select is a building: //set the color as the building's faction color: if (Selection.BuildingComp.FreeBuilding == false) //building belongs to a faction { //set as the faction color IconRenderer.material.color = GameManager.Instance.Factions[Selection.BuildingComp.FactionID].FactionColor; } else //free building { //set as the free faction color IconRenderer.material.color = FreeFactionIconColor; } break; case SelectionObj.ObjTypes.Resource: //in case it's a resource //set the color depending on the resource type IconRenderer.material.color = GameManager.Instance.ResourceMgr.ResourcesInfo[Selection.ResourceComp.ResourceID].TypeInfo.MinimapIconColor; break; default: break; } }
//Attack object collision effect: void OnTriggerEnter(Collider other) { if ((DidDamage == false || DamageOnce == false) && DoDamage == true) { //Make sure that the attack obj either didn't do damage when the attack object is allowed to do damage once or if it can do damage multiple times. SelectionObj HitObj = other.gameObject.GetComponent <SelectionObj>(); if (HitObj != null) { Unit HitUnit = HitObj.MainObj.GetComponent <Unit>(); Building HitBuilding = HitObj.MainObj.GetComponent <Building>(); //If the damaged object is a unit: if (HitUnit) { //Check if the unit belongs to the faction that this attack obj is targeted to and if the unit is actually not dead yet: if (HitUnit.FactionID == TargetFactionID && HitUnit.Dead == false) { if (other != null) { DidDamage = true; //Inform the script that the damage has been done if (AreaDamage) { AttackManager.Instance.LaunchAreaDamage(transform.position, Source); } else { //Custom event: if (GameManager.Instance.Events) { GameManager.Instance.Events.OnAttackPerformed(Source, HitUnit.gameObject); } if (DealDamage == true) { if (DoT.Enabled) //if it's DoT { //DoT settings: Source.ConfigureTargetDoT(HitUnit, AttackManager.GetDamage(HitUnit.gameObject, CustomDamage, DefaultUnitDamage)); } else { //Remove health points from the unit: HitUnit.AddHealth(-AttackManager.GetDamage(HitUnit.gameObject, CustomDamage, DefaultUnitDamage), SourceObj); //Attack effect: AttackManager.Instance.SpawnEffectObj(AttackEffect, other.gameObject, AttackEffectTime, false); //Spawning the damage effect object: AttackManager.Instance.SpawnEffectObj(HitUnit.DamageEffect, other.gameObject, 0.0f, true); } } } } } } //If the attack obj hit a building: if (HitBuilding) { //Check if the building belongs to the faction that this attack obj is targeted to and if the building still has health: if (HitBuilding.FactionID == TargetFactionID && HitBuilding.Health >= 0) { if (other != null) { DidDamage = true; //Inform the script that the damage has been done if (AreaDamage) { AttackManager.Instance.LaunchAreaDamage(transform.position, Source); } else { //Custom event: if (GameManager.Instance.Events) { GameManager.Instance.Events.OnAttackPerformed(Source, HitBuilding.gameObject); } if (DealDamage == true) //only if we can deal damage directly { //Remove health points from the unit: HitBuilding.AddHealth(-AttackManager.GetDamage(HitBuilding.gameObject, CustomDamage, DefaultBuildingDamage), SourceObj); //Attack effect: AttackManager.Instance.SpawnEffectObj(AttackEffect, other.gameObject, AttackEffectTime, false); //Spawning the damage effect object: AttackManager.Instance.SpawnEffectObj(HitBuilding.DamageEffect, other.gameObject, 0.0f, true); } } } } } } } }
//Attack object collision effect: void OnTriggerEnter(Collider other) { if ((DidDamage == false || DamageOnce == false) && DoDamage == true) //Make sure that the attack obj either didn't do damage when the attack object is allowed to do damage once or if it can do damage multiple times. { SelectionObj HitObj = other.gameObject.GetComponent <SelectionObj> (); if (HitObj != null) { Unit HitUnit = HitObj.MainObj.GetComponent <Unit> (); Building HitBuilding = HitObj.MainObj.GetComponent <Building> (); //If the damaged object is a unit: if (HitUnit) { //Check if the unit belongs to the faction that this attack obj is targeted to and if the unit is actually not dead yet: if (HitUnit.FactionID == TargetFactionID && HitUnit.Dead == false) { if (other != null) { DidDamage = true; //Inform the script that the damage has been done if (AreaDamage) { AttackManager.Instance.LaunchAreaDamage(transform.position, AttackRanges, SourceFactionID, AttackEffect, AttackEffectTime, AttackCategoriesList, DoT); } else if (DoT.Enabled) //if it's DoT { //DoT settings: HitUnit.DoT = DoT; HitUnit.DoT.Damage = AttackManager.GetDamage(HitUnit.gameObject, DefaultUnitDamage); } else { //Remove health points from the unit: HitUnit.AddHealth(-AttackManager.GetDamage(HitUnit.gameObject, DefaultUnitDamage), Source); //Attack effect: units only currently AttackManager.Instance.SpawnEffectObj(AttackEffect, other.gameObject, AttackEffectTime, false); } //Spawning the damage effect object: AttackManager.Instance.SpawnEffectObj(HitUnit.DamageEffect, other.gameObject, 0.0f, true); } } } //If the attack obj hit a building: if (HitBuilding) { //Check if the building belongs to the faction that this attack obj is targeted to and if the building still has health: if (HitBuilding.FactionID == TargetFactionID && HitBuilding.Health >= 0) { if (other != null) { DidDamage = true; //Inform the script that the damage has been done if (AreaDamage) { AttackManager.Instance.LaunchAreaDamage(transform.position, AttackRanges, SourceFactionID, AttackEffect, AttackEffectTime, AttackCategoriesList, DoT); } else { //Remove health points from the unit: HitBuilding.AddHealth(-AttackManager.GetDamage(HitBuilding.gameObject, DefaultUnitDamage), Source); } //Spawning the damage effect object: AttackManager.Instance.SpawnEffectObj(HitBuilding.DamageEffect, other.gameObject, 0.0f, true); } } } } } }