BulletData.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using UnityEngine;
  2. using System.Collections;
  3. using System;
  4. using System.Collections.Generic;
  5. //子弹移动类型
  6. public enum BulletMoveType
  7. {
  8. Bullet_Move_Target_Toward = 0, //向目标移动, 总是面朝移动方向
  9. Bullet_Move_Trace_Target_Toward = 1, //跟踪目标, 总是面朝移动方向
  10. Bullet_Move_Throw_Toward = 2, //抛掷,总是面朝移动方向
  11. Bullet_Move_Target = 3, //向目标移动
  12. Bullet_Move_Forward = 4, //向前移动
  13. Bullet_Move_Trace_Target = 5, //跟踪目标
  14. Bullet_Move_Throw = 6, //抛掷
  15. Bullet_Move_Forward_Toward = 7, //向前移动,总是面朝移动方向
  16. Bullet_Move_None = 8, //不移动
  17. }
  18. //子弹(炮弹)碰撞销毁类型
  19. public enum BulletHitDestroyType
  20. {
  21. Bullet_HitDestroy_Fighter = 0, //碰撞玩家销毁
  22. Bullet_HitDestroy_Penetrate = 1, //穿透玩家销毁
  23. Bullet_HitDestroy_Floor = 2, //碰撞地面销毁
  24. Bullet_HitDestroy_None = 3, //不碰撞,到时间销毁
  25. Bullet_HitDestroy_Target = 4, //类似0,但只有碰撞到目标才会发生事件
  26. Bullet_HitDestory_Fighter_Floor = 5, //碰撞到地面或者玩家都会销毁
  27. }
  28. public class BulletData
  29. {
  30. public int id;
  31. public EffectFollowType followType;
  32. public EffectTargetType targetType;
  33. public Vector3 offset;
  34. public string effect;
  35. public EffectType actorType;
  36. public float lifeTime;
  37. public string sound;
  38. public Vector3 targetOffset;
  39. public BulletHitDestroyType hitDestroyType;
  40. public Vector3 initSpeedVec;
  41. public Vector3 accelationSpeedVec;
  42. public float accelationDuration;
  43. public string targetLink; //目标随机范围
  44. public string startLink; //出发点随机范围
  45. public BulletMoveType moveType; //移动类型
  46. private float[] mHurtDist = null;
  47. private int[] mHurtFrames = null;
  48. public float[] HurtDist
  49. {
  50. get { return mHurtDist; }
  51. }
  52. public int[] HurtFrames
  53. {
  54. get { return mHurtFrames; }
  55. }
  56. public BulletData(int id)
  57. {
  58. Dictionary<string, string> cfg = ConfigMgr.Instance.getLine(id, Config.BulletCfgName);
  59. if(cfg!=null)
  60. {
  61. this.id = id;
  62. if (cfg.ContainsKey("Prefab"))
  63. this.effect = cfg["Prefab"];
  64. if (cfg.ContainsKey("Link"))
  65. this.startLink = cfg["Link"];
  66. if (cfg.ContainsKey("TargetLink"))
  67. this.targetLink = cfg["TargetLink"];
  68. if (cfg.ContainsKey("FlyDuration"))
  69. float.TryParse(cfg["FlyDuration"], out lifeTime);
  70. if(cfg.ContainsKey("VelocityVector"))
  71. {
  72. initSpeedVec = StringUtil.convertVector3(cfg["VelocityVector"]);
  73. }
  74. if(cfg.ContainsKey("VariableSpeed"))
  75. {
  76. accelationSpeedVec = StringUtil.convertVector3(cfg["VariableSpeed"]);
  77. }
  78. if(cfg.ContainsKey("VariableTime"))
  79. {
  80. float.TryParse(cfg["VariableTime"], out accelationDuration);
  81. }
  82. if(cfg.ContainsKey("HurtFrames"))
  83. {
  84. string[] strTemps = StringUtil.split(cfg["HurtFrames"], ';');
  85. if(strTemps != null)
  86. {
  87. mHurtDist = new float[strTemps.Length];
  88. mHurtFrames = new int[strTemps.Length];
  89. for (int idx =0; idx < strTemps.Length;idx++)
  90. {
  91. string[] strTemps2 = StringUtil.split(strTemps[idx], ':');
  92. if(strTemps2 != null && strTemps2.Length == 2)
  93. {
  94. float dist = 0;
  95. int frame = 0;
  96. float.TryParse(strTemps2[0], out dist);
  97. int.TryParse(strTemps2[1], out frame);
  98. mHurtDist[idx] = dist;
  99. mHurtFrames[idx] = frame;
  100. }
  101. }
  102. }
  103. }
  104. actorType = EffectType.EffectType_Fly;
  105. hitDestroyType = BulletHitDestroyType.Bullet_HitDestroy_Target;
  106. moveType = BulletMoveType.Bullet_Move_Forward_Toward;
  107. targetType = EffectTargetType.Effect_Target_Self;
  108. }
  109. else
  110. {
  111. DebugHelper.LogError("读取子弹特效数据 {0} 出错", id);
  112. }
  113. }
  114. }