JD_Controller_Example.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. /// <summary>
  5. /// 胶带控制案例
  6. /// </summary>
  7. public class JD_Controller_Example : MonoBehaviour
  8. {
  9. public ChivaVR_JD_ShaderController[] controllers;
  10. // Update is called once per frame
  11. void Update()
  12. {
  13. if (Input.GetKeyDown(KeyCode.Z))
  14. {
  15. SetJDType(JDLineType.lineoff);
  16. }
  17. if (Input.GetKeyDown(KeyCode.X))
  18. {
  19. SetJDType(JDLineType.lineon_JDJuan);
  20. }
  21. if (Input.GetKeyDown(KeyCode.C))
  22. {
  23. SetJDType(JDLineType.lineon_NoJDJuan);
  24. }
  25. SetJDAngle(Input.GetAxis("Horizontal"));
  26. SetJDDirectionAngle(Input.GetAxis("Vertical"));
  27. }
  28. /// <summary>
  29. /// 设置胶带类型
  30. /// </summary>
  31. /// <param name="type"></param>
  32. public void SetJDType(JDLineType type)
  33. {
  34. foreach (var item in controllers)
  35. {
  36. item.SetJDLineType(type);
  37. }
  38. }
  39. /// <summary>
  40. /// 设置胶带缠绕角度
  41. /// </summary>
  42. /// <param name="delta"></param>
  43. public void SetJDAngle(float delta)
  44. {
  45. foreach (var item in controllers)
  46. {
  47. //可直接设置目标角度
  48. item.SetJDValue((item.value + delta));
  49. }
  50. }
  51. /// <summary>
  52. /// 伸出部分旋转角度
  53. /// </summary>
  54. /// <param name="delta"></param>
  55. public void SetJDDirectionAngle(float delta)
  56. {
  57. foreach (var item in controllers)
  58. {
  59. item.SetJDDirectionAngle((item.backAngle + delta));
  60. }
  61. }
  62. }