FTriggerBulletEvent.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Security;
  4. using UnityEngine;
  5. namespace Flux
  6. {
  7. [FEvent("Skill/伤害相关/发射子弹")]
  8. public class FTriggerBulletEvent : FEvent
  9. {
  10. [SerializeField]
  11. private AudioClip _soundClip = null;
  12. public AudioClip SoundClip { get { return _soundClip; } }
  13. [HideInInspector]
  14. [SerializeField]
  15. private int _hitEffectId;
  16. public int HitEffectId
  17. {
  18. get { return _hitEffectId; }
  19. }
  20. [HideInInspector]
  21. [SerializeField]
  22. private GameObject _hitEffectPrefab = null;
  23. public GameObject HitEffectPrefab
  24. {
  25. get { return _hitEffectPrefab; }
  26. }
  27. [HideInInspector]
  28. [SerializeField]
  29. private string _hitEffectLink;
  30. public string HitEffectLink
  31. {
  32. get { return _hitEffectLink; }
  33. }
  34. [HideInInspector]
  35. [SerializeField]
  36. private GameObject _bulletPrefab = null; //子弹预制体
  37. public GameObject BulletPrefab
  38. {
  39. get { return _bulletPrefab; }
  40. }
  41. [HideInInspector]
  42. [SerializeField]
  43. private int _bulletId;
  44. public int BulletId
  45. {
  46. get { return _bulletId; }
  47. }
  48. [HideInInspector]
  49. [SerializeField]
  50. private string _bulletLink = null; //子弹挂载点
  51. public string BulletLink
  52. {
  53. get { return _bulletLink; }
  54. }
  55. [HideInInspector]
  56. [SerializeField]
  57. private float _bulletFlyDuration = 0;
  58. public float BulletFlyDuration
  59. {
  60. get { return _bulletFlyDuration; }
  61. }
  62. [HideInInspector]
  63. [SerializeField]
  64. private Vector3 _bulletInitVelocity;
  65. public Vector3 BulletInitVelocity
  66. {
  67. get { return _bulletInitVelocity; }
  68. }
  69. [HideInInspector]
  70. [SerializeField]
  71. private Vector3 _bulletAcceleration;
  72. public Vector3 BulletAcceleration
  73. {
  74. get { return _bulletAcceleration; }
  75. }
  76. [HideInInspector]
  77. [SerializeField]
  78. private float _bulletAccelerationTime;
  79. public float BulletAccelerationTime
  80. {
  81. get { return _bulletAccelerationTime; }
  82. }
  83. [HideInInspector]
  84. [SerializeField]
  85. private string _bulletTargetLink;
  86. public string BulletTargetLink
  87. {
  88. get { return _bulletTargetLink; }
  89. }
  90. [HideInInspector]
  91. [SerializeField]
  92. private Vector3 _range;
  93. public Vector3 Range
  94. {
  95. get { return _range; }
  96. }
  97. [HideInInspector]
  98. [SerializeField]
  99. private int _moveType;
  100. public int MoveType
  101. {
  102. get { return _moveType; }
  103. }
  104. [HideInInspector]
  105. [SerializeField]
  106. private float _initSpeed;
  107. public float InitSpeed
  108. {
  109. get { return _initSpeed; }
  110. }
  111. [HideInInspector]
  112. [SerializeField]
  113. private float _acceleration;
  114. public float Acceleration
  115. {
  116. get { return _acceleration; }
  117. }
  118. [HideInInspector]
  119. [SerializeField]
  120. private float _moveDistance;
  121. public float MoveDistance
  122. {
  123. get { return _moveDistance; }
  124. }
  125. [HideInInspector]
  126. [SerializeField]
  127. private int _triggerBuffId;
  128. public int TriggerBuffId
  129. {
  130. get { return _triggerBuffId; }
  131. }
  132. [HideInInspector]
  133. [SerializeField]
  134. private int _triggerBuffRate;
  135. public int TriggerBuffRate
  136. {
  137. get { return _triggerBuffRate; }
  138. }
  139. private GameObject _bulletGo;
  140. private ParticleSystem _bulletParticleSystem;
  141. private Animator _bulletAnimator;
  142. private GameObject _hitEffectGo;
  143. private ParticleSystem _hitParticleSystem;
  144. private Transform _bulletTrans;
  145. private Vector3 mStartOffset; //开始偏移位置
  146. private Vector3 mTargetOffset; //目标偏移位置
  147. private AudioSource _source;
  148. private MoveProcessor _beHitMoveProcessor;
  149. private BulletEventMoveProcessor _bulletMoveProcessor = null;
  150. private Vector3 _beHitDestPos;
  151. private float moveSpeed = 0;
  152. private float _lifeTime = 0;
  153. private float _previousTimeSinceTrigger = 0;
  154. private float _previousSpeed = 0;
  155. private Vector3 _targetPos;
  156. public FTriggerBulletEvent()
  157. {
  158. _eventType = SkillActionFrameEventType.FE_Bullet;
  159. }
  160. protected override void OnSetDefaultValues()
  161. {
  162. base.OnSetDefaultValues();
  163. }
  164. protected override void OnTrigger(float timeSinceTrigger)
  165. {
  166. if (_targetTrans != null)
  167. {
  168. FighterMoveType type = (FighterMoveType)_moveType;
  169. if (type != FighterMoveType.None)
  170. {
  171. _beHitMoveProcessor = new MoveProcessor(_targetTrans);
  172. if (type == FighterMoveType.Beat_Back)
  173. {
  174. Vector3 dir = (_targetTrans.position - _casterTrans.position).normalized;
  175. dir.y = 0;
  176. _beHitDestPos = dir * _moveDistance + _targetTrans.position;
  177. }
  178. else if (type == FighterMoveType.Beat_Fly)
  179. {
  180. Vector3 dir = Vector3.up;
  181. _beHitDestPos = dir * _moveDistance + _targetTrans.position;
  182. }
  183. }
  184. }
  185. if (_bulletPrefab != null)
  186. {
  187. _bulletGo = (GameObject)Instantiate(_bulletPrefab);
  188. _bulletTrans = _bulletGo.transform;
  189. Vector3 startForward = _targetTrans != null ? (_targetTrans.position - _casterTrans.position).normalized : Vector3.forward;
  190. SetStartTransform(startForward);
  191. if (_bulletFlyDuration > 0 && _targetTrans != null)
  192. moveSpeed = Vector3.Distance(_targetTrans.position, _casterTrans.position) / _bulletFlyDuration;
  193. _bulletParticleSystem = _bulletGo.GetComponentInChildren<ParticleSystem>();
  194. if (_bulletParticleSystem != null)
  195. {
  196. ParticleSystem.MainModule mainModule = _bulletParticleSystem.main;
  197. mainModule.simulationSpeed = Sequence.Speed;
  198. }
  199. _bulletAnimator = _bulletGo.GetComponentInChildren<Animator>();
  200. if(_bulletAnimator!=null)
  201. {
  202. _bulletAnimator.enabled = true;
  203. _bulletAnimator.SetLayerWeight(0, 1);
  204. if (timeSinceTrigger > 0)
  205. {
  206. _bulletAnimator.Update(timeSinceTrigger - 0.001f);
  207. }
  208. else
  209. {
  210. _bulletAnimator.Update(0f);
  211. }
  212. }
  213. if (_targetTrans != null)
  214. {
  215. _targetPos = _targetTrans.position;
  216. }
  217. if (_bulletMoveProcessor == null)
  218. {
  219. _bulletMoveProcessor = new BulletEventMoveProcessor(_bulletTrans, BulletMoveType.Bullet_Move_Forward_Toward, moveSpeed, _bulletInitVelocity, _bulletAcceleration, mTargetOffset, _bulletAccelerationTime);
  220. }
  221. _bulletMoveProcessor.Start();
  222. }
  223. else
  224. {
  225. Debug.LogError("没有选择子弹的预制体");
  226. }
  227. if (_bulletParticleSystem != null && Sequence.IsPlaying && Sequence.IsPlayingForward)
  228. _bulletParticleSystem.Play(true);
  229. _previousTimeSinceTrigger = timeSinceTrigger;
  230. _previousSpeed = Sequence.Speed;
  231. _lifeTime = _bulletFlyDuration;
  232. }
  233. protected override void OnPause()
  234. {
  235. if(Application.isPlaying)
  236. {
  237. if (_source)
  238. _source.Pause();
  239. }
  240. else
  241. {
  242. #if UNITY_EDITOR
  243. UnityEditor.AudioUtility.PauseClip(_soundClip);
  244. #endif
  245. }
  246. if (_hitParticleSystem != null)
  247. _hitParticleSystem.Pause();
  248. if (_bulletParticleSystem != null)
  249. _bulletParticleSystem.Pause();
  250. if (_bulletAnimator != null)
  251. _bulletAnimator.enabled = false;
  252. }
  253. protected override void OnResume()
  254. {
  255. if (Sequence.IsPlaying)
  256. {
  257. if(Application.isPlaying)
  258. {
  259. if (_source)
  260. _source.Play();
  261. }
  262. else
  263. {
  264. #if UNITY_EDITOR
  265. UnityEditor.AudioUtility.PlayClip(_soundClip);
  266. #endif
  267. }
  268. }
  269. if (_hitParticleSystem != null && Sequence.IsPlayingForward)
  270. _hitParticleSystem.Play(true);
  271. if (_bulletParticleSystem != null && Sequence.IsPlayingForward)
  272. _bulletParticleSystem.Play(true);
  273. if (_bulletAnimator != null)
  274. _bulletAnimator.enabled = true;
  275. }
  276. protected override void OnFinish()
  277. {
  278. if(Application.isPlaying)
  279. {
  280. if (_source)
  281. {
  282. if (_source.clip == _soundClip && _source.isPlaying)
  283. {
  284. _source.Stop();
  285. _source.clip = null;
  286. }
  287. }
  288. }
  289. else
  290. {
  291. #if UNITY_EDITOR
  292. UnityEditor.AudioUtility.StopClip(_soundClip);
  293. #endif
  294. }
  295. if (_bulletMoveProcessor != null)
  296. {
  297. _bulletMoveProcessor.Stop();
  298. _bulletMoveProcessor = null;
  299. }
  300. if (_hitParticleSystem != null)
  301. _hitParticleSystem.Stop(true);
  302. if (_bulletParticleSystem != null)
  303. _bulletParticleSystem.Stop(true);
  304. if (_bulletAnimator && (IsLastEvent || _track.GetEvent(GetId() + 1).Start != End))
  305. {
  306. _bulletAnimator.SetLayerWeight(0, 0);
  307. _bulletAnimator.enabled = false;
  308. }
  309. if (_hitEffectGo != null)
  310. {
  311. GameObject.DestroyImmediate(_hitEffectGo);
  312. _hitEffectGo = null;
  313. }
  314. if (_bulletGo != null)
  315. {
  316. GameObject.DestroyImmediate(_bulletGo);
  317. _bulletGo = null;
  318. _bulletTrans = null;
  319. }
  320. if (_targetTrans != null)
  321. {
  322. _targetTrans.position = _targetPos;
  323. }
  324. }
  325. protected override void OnStop()
  326. {
  327. if (Application.isPlaying)
  328. {
  329. if (_source)
  330. {
  331. if (_source.clip == _soundClip && _source.isPlaying)
  332. {
  333. _source.Stop();
  334. _source.clip = null;
  335. }
  336. }
  337. }
  338. else
  339. {
  340. #if UNITY_EDITOR
  341. UnityEditor.AudioUtility.StopClip(_soundClip);
  342. #endif
  343. }
  344. if (_hitParticleSystem != null)
  345. {
  346. _hitParticleSystem.Stop(true);
  347. _hitParticleSystem.Clear(true);
  348. }
  349. if(_bulletParticleSystem!=null)
  350. {
  351. _bulletParticleSystem.Stop(true);
  352. _bulletParticleSystem.Clear(true);
  353. }
  354. if (_bulletMoveProcessor != null)
  355. {
  356. _bulletMoveProcessor.Stop();
  357. _bulletMoveProcessor = null;
  358. }
  359. if (_bulletAnimator && (IsLastEvent || _track.GetEvent(GetId() + 1).Start != End))
  360. {
  361. _bulletAnimator.SetLayerWeight(0, 0);
  362. _bulletAnimator.enabled = false;
  363. }
  364. if (_bulletGo!=null)
  365. {
  366. GameObject.DestroyImmediate(_bulletGo);
  367. _bulletGo = null;
  368. _bulletTrans = null;
  369. }
  370. if (_hitEffectGo != null)
  371. {
  372. GameObject.DestroyImmediate(_hitEffectGo);
  373. _hitEffectGo = null;
  374. }
  375. if (_targetTrans != null)
  376. {
  377. _targetTrans.position = _targetPos;
  378. }
  379. }
  380. public override int GetMaxLength()
  381. {
  382. return base.GetMaxLength();
  383. }
  384. public override string Text
  385. {
  386. get { return "发射子弹"; }
  387. set { }
  388. }
  389. protected override void OnUpdateEvent(float timeSinceTrigger)
  390. {
  391. float delta = timeSinceTrigger - _previousTimeSinceTrigger;
  392. _previousTimeSinceTrigger = timeSinceTrigger;
  393. _lifeTime -= delta;
  394. if (_lifeTime > 0)
  395. {
  396. if (_bulletParticleSystem != null)
  397. {
  398. if (!Sequence.IsPlaying || !Sequence.IsPlayingForward)
  399. {
  400. _previousSpeed = 1;
  401. ParticleSystem.MainModule mainModule = _bulletParticleSystem.main;
  402. mainModule.simulationSpeed = _previousSpeed;
  403. if (Sequence.IsPlayingForward && delta > 0)
  404. {
  405. _bulletParticleSystem.Simulate(delta, true, false);
  406. }
  407. }
  408. else if (_previousSpeed != Sequence.Speed)
  409. {
  410. _previousSpeed = Sequence.Speed;
  411. ParticleSystem.MainModule mainModule = _bulletParticleSystem.main;
  412. mainModule.simulationSpeed = Mathf.Abs(_previousSpeed);
  413. }
  414. }
  415. if (_bulletMoveProcessor != null)
  416. {
  417. _bulletMoveProcessor.Update(delta);
  418. CheckFlyBulletHit();
  419. }
  420. if (_bulletAnimator != null)
  421. {
  422. if (!_bulletAnimator.enabled)
  423. _bulletAnimator.enabled = true;
  424. if (delta > 0)
  425. {
  426. _bulletAnimator.Update(delta);
  427. _previousTimeSinceTrigger = timeSinceTrigger;
  428. }
  429. }
  430. }
  431. if (_source != null && _source.clip != null)
  432. {
  433. _source.PlayScheduled(delta);
  434. }
  435. if (_hitParticleSystem != null)
  436. {
  437. if (!Sequence.IsPlaying || !Sequence.IsPlayingForward)
  438. {
  439. _previousSpeed = 1;
  440. ParticleSystem.MainModule mainModule = _hitParticleSystem.main;
  441. mainModule.simulationSpeed = _previousSpeed;
  442. if (Sequence.IsPlayingForward && delta > 0)
  443. {
  444. _hitParticleSystem.Simulate(delta, true, false);
  445. }
  446. }
  447. else if (_previousSpeed != Sequence.Speed)
  448. {
  449. _previousSpeed = Sequence.Speed;
  450. ParticleSystem.MainModule mainModule = _hitParticleSystem.main;
  451. mainModule.simulationSpeed = Mathf.Abs(_previousSpeed);
  452. }
  453. }
  454. if (_beHitMoveProcessor != null)
  455. {
  456. _beHitMoveProcessor.Update(delta);
  457. }
  458. }
  459. private void SetStartTransform(Vector3 startForward)
  460. {
  461. Transform linkTrans = UnityEngineUtils.RecurisiveFindTransformChild(_casterTrans,_bulletLink);
  462. if(linkTrans!=null)
  463. {
  464. mStartOffset = linkTrans.position;
  465. }
  466. if (_targetTrans != null)
  467. {
  468. linkTrans = UnityEngineUtils.RecurisiveFindTransformChild(_targetTrans, _bulletTargetLink);
  469. if (linkTrans != null)
  470. {
  471. mTargetOffset = linkTrans.position;
  472. }
  473. }
  474. _bulletTrans.position = mStartOffset;
  475. _bulletTrans.forward = startForward;
  476. }
  477. private void CheckFlyBulletHit()
  478. {
  479. if (CheckHitTarget())
  480. {
  481. ProcessHitFighter();
  482. DestroyBullet();
  483. }
  484. }
  485. private void ProcessHitFighter()
  486. {
  487. if(Application.isPlaying)
  488. {
  489. _source = Owner.GetComponent<AudioSource>();
  490. if (_source == null)
  491. _source = Owner.gameObject.AddComponent<AudioSource>();
  492. _source.volume = 1;
  493. _source.loop = false;
  494. _source.clip = _soundClip;
  495. if (Sequence.IsPlaying)
  496. _source.Play();
  497. }
  498. else
  499. {
  500. #if UNITY_EDITOR
  501. UnityEditor.AudioUtility.PlayClip(_soundClip);
  502. #endif
  503. }
  504. if (_hitEffectPrefab != null)
  505. {
  506. Vector3 pos = _targetTrans.position;
  507. Transform hitPoint = UnityEngineUtils.RecurisiveFindTransformChild(_targetTrans, _hitEffectLink);
  508. if(hitPoint!=null)
  509. {
  510. pos = hitPoint.position;
  511. }
  512. _hitEffectGo = (GameObject)Instantiate(_hitEffectPrefab);
  513. _hitEffectGo.transform.SetParent(hitPoint);
  514. _hitEffectGo.transform.localPosition = Vector3.zero;
  515. _hitEffectGo.transform.localScale = Vector3.one;
  516. _hitEffectGo.transform.localRotation = Quaternion.identity;
  517. _hitParticleSystem = _hitEffectGo.GetComponentInChildren<ParticleSystem>();
  518. if (_hitParticleSystem != null)
  519. {
  520. ParticleSystem.MainModule mainModule = _hitParticleSystem.main;
  521. mainModule.simulationSpeed = Sequence.Speed;
  522. }
  523. }
  524. if (_hitParticleSystem != null && Sequence.IsPlaying && Sequence.IsPlayingForward)
  525. _hitParticleSystem.Play(true);
  526. if (_beHitMoveProcessor != null)
  527. {
  528. _beHitMoveProcessor.Start(_initSpeed, _acceleration, _beHitDestPos);
  529. }
  530. }
  531. private bool CheckHitTarget()
  532. {
  533. if (_targetTrans != null)
  534. {
  535. Vector3 offset = mTargetOffset - _bulletTrans.position;
  536. return Mathf.Abs(offset.x) <= _range.x && Mathf.Abs(offset.y) <= _range.y && Mathf.Abs(offset.z) <= _range.z;
  537. }
  538. return false;
  539. }
  540. private void DestroyBullet()
  541. {
  542. if (_bulletParticleSystem != null)
  543. {
  544. _bulletParticleSystem.Stop(true);
  545. _bulletParticleSystem.Clear(true);
  546. }
  547. _bulletMoveProcessor.Stop();
  548. _bulletMoveProcessor = null;
  549. if (_bulletGo != null)
  550. {
  551. GameObject.DestroyImmediate(_bulletGo);
  552. _bulletGo = null;
  553. _bulletTrans = null;
  554. }
  555. }
  556. public override SecurityElement SaveToXml()
  557. {
  558. SecurityElement node = base.SaveToXml();
  559. SecurityElement paramNode = WriteParamNode("bulletid", _bulletId.ToString(), "int");
  560. node.AddChild(paramNode);
  561. if (_bulletPrefab != null)
  562. {
  563. #if UNITY_EDITOR
  564. paramNode = WriteParamNode("bulletPrefab", UnityEditor.AssetDatabase.GetAssetPath(_bulletPrefab), "string");
  565. node.AddChild(paramNode);
  566. #endif
  567. }
  568. paramNode = WriteParamNode("bulletLink",_bulletLink, "string");
  569. if (paramNode != null)
  570. node.AddChild(paramNode);
  571. paramNode = WriteParamNode("bulletTargetLink", _bulletTargetLink, "string");
  572. if (paramNode != null)
  573. node.AddChild(paramNode);
  574. paramNode = WriteParamNode("bulletFlyDuration", _bulletFlyDuration.ToString(), "string");
  575. node.AddChild(paramNode);
  576. paramNode = WriteParamNode("bulletInitVelocity", StringUtil.ConvertVector2Str(_bulletInitVelocity), "string");
  577. node.AddChild(paramNode);
  578. paramNode = WriteParamNode("bulletAcceleration", StringUtil.ConvertVector2Str(_bulletAcceleration), "string");
  579. node.AddChild(paramNode);
  580. paramNode = WriteParamNode("bulletAccelerationTime", _bulletAccelerationTime.ToString(), "string");
  581. node.AddChild(paramNode);
  582. paramNode = WriteParamNode("bulletTargetLink", _bulletTargetLink, "string");
  583. if(paramNode!=null)
  584. node.AddChild(paramNode);
  585. paramNode = WriteParamNode("range", StringUtil.ConvertVector2Str(_range), "string");
  586. node.AddChild(paramNode);
  587. paramNode = WriteParamNode("hiteffect", _hitEffectId.ToString(), "int");
  588. node.AddChild(paramNode);
  589. if(_hitEffectPrefab!=null)
  590. {
  591. #if UNITY_EDITOR
  592. paramNode = WriteParamNode("hitEffectPrefab", UnityEditor.AssetDatabase.GetAssetPath(_hitEffectPrefab), "string");
  593. node.AddChild(paramNode);
  594. #endif
  595. }
  596. paramNode = WriteParamNode("hitEffectLink", _hitEffectLink, "string");
  597. if (paramNode != null)
  598. node.AddChild(paramNode);
  599. if (_soundClip != null)
  600. {
  601. #if UNITY_EDITOR
  602. string audioPath = UnityEditor.AssetDatabase.GetAssetPath(_soundClip);
  603. string relativeName = FileUtils.RemoveParent(Constants.FightAudioPath, audioPath);
  604. paramNode = WriteParamNode("sound", relativeName, "string");
  605. node.AddChild(paramNode);
  606. paramNode = WriteParamNode("soundPath", audioPath, "string");
  607. node.AddChild(paramNode);
  608. #endif
  609. }
  610. paramNode = WriteParamNode("buffid", _triggerBuffId.ToString(), "int");
  611. node.AddChild(paramNode);
  612. paramNode = WriteParamNode("rate", _triggerBuffRate.ToString(), "int");
  613. node.AddChild(paramNode);
  614. paramNode = WriteParamNode("moveType", _moveType.ToString(), "int");
  615. node.AddChild(paramNode);
  616. paramNode = WriteParamNode("initSpeed", ((int)(_initSpeed * 100)).ToString(), "int");
  617. node.AddChild(paramNode);
  618. paramNode = WriteParamNode("acceleration", ((int)(_acceleration * 100)).ToString(), "int");
  619. node.AddChild(paramNode);
  620. paramNode = WriteParamNode("moveDist", ((int)(_moveDistance * 100)).ToString(), "int");
  621. node.AddChild(paramNode);
  622. return node;
  623. }
  624. public override void LoadFromXml(SecurityElement eventNode)
  625. {
  626. base.LoadFromXml(eventNode);
  627. _bulletId = GetNParam("bulletid");
  628. string bulletPrefab = GetSParam("bulletPrefab");
  629. if(!string.IsNullOrEmpty(bulletPrefab))
  630. {
  631. #if UNITY_EDITOR
  632. _bulletPrefab = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(bulletPrefab);
  633. #endif
  634. }
  635. _bulletLink = GetSParam("bulletLink");
  636. _bulletTargetLink = GetSParam("bulletTargetLink");
  637. _bulletFlyDuration = GetFParam("bulletFlyDuration");
  638. _bulletInitVelocity = GetVParam("bulletInitVelocity");
  639. _bulletAcceleration = GetVParam("bulletAcceleration");
  640. _bulletAccelerationTime = GetFParam("bulletAccelerationTime");
  641. _range = GetVParam("range");
  642. _hitEffectId = GetNParam("hiteffect");
  643. string hitEffectPrefab = GetSParam("hitEffectPrefab");
  644. if(!string.IsNullOrEmpty(hitEffectPrefab))
  645. {
  646. #if UNITY_EDITOR
  647. _hitEffectPrefab = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(hitEffectPrefab);
  648. #endif
  649. }
  650. _hitEffectLink = GetSParam("hitEffectLink");
  651. string soundPath = GetSParam("soundPath");
  652. if (!string.IsNullOrEmpty(soundPath))
  653. {
  654. #if UNITY_EDITOR
  655. _soundClip = UnityEditor.AssetDatabase.LoadAssetAtPath<AudioClip>(soundPath);
  656. #endif
  657. }
  658. _triggerBuffId = GetNParam("buffid");
  659. _triggerBuffRate = GetNParam("rate");
  660. _moveType = GetNParam("moveType");
  661. _initSpeed = GetNParam("initSpeed") * 0.01f;
  662. _acceleration = GetNParam("acceleration") * 0.01f;
  663. _moveDistance = GetNParam("moveDist") * 0.01f;
  664. }
  665. }
  666. }