Advertisement
Caminhoneiro

Repository Pattern unity

Jan 21st, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.11 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using Kvant;
  4.  
  5. public enum WeaponType
  6. {
  7.     BulletUp,
  8.     Bullet
  9. }
  10.  
  11. //public enum Flame
  12. //{
  13. //    Blue,
  14. //    Red
  15. //}
  16.  
  17. //Na real sou o player controller
  18. public class WeaponController : MonoBehaviour
  19. {
  20.     public Wall waveReference;
  21.  
  22.     [SerializeField]
  23.     [Header("O attack reference o player pega automatico no start IGNORE")]
  24.     GameObject attackReference;
  25.     float attackRange;
  26.  
  27.     #region Enums
  28.     public WeaponType weaponType;
  29.     //public Flame flameColor;
  30.  
  31.     private IWeapon iWeapon;
  32.     #endregion
  33.  
  34.     private void HandleWeaponType()
  35.     {
  36.  
  37.         //To prevent Unity from creating multiple copies of the same component in inspector at runtime
  38.         Component c = gameObject.GetComponent<IWeapon>() as Component;
  39.  
  40.         if (c != null)
  41.         {
  42.             Destroy(c);
  43.         }
  44.  
  45.         #region Strategy
  46.         switch (weaponType)
  47.         {
  48.             case WeaponType.BulletUp:
  49.                 iWeapon = gameObject.AddComponent<BulletUp>();
  50.                 break;
  51.  
  52.             case WeaponType.Bullet:
  53.                 iWeapon = gameObject.AddComponent<Bullet>();
  54.                 break;
  55.  
  56.             default:
  57.                 iWeapon = gameObject.AddComponent<Bullet>();
  58.                 break;
  59.         }
  60.         #endregion
  61.     }
  62.  
  63.     //public void HandleFlameColor()
  64.     //{
  65.  
  66.     //    Component c = gameObject.GetComponent<IFlame>() as Component;
  67.  
  68.     //    if (c != null)
  69.     //    {
  70.     //        Destroy(c);
  71.     //        iFlame.DestroyFlame(); // so that number of flame objects remains one
  72.     //    }
  73.  
  74.     //    #region Strategy
  75.     //    switch (flameColor)
  76.     //    {
  77.  
  78.     //        case Flame.Blue:
  79.     //            iFlame = gameObject.AddComponent<BlueFlame>();
  80.     //            break;
  81.  
  82.     //        case Flame.Red:
  83.     //            iFlame = gameObject.AddComponent<RedFlame>();
  84.     //            break;
  85.  
  86.     //        default:
  87.     //            iFlame = gameObject.AddComponent<BlueFlame>();
  88.     //            break;
  89.     //    }
  90.     //    #endregion
  91.  
  92.     //}
  93.  
  94.     public void Fire()
  95.     {
  96.         iWeapon.Shoot();
  97.     }
  98.  
  99.     void Start()
  100.     {
  101.         attackReference = GameObject.FindGameObjectWithTag("AudioRef");
  102.         HandleWeaponType();
  103.         //HandleFlameColor();
  104.         //iFlame.ShowFlame();
  105.     }
  106.    
  107.     void BerserkRage()
  108.     {
  109.         print("PUTAÇO");
  110.     }
  111.    
  112.     void BrutalizaTudo()
  113.     {
  114.        waveReference.positionNoiseAmplitude = 3f; //aumentar gradualmente
  115.         FindObjectOfType<ShakeCamera>().enabled = true;
  116.     }
  117.  
  118.     void TudoSusu()
  119.     {
  120.         waveReference.positionNoiseAmplitude = 0.7f; //diminuir gradualmente
  121.         FindObjectOfType<ShakeCamera>().enabled = false;
  122.     }
  123.  
  124.     [SerializeField]
  125.     BreathScript breath;
  126.  
  127.     [SerializeField]
  128.     [Tooltip("Altura da voz pra captar para dar ataque aéreo")]
  129.     float HardAttackVolumeInput = 2f;
  130.  
  131.     [SerializeField]
  132.     [Tooltip("Altura da voz pra captar para dar ataque terrestre")]
  133.     float EasyAttackVolumeInput = 1f;
  134.  
  135.     void AtaquePorVoz()
  136.     {
  137.         if (attackRange > HardAttackVolumeInput)
  138.         {
  139.             weaponType = WeaponType.BulletUp;
  140.             BrutalizaTudo();
  141.         }
  142.         else if (attackRange > EasyAttackVolumeInput)
  143.         {
  144.             weaponType = WeaponType.Bullet;
  145.             Fire();
  146.         }
  147.         else
  148.         {
  149.             TudoSusu();
  150.             print("Fica de boa ai irmão");
  151.         }
  152.     }
  153.  
  154.     void AtaquePorMouse()
  155.     {
  156.         if (Input.GetMouseButton(0))
  157.         {
  158.             weaponType = WeaponType.BulletUp;
  159.             BrutalizaTudo();
  160.             Fire();
  161.         }
  162.  
  163.         else if (Input.GetMouseButton(1))
  164.         {
  165.             weaponType = WeaponType.Bullet;
  166.             Fire();
  167.         }
  168.         else
  169.         {
  170.             TudoSusu();
  171.         }
  172.     }
  173.  
  174.     void Update()
  175.     {
  176.         HandleWeaponType();
  177.         attackRange = attackReference.transform.localScale.y;
  178.  
  179.  
  180.         AtaquePorMouse();
  181.  
  182.         if (Input.GetKeyDown(KeyCode.Space))
  183.         {
  184.             EventManager.onStartGame();
  185.         }
  186.  
  187.         //to check the value of weaponType in the inspector while in play mode
  188.         if (Input.GetKeyDown(KeyCode.C))
  189.         {
  190.             HandleWeaponType();
  191.         }
  192.  
  193.         //if (Input.GetKeyDown(KeyCode.F))
  194.         //{
  195.         //    HandleFlameColor();
  196.         //    iFlame.ShowFlame();
  197.         //}
  198.     }
  199.  
  200.  
  201.     #region Colisão
  202.  
  203.     //Pega local de colisão, alvo, e distribui dano
  204.     void SpawnExplosion(Vector3 hitPosition, Transform target, int damage)
  205.     {
  206.         Explosion temp = target.GetComponent<Explosion>();
  207.         if (temp != null)
  208.             temp.IveBeenHit(hitPosition, damage);
  209.  
  210.     }
  211.  
  212.  
  213.     private void OnTriggerEnter(Collider c)
  214.     {
  215.         if (c.tag == "Enemy" && this.gameObject.tag == "Player")
  216.         {
  217.             SpawnExplosion(c.transform.position, gameObject.transform, 1);
  218.             //SpawnImpulse(c.transform.position, c.transform);
  219.             print("Sentiu");
  220.             //GetHit();
  221.         }
  222.     }
  223.  
  224.     #endregion
  225. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement