ArrowSync.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class ArrowSync : MonoBehaviour
  5. {
  6. void Awake()
  7. {
  8. this.transform.Find("Head/_hunse_jian").gameObject.layer = 0;
  9. }
  10. void Update()
  11. {
  12. transform.position = Vector3.Lerp(transform.position, position, Time.deltaTime * 15);
  13. Head().position = transform.position;
  14. transform.rotation = Quaternion.Lerp(transform.rotation, rotation, Time.deltaTime * 15);
  15. }
  16. public Transform Head() {
  17. return transform.Find("Head");
  18. }
  19. Quaternion rotation;
  20. Vector3 position;
  21. [System.NonSerialized] public bool isHit;
  22. [System.NonSerialized] public bool canUseSideCamera;
  23. [System.NonSerialized] public bool hasSetSyncData = false; //外部运算用的
  24. public void SetSyncData(SyncData syncData, bool apply = false) {
  25. rotation.x = syncData.rx;
  26. rotation.y = syncData.ry;
  27. rotation.z = syncData.rz;
  28. rotation.w = syncData.rw;
  29. position.x = syncData.px;
  30. position.y = syncData.py;
  31. position.z = syncData.pz;
  32. canUseSideCamera = syncData.cs;
  33. isHit = syncData.ih;
  34. if (apply) {
  35. transform.position = position;
  36. transform.rotation = rotation;
  37. //激活镜头
  38. Transform cameraTF = this.transform.Find("Camera");
  39. cameraTF.gameObject.SetActive(true);
  40. ArrowCamera arrowCameraComp = cameraTF.gameObject.AddComponent<ArrowCamera>();
  41. arrowCameraComp.SetArrowSync(this);
  42. //射出的声音
  43. AudioMgr.ins.PlayShoot(AudioMgr.GetAudioSource(this.gameObject));
  44. }
  45. }
  46. public class SyncData {
  47. [System.NonSerialized] public bool inited;
  48. static int autoID;
  49. public int id;
  50. public float rx;
  51. public float ry;
  52. public float rz;
  53. public float rw;
  54. public float px;
  55. public float py;
  56. public float pz;
  57. public bool cs;
  58. public bool ih;
  59. public void SetData(Arrow arrow) {
  60. Quaternion r = arrow.transform.rotation;
  61. Vector3 p = arrow.Head().transform.position;
  62. rx = r.x;
  63. ry = r.y;
  64. rz = r.z;
  65. rw = r.w;
  66. px = p.x;
  67. py = p.y;
  68. pz = p.z;
  69. cs = arrow.canUseSideCamera;
  70. ih = arrow.isHit;
  71. if (!inited) {
  72. id = autoID++;
  73. if (autoID > 1000) autoID = 0;
  74. }
  75. inited = true;
  76. }
  77. }
  78. }