diff options
author | chai <chaifix@163.com> | 2022-04-23 16:29:56 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2022-04-23 16:29:56 +0800 |
commit | 2c4e865e9ed9fff96aeb7ca3851491d9715b8589 (patch) | |
tree | 45af23d9bad01a061c5129c14b3f30082d188bc8 /SurvivalTest/Assets/Scripts | |
parent | 33858a90ec0bc47f0c3d4fc843f9f45a749175e3 (diff) |
* equip
Diffstat (limited to 'SurvivalTest/Assets/Scripts')
6 files changed, 63 insertions, 55 deletions
diff --git a/SurvivalTest/Assets/Scripts/Equips/Equip_GrenadeLauncher.cs b/SurvivalTest/Assets/Scripts/Equips/Equip_GrenadeLauncher.cs index 090c3ab..0ec7dc9 100644 --- a/SurvivalTest/Assets/Scripts/Equips/Equip_GrenadeLauncher.cs +++ b/SurvivalTest/Assets/Scripts/Equips/Equip_GrenadeLauncher.cs @@ -32,8 +32,6 @@ public class Equip_GrenadeLauncher : EquipBase public override void OnTrigger(GameObject owner) { - Debug.Log("Grenade !!!"); - CrewScript crew = owner.GetComponent<CrewScript>(); //// grenade diff --git a/SurvivalTest/Assets/Scripts/Equips/Equip_Gun.cs b/SurvivalTest/Assets/Scripts/Equips/Equip_Gun.cs index b370e66..fbc3aac 100644 --- a/SurvivalTest/Assets/Scripts/Equips/Equip_Gun.cs +++ b/SurvivalTest/Assets/Scripts/Equips/Equip_Gun.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using UnityEngine; /// <summary> -/// ǹ +/// 枪 /// </summary> public class Equip_Gun : EquipBase { @@ -16,8 +16,43 @@ public class Equip_Gun : EquipBase public override float interval => 0.1f; + private string prefabPath = "prefabs/bullet/bullet"; + + private int index = 0; + + TestPeaceMakerBullet CreateBullet(CrewScript crew, Vector2 dir, float speed, float lifeTime) + { + + TestPeaceMakerBullet bullet = UnityEngine.Object.Instantiate<TestPeaceMakerBullet>(ResourceManager.Instance.Load< TestPeaceMakerBullet>(prefabPath)); + + bullet.transform.position = crew.arrow.position + new Vector3(crew.aimDirection.x, crew.aimDirection.y, 0) * -0.3f; + + bullet.Set(dir, speed, lifeTime); + bullet.gameObject.SetActive(true); + + return bullet; + } + public override void OnTrigger(GameObject owner) { + CrewScript crew = owner.GetComponent<CrewScript>(); + + index++; + index = index % 3; + + if(index == 0) + { + CreateBullet(crew, TestMathHelper.Rotate(crew.aimDirection, -10 * Mathf.Deg2Rad), 12f, 2f); + } + else if(index == 1) + { + CreateBullet(crew, crew.aimDirection, 12f, 2f); + } + else if(index == 2) + { + CreateBullet(crew, TestMathHelper.Rotate(crew.aimDirection, 10 * Mathf.Deg2Rad), 12f, 2f); + } + } }
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Equips.cs b/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Equips.cs index 67e8ae7..3e21c56 100644 --- a/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Equips.cs +++ b/SurvivalTest/Assets/Scripts/Managers/PlayerManager_Equips.cs @@ -4,13 +4,14 @@ using UnityEngine; public partial class PlayerManager : Singleton<PlayerManager> { - // ³ÖÓеÄ×°±¸ public List<EquipBase> equips { get { return m_Equips; } } private List<EquipBase> m_Equips = new List<EquipBase>(); private Coroutine m_CoFire; + public bool isFire { get; private set; } + void InitEquips() { m_Equips.Add(new Equip_Gun()); @@ -35,6 +36,7 @@ public partial class PlayerManager : Singleton<PlayerManager> { if (Input.GetButtonDown("Fire1") || (Input.GetAxis("GunTrigger") == 1)) { + isFire = true; if (m_CoFire == null) { m_CoFire = GameApp.Instance.StartCoroutine(coFire()); @@ -42,6 +44,7 @@ public partial class PlayerManager : Singleton<PlayerManager> } if (!Input.GetButton("Fire1") && (Input.GetAxis("GunTrigger") == 0)) { + isFire = false; if (m_CoFire != null) { GameApp.Instance.StopCoroutine(m_CoFire); @@ -66,7 +69,7 @@ public partial class PlayerManager : Singleton<PlayerManager> if(equip.autoMode == EquipBase.AutoMode.Interval) { string id = equip.GetHashCode().ToString(); - float countDown = TinyCountDown.Instance.Get(id); + float countDown = TinyCountDown.Instance.Get(id); // µ¹¼ÆÊ±ÍÑÀëfireµ¥¶À¼ÆÊ± if(countDown <= 0) { equip.OnTrigger(m_Crew.gameObject); diff --git a/SurvivalTest/Assets/Scripts/Test/TestPeaceMaker.cs b/SurvivalTest/Assets/Scripts/Test/TestPeaceMaker.cs index 7226ac9..86b781b 100644 --- a/SurvivalTest/Assets/Scripts/Test/TestPeaceMaker.cs +++ b/SurvivalTest/Assets/Scripts/Test/TestPeaceMaker.cs @@ -23,6 +23,13 @@ public class TestPeaceMaker : CrewScript } } + public override Transform arrow + { + get + { + return m_Arrow.transform; + } + } public override Transform launchPoint { @@ -53,7 +60,6 @@ public class TestPeaceMaker : CrewScript private SpriteRenderer m_SpriteRenderer; private TopDownTransform m_Coord; - private Coroutine m_CoFire; private Vector3 m_PreMouse; @@ -92,7 +98,7 @@ public class TestPeaceMaker : CrewScript SetAim(); - bool isFire = Fire(); + bool isFire = PlayerManager.Instance.isFire; CameraFollow(); @@ -204,52 +210,4 @@ public class TestPeaceMaker : CrewScript return target; } - bool Fire() - { - if (Input.GetButtonDown("Fire1") || (Input.GetAxis("GunTrigger") == 1)) - { - if (m_CoFire == null) - { - m_CoFire = StartCoroutine(coFire(0.1f)); - } - } - if (!Input.GetButton("Fire1") && (Input.GetAxis("GunTrigger") == 0)) - { - if(m_CoFire != null) - { - StopCoroutine(m_CoFire); - m_CoFire = null; - } - return false; - } - return true; - } - - IEnumerator coFire(float interval) - { - while (true) - { - CreateBullet(TestMathHelper.Rotate(m_AimDirection, -10 * Mathf.Deg2Rad), 12f, 2f); - yield return new WaitForSeconds(interval / 3f); - - CreateBullet(m_AimDirection, 12f, 2f); - yield return new WaitForSeconds(interval / 3f); - - CreateBullet(TestMathHelper.Rotate(m_AimDirection, 10 * Mathf.Deg2Rad), 12f, 2f); - yield return new WaitForSeconds(interval / 3f); - } - } - - TestPeaceMakerBullet CreateBullet(Vector2 dir, float speed, float lifeTime) - { - TestPeaceMakerBullet bullet = Instantiate<TestPeaceMakerBullet>(m_Bullet); - - bullet.transform.position = m_Arrow.transform.position + new Vector3(m_AimDirection.x, m_AimDirection.y, 0) * -0.3f; - - bullet.Set(dir, speed, lifeTime); - bullet.gameObject.SetActive(true); - - return bullet; - } - } diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelEquipBar/UIEquipWidget.cs b/SurvivalTest/Assets/Scripts/UI/Panel/PanelEquipBar/UIEquipWidget.cs index bccd322..14c8717 100644 --- a/SurvivalTest/Assets/Scripts/UI/Panel/PanelEquipBar/UIEquipWidget.cs +++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelEquipBar/UIEquipWidget.cs @@ -11,6 +11,7 @@ public struct UIEquipWidgetParam public class UIEquipWidget : UIGridItemBase { public Image Image_Icon; + public Image Image_CD; public EquipBase equip { get { return m_Equip; } } private EquipBase m_Equip; @@ -21,6 +22,16 @@ public class UIEquipWidget : UIGridItemBase m_Equip = info.equip; Image_Icon.sprite = ResourceManager.Instance.Load<Sprite>(info.equip.iconPath); + } + private void Update() + { + if(equip.autoMode == EquipBase.AutoMode.Interval) + { + float countDown = TinyCountDown.Instance.Get(equip.GetHashCode().ToString()); + float t = countDown / equip.interval; + Image_CD.fillAmount = t; + } } + }
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/Unit/Crew/CrewScript.cs b/SurvivalTest/Assets/Scripts/Unit/Crew/CrewScript.cs index 4993cd7..348e793 100644 --- a/SurvivalTest/Assets/Scripts/Unit/Crew/CrewScript.cs +++ b/SurvivalTest/Assets/Scripts/Unit/Crew/CrewScript.cs @@ -11,4 +11,7 @@ public class CrewScript : MonoBehaviour // Áñµ¯·¢Éä¿Ú£¨Èç¹ûÓеϰ£© public virtual Transform launchPoint { get; } + // ×¼ÐÇ£¨Èç¹ûÓеϰ£© + public virtual Transform arrow { get; } + } |