HeadDevicePartManipulation.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using SC.XR.Unity.Module_InputSystem;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using UnityEngine;
  7. public class HeadDevicePartManipulation : AbstractDevicePartManipulation
  8. {
  9. private SCPointEventData eventData;
  10. private SCPose pointerPose;
  11. private Quaternion startRotation;
  12. private Quaternion localRotationInHead;
  13. public override void OneDevicePartInit(ManipulationHandler manipulationHandler, Dictionary<InputDevicePartType, SCPointEventData> eventDataDic, Transform targetTransform, MoveLogic moveLogic, RotateLogic rotateLogic, ScaleLogic scaleLogic)
  14. {
  15. base.OneDevicePartInit(manipulationHandler, eventDataDic, targetTransform, moveLogic, rotateLogic, scaleLogic);
  16. this.eventData = this.eventDataDic.Values.ToArray()[0];
  17. pointerPose = new SCPose(Vector3.zero, Quaternion.identity);
  18. Vector3 grabPosition = Vector3.zero;
  19. pointerPose.position = this.eventData.Position3D;
  20. pointerPose.rotation = Quaternion.identity;
  21. grabPosition = this.eventData.Position3D;
  22. startRotation = targetTransform.rotation;
  23. localRotationInHead = Quaternion.Inverse(Camera.main.transform.rotation) * startRotation;
  24. //Head only need to setup movelogic
  25. moveLogic.Setup(pointerPose, grabPosition, targetTransform, targetTransform.localScale);
  26. }
  27. public override Tuple<Vector3, Quaternion, Vector3> OneDevicePartUpdate()
  28. {
  29. pointerPose.position = this.eventData.Position3D;
  30. pointerPose.rotation = startRotation;//Quaternion.identity;
  31. Quaternion rotation = targetTransform.rotation;
  32. if (manipulationHandler.headRotate)
  33. {
  34. rotation = Camera.main.transform.transform.rotation * localRotationInHead;
  35. }
  36. Vector3 position = moveLogic.Update(pointerPose, rotation, targetTransform.localScale, true);
  37. return new Tuple<Vector3, Quaternion, Vector3>(position, rotation, targetTransform.localScale);
  38. }
  39. public override void TwoDevicePartInit(ManipulationHandler manipulationHandler, Dictionary<InputDevicePartType, SCPointEventData> eventDataDic, Transform targetTransform, MoveLogic moveLogic, RotateLogic rotateLogic, ScaleLogic scaleLogic)
  40. {
  41. base.TwoDevicePartInit(manipulationHandler, eventDataDic, targetTransform, moveLogic, rotateLogic, scaleLogic);
  42. //Do nothing
  43. }
  44. public override Tuple<Vector3, Quaternion, Vector3> TwoDevicePartUpdate(Func<Vector3, Vector3> scaleConstraint)
  45. {
  46. //Do nothing
  47. return new Tuple<Vector3, Quaternion, Vector3>(Vector3.zero, Quaternion.identity, Vector3.one);
  48. }
  49. }