Advertisement
EagleOwle

UI_GunAimText

May 31st, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.48 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class UI_GunAimText : MonoBehaviour
  7. {
  8.  
  9.     [Header("Позиция оружия относительно робота")]
  10.     [SerializeField]
  11.     ModulType modulType;
  12.     [Header("Текущий модуль оружия")]
  13.     [SerializeField]
  14.     private ModulBasys currentModul;
  15.  
  16.     [Header("Максимальный угол, для отключения image")]
  17.     [SerializeField]
  18.     private float maxAngle;
  19.  
  20.     [SerializeField]
  21.     private Text aimTargetText;
  22.  
  23.     [SerializeField]
  24.     private GameObject aimTargetObj;
  25.  
  26.     private void Awake()
  27.     {
  28.         EventController.Singleton.d_SetNewModul += SetNewModul;
  29.         EventController.Singleton.d_ModulClear += ModulClear;
  30.     }
  31.  
  32.     void Update()
  33.     {
  34.         aimTargetObj.SetActive(GameController.showAimTargetName);
  35.  
  36.         if (currentModul == null || GameController.showAimTargetName == false)
  37.         {
  38.             aimTargetText.text = "none";
  39.             return;
  40.         }
  41.  
  42.         //угол между вектором камеры вперед и вектором модуля вперед больше заданной величины
  43.         if (UI_WorldToScreen.CheckAngle(maxAngle, EventController.PlayerDirectionForward, currentModul.GetDirectionForward()) == false)
  44.         {
  45.             aimTargetObj.SetActive(false);
  46.             return;
  47.         }
  48.  
  49.         if (currentModul.GetGunCollision() != null)
  50.         {
  51.             aimTargetText.text = currentModul.GetGunCollision().name;
  52.         }
  53.         else
  54.         {
  55.             aimTargetText.text = "none";
  56.         }
  57.  
  58.     }
  59.  
  60.     private void SetNewModul(ModulBasys modul)
  61.     {
  62.         if (modul.modulType == modulType)
  63.         {
  64.             currentModul = modul;
  65.         }
  66.     }
  67.  
  68.     //Вызывается через делагат из наследников класса modulBasys
  69.     private void ModulClear(ModulBasys modul)
  70.     {
  71.         if (currentModul != null)
  72.         {
  73.             if (currentModul.idModul == modul.idModul)
  74.             {
  75.                 currentModul = null;
  76.             }
  77.         }
  78.     }
  79.  
  80.     private void OnDestroy()
  81.     {
  82.         //Debug.Log("DestroyEventController");
  83.  
  84.         if (EventController.Singleton != null)
  85.         {
  86.             EventController.Singleton.d_SetNewModul -= SetNewModul;
  87.             EventController.Singleton.d_ModulClear -= ModulClear;
  88.         }
  89.     }
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement