Bullet.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //------------------------------------------------------------
  2. // Game Framework
  3. // Copyright © 2013-2021 Jiang Yin. All rights reserved.
  4. // Homepage: https://gameframework.cn/
  5. // Feedback: mailto:ellan@gameframework.cn
  6. //------------------------------------------------------------
  7. using UnityEngine;
  8. using UnityGameFramework.Runtime;
  9. namespace MetaClient
  10. {
  11. /// <summary>
  12. /// 子弹类。
  13. /// </summary>
  14. public class Bullet : Entity
  15. {
  16. [SerializeField]
  17. private BulletData m_BulletData = null;
  18. public ImpactData GetImpactData()
  19. {
  20. return new ImpactData(m_BulletData.OwnerCamp, 0, m_BulletData.Attack, 0);
  21. }
  22. #if UNITY_2017_3_OR_NEWER
  23. protected override void OnInit(object userData)
  24. #else
  25. protected internal override void OnInit(object userData)
  26. #endif
  27. {
  28. base.OnInit(userData);
  29. }
  30. #if UNITY_2017_3_OR_NEWER
  31. protected override void OnShow(object userData)
  32. #else
  33. protected internal override void OnShow(object userData)
  34. #endif
  35. {
  36. base.OnShow(userData);
  37. m_BulletData = userData as BulletData;
  38. if (m_BulletData == null)
  39. {
  40. Log.Error("Bullet data is invalid.");
  41. return;
  42. }
  43. }
  44. #if UNITY_2017_3_OR_NEWER
  45. protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
  46. #else
  47. protected internal override void OnUpdate(float elapseSeconds, float realElapseSeconds)
  48. #endif
  49. {
  50. base.OnUpdate(elapseSeconds, realElapseSeconds);
  51. CachedTransform.Translate(Vector3.forward * m_BulletData.Speed * elapseSeconds, Space.World);
  52. }
  53. }
  54. }