ArrowSync.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using DG.Tweening;
  5. public class ArrowSync : MonoBehaviour
  6. {
  7. void Awake()
  8. {
  9. this.transform.Find("Head/_hunse_jian").gameObject.layer = 0;
  10. }
  11. void Update()
  12. {
  13. transform.position = Vector3.Lerp(transform.position, position, Time.deltaTime * 15);
  14. Head().position = transform.position;
  15. transform.rotation = Quaternion.Lerp(transform.rotation, rotation, Time.deltaTime * 15);
  16. }
  17. public Transform Head() {
  18. return transform.Find("Head");
  19. }
  20. #region ---------箭矢特效---------
  21. public void activeEffectCyclone(bool value)
  22. {
  23. this.transform.Find("Head/EF_kuosanquan").gameObject.SetActive(value);
  24. if (!value) return;
  25. ParticleSystemRenderer ps = this.transform.Find("Head/EF_kuosanquan/kuosan").GetComponent<ParticleSystemRenderer>();
  26. ParticleSystemRenderer ps1 = this.transform.Find("Head/EF_kuosanquan/kuosan (1)").GetComponent<ParticleSystemRenderer>();
  27. DOTween.To(() => ps.minParticleSize, value => {
  28. ps.minParticleSize = value;
  29. ps.maxParticleSize = value;
  30. }, 0.4f, 0.6f);
  31. DOTween.To(() => ps1.minParticleSize, value => {
  32. ps1.minParticleSize = value;
  33. ps1.maxParticleSize = value;
  34. }, 0.8f, 0.6f);
  35. }
  36. void activeEffectBomb(bool value)
  37. {
  38. this.transform.Find("Head/EF_baodian").gameObject.SetActive(value);
  39. }
  40. void activeEffectTrail(bool value)
  41. {
  42. this.transform.Find("EF_tuowei").gameObject.SetActive(value);
  43. this.transform.Find("EF_tuowei/Trail").GetComponent<TrailRenderer>().time = 1.6f / mySpeed;
  44. }
  45. #endregion
  46. Quaternion rotation;
  47. Vector3 position;
  48. float mySpeed;
  49. bool hasPlayHitAudio = false;
  50. bool hasPlayHitEffect = false;
  51. [System.NonSerialized] public bool isHit;
  52. [System.NonSerialized] public bool canUseSideCamera;
  53. [System.NonSerialized] public bool hasSetSyncData = false; //外部运算用的
  54. public void SetSyncData(SyncData syncData, bool apply = false) {
  55. rotation.x = syncData.rx;
  56. rotation.y = syncData.ry;
  57. rotation.z = syncData.rz;
  58. rotation.w = syncData.rw;
  59. position.x = syncData.px;
  60. position.y = syncData.py;
  61. position.z = syncData.pz;
  62. canUseSideCamera = syncData.cs;
  63. isHit = syncData.ih;
  64. mySpeed = syncData.sp;
  65. if (apply) {
  66. transform.position = position;
  67. transform.rotation = rotation;
  68. if (!isHit) {
  69. //激活镜头
  70. Transform cameraTF = this.transform.Find("Camera");
  71. cameraTF.gameObject.SetActive(true);
  72. ArrowCamera arrowCameraComp = cameraTF.gameObject.AddComponent<ArrowCamera>();
  73. arrowCameraComp.SetArrowSync(this);
  74. //射出的声音
  75. AudioMgr.ins.PlayShoot(AudioMgr.GetAudioSource(this.gameObject));
  76. //拖尾
  77. activeEffectTrail(true);
  78. }
  79. else if (isHit) {
  80. hasPlayHitAudio = true;
  81. hasPlayHitEffect = true;
  82. activeEffectCyclone(false);
  83. activeEffectTrail(false);
  84. }
  85. }
  86. if (isHit && !hasPlayHitAudio) {
  87. hasPlayHitAudio = true;
  88. int hitType = syncData.ht;
  89. if (hitType == 1 || hitType == 2) {
  90. AudioMgr.ins.PlayHit(AudioMgr.GetAudioSource(TargetBody.ins.gameObject));
  91. AudioMgr.ins.PlayCheer(hitType == 1 ? true : false);
  92. } else if (hitType == 4 || hitType == 5) {
  93. AudioMgr.ins.PlayArrowEnter();
  94. } else if (hitType == 3) {
  95. AudioMgr.ins.PlayCheer(false);
  96. }
  97. }
  98. if (isHit && !hasPlayHitEffect) {
  99. hasPlayHitEffect = true;
  100. activeEffectBomb(true);
  101. activeEffectCyclone(false);
  102. activeEffectTrail(false);
  103. }
  104. }
  105. public class SyncData {
  106. [System.NonSerialized] public bool inited;
  107. static int autoID;
  108. public int id;
  109. public float rx;
  110. public float ry;
  111. public float rz;
  112. public float rw;
  113. public float px;
  114. public float py;
  115. public float pz;
  116. public bool cs;
  117. public bool ih;
  118. public int ht;
  119. public float sp;
  120. public void SetData(Arrow arrow) {
  121. Quaternion r = arrow.transform.rotation;
  122. Vector3 p = arrow.Head().transform.position;
  123. rx = r.x;
  124. ry = r.y;
  125. rz = r.z;
  126. rw = r.w;
  127. px = p.x;
  128. py = p.y;
  129. pz = p.z;
  130. cs = arrow.canUseSideCamera;
  131. ih = arrow.isHit;
  132. ht = arrow.hitType;
  133. sp = arrow.mySpeed;
  134. if (!inited) {
  135. id = autoID++;
  136. if (autoID > 1000) autoID = 0;
  137. }
  138. inited = true;
  139. }
  140. }
  141. }