Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace FrooxEngine
  8. {
  9. [GenericTypes(GenericTypes.Group.NeosPrimitives)]
  10. [Category("Transform/Interaction")]
  11. public class TouchValueOption<T> : Component, ITouchable
  12. {
  13. public readonly RelayRef<IField<T>> Target;
  14. public readonly Sync<T> Value;
  15.  
  16. public readonly FieldDrive<bool> ActiveIndicator;
  17. public readonly FieldDrive<bool> HoverIndicator;
  18.  
  19. public readonly Sync<VibratePreset> HoverVibrate;
  20. public readonly Sync<VibratePreset> Vibrate;
  21.  
  22. public readonly Sync<bool> SetOnTouchBegin;
  23. public readonly Sync<bool> SetOnTouchStay;
  24. public readonly Sync<bool> SetOnTouchEnd;
  25.  
  26. public readonly Sync<bool> AcceptOutOfSightTouch;
  27.  
  28. public readonly Sync<bool> AcceptPhysicalTouch;
  29. public readonly Sync<bool> AcceptRemoteTouch;
  30.  
  31. protected override void OnAwake()
  32. {
  33. Vibrate.Value = VibratePreset.Medium;
  34. HoverVibrate.Value = VibratePreset.Short;
  35. SetOnTouchBegin.Value = true;
  36.  
  37. AcceptPhysicalTouch.Value = true;
  38. AcceptRemoteTouch.Value = true;
  39. }
  40.  
  41. public bool CanTouchOutOfSight => AcceptOutOfSightTouch;
  42. public bool CanTouchInteract(Component touchSource) => true;
  43.  
  44. public void OnTouch(TouchEventInfo eventInfo)
  45. {
  46. if (Target.Target == null)
  47. return;
  48.  
  49. if (Coder<T>.Equals(Target.Target.Value, Value.Value))
  50. return;
  51.  
  52. if (eventInfo.type == TouchType.Physical && !AcceptPhysicalTouch)
  53. return;
  54.  
  55. if (eventInfo.type == TouchType.Remote && !AcceptRemoteTouch)
  56. return;
  57.  
  58. if (eventInfo.hover == EventState.Begin)
  59. eventInfo.source?.Slot.TryVibrate(HoverVibrate);
  60.  
  61. if (HoverIndicator.Target != null)
  62. {
  63. if (eventInfo.hover == EventState.Begin || eventInfo.hover == EventState.Stay)
  64. HoverIndicator.Target.Value = true;
  65. else if (eventInfo.hover == EventState.End)
  66. HoverIndicator.Target.Value = false;
  67. }
  68.  
  69. bool set = false;
  70.  
  71. if(SetOnTouchBegin && eventInfo.touch == EventState.Begin)
  72. {
  73. Target.Target.Value = Value;
  74. set = true;
  75. }
  76.  
  77. if (SetOnTouchStay && eventInfo.touch == EventState.Stay)
  78. {
  79. Target.Target.Value = Value;
  80. set = true;
  81. }
  82.  
  83. if (SetOnTouchEnd && eventInfo.touch == EventState.End)
  84. {
  85. Target.Target.Value = Value;
  86. set = true;
  87. }
  88.  
  89. if (set)
  90. eventInfo.source?.Slot.TryVibrate(Vibrate);
  91. }
  92.  
  93. protected override void OnChanges()
  94. {
  95. if (ActiveIndicator.IsLinkValid)
  96. ActiveIndicator.Target.Value = Target.Target != null &&
  97. Coder<T>.Equals(Target.Target.Value, Value.Value);
  98. }
  99.  
  100.  
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement