Beispiel #1
0
        //method called each time a friendly unit/object is getting attacked and therefore requests a radar ping to be shown in the minimap
        public void AddAttackWarning(GameObject Source)
        {
            //first we check whether we can actually add a attack warning (if there isn't one already in that range)
            if (CanAddAttackWarning(Source.transform.position))
            {
                AttackWarning Warning = GetAttackWarning();  //this gets a attack warning that we can use (either an already created one that is unactive and therefore not used or create a new one)
                if (Warning != null)
                {                                            //making sure we have a valid attack warning
                    //settings for the new
                    Warning.Pos = Source.transform.position; //register the position of the source in the attack warning
                    Warning.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
                    Warning.Timer = WarningDuration;

                    //play audio:
                    if (AttackWarningAudio)
                    {
                        AudioManager.PlayAudio(GameManager.Instance.GeneralAudioSource.gameObject, AttackWarningAudio, false);
                    }

                    //set the position of the attack warning correctly on the minimap
                    SetAttackWarningPos(Warning.gameObject, Source.transform.position);

                    Warning.gameObject.SetActive(true); //activate the new attack warning
                }
            }
        }
        /// <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!");
            }
        }
 /// <summary>
 /// Called from an AttackWarning instance when it is disabled.
 /// </summary>
 public void OnAttackWarningDisabled(AttackWarning attackWarning)
 {
     activeList.Remove(attackWarning); //remove the disabled attack warning from the active list
 }