//a method that spawns an effect object considering a couple of options public EffectObj SpawnEffectObj(EffectObj prefab, Vector3 spawnPosition, Quaternion spawnRotation = default, Transform parent = null, bool enableLifeTime = true, bool autoLifeTime = true, float lifeTime = 0.0f, bool UI = false) { if (prefab == null) { return(null); } //get the attack effect (either create it or get one tht is inactive): EffectObj newEffect = GetFreeEffectObj(prefab); //make the object child of the assigned parent transform newEffect.transform.SetParent(parent, true); if (UI) { newEffect.GetComponent <RectTransform>().localPosition = spawnPosition; newEffect.GetComponent <RectTransform>().localRotation = spawnRotation; } else { //set the effect's position and rotation newEffect.transform.position = spawnPosition; newEffect.transform.rotation = spawnRotation; } newEffect.ReloadTimer(enableLifeTime, autoLifeTime, lifeTime); //reload lifetime newEffect.Enable(); return(newEffect); }
//a method that destroys a faction entity locally public virtual void DestroyFactionEntityLocal(bool upgrade) { gameMgr.SelectionMgr.Selected.Remove(factionEntity); //deselect the faction entity if it was selected //faction entity death: isDead = true; CurrHealth = 0; //remove the minimap icon: factionEntity.GetSelection().DisableMinimapIcon(); //If this is no upgrade if (upgrade == false) { factionEntity.Disable(true); CustomEvents.OnFactionEntityDead(factionEntity); //call the custom events if (destructionEffect != null) //do not show desctruction effect if it's not even assigned { //get the destruction effect from the pool EffectObj newDestructionEffect = gameMgr.EffectPool.SpawnEffectObj(destructionEffect, transform.position, Quaternion.identity); //destruction sound effect if (destructionAudio != null) { //Check if the destruction effect object has an audio source: if (newDestructionEffect.GetComponent <AudioSource>() != null) { AudioManager.Play(newDestructionEffect.GetComponent <AudioSource>(), destructionAudio, false); //play the destruction audio } else { Debug.LogError("A destruction audio clip has been assigned but the destruction effect object doesn't have an audio source!"); } } } } //Destroy the faction entity's object: if (destroyObject == true) //only if object destruction is allowed { Destroy(gameObject, !upgrade ? destroyObjectTime : 0.0f); IsDestroyed = true; } }
/// <summary> /// Spawns a new attack warning /// </summary> public void Add(Vector3 targetPosition) { //first we check whether we can actually add a attack warning (if there isn't one already in that range) if (!CanAdd(targetPosition)) { return; } //set the the new attack warning's position if (RectTransformUtility.ScreenPointToLocalPointInRectangle( minimapCanvas.GetComponent <RectTransform>(), minimapCamera.WorldToScreenPoint(targetPosition), minimapCamera, out Vector2 canvasPos)) { Vector3 spawnPosition = new Vector3(canvasPos.x, canvasPos.y, 0.0f); //create new attack warning element (or get an inactive one) AttackWarning newWarning = gameMgr.EffectPool.SpawnEffectObj(prefab, spawnPosition, prefab.GetComponent <RectTransform>().localRotation, minimapCanvas.transform, true, true, 0.0f, true).GetComponent <AttackWarning>(); //set the attack warning parameters: newWarning.Init(this, targetPosition); activeList.Add(newWarning); //add it to the active attack warnings list //play audio: AudioManager.Play(gameMgr.GetGeneralAudioSource(), audioClip, false); if (showUIMessage == true) { ErrorMessageHandler.OnErrorMessage(ErrorMessage.underAttack, null); } } else { Debug.LogError("[AttackWarningManager] Unable to find the target position for the new attack warning on the minimap canvas!"); } }