Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace FrooxEngine
- {
- [GenericTypes(GenericTypes.Group.NeosPrimitives)]
- [Category("Transform/Interaction")]
- public class TouchValueOption<T> : Component, ITouchable
- {
- public readonly RelayRef<IField<T>> Target;
- public readonly Sync<T> Value;
- public readonly FieldDrive<bool> ActiveIndicator;
- public readonly FieldDrive<bool> HoverIndicator;
- public readonly Sync<VibratePreset> HoverVibrate;
- public readonly Sync<VibratePreset> Vibrate;
- public readonly Sync<bool> SetOnTouchBegin;
- public readonly Sync<bool> SetOnTouchStay;
- public readonly Sync<bool> SetOnTouchEnd;
- public readonly Sync<bool> AcceptOutOfSightTouch;
- public readonly Sync<bool> AcceptPhysicalTouch;
- public readonly Sync<bool> AcceptRemoteTouch;
- protected override void OnAwake()
- {
- Vibrate.Value = VibratePreset.Medium;
- HoverVibrate.Value = VibratePreset.Short;
- SetOnTouchBegin.Value = true;
- AcceptPhysicalTouch.Value = true;
- AcceptRemoteTouch.Value = true;
- }
- public bool CanTouchOutOfSight => AcceptOutOfSightTouch;
- public bool CanTouchInteract(Component touchSource) => true;
- public void OnTouch(TouchEventInfo eventInfo)
- {
- if (Target.Target == null)
- return;
- if (Coder<T>.Equals(Target.Target.Value, Value.Value))
- return;
- if (eventInfo.type == TouchType.Physical && !AcceptPhysicalTouch)
- return;
- if (eventInfo.type == TouchType.Remote && !AcceptRemoteTouch)
- return;
- if (eventInfo.hover == EventState.Begin)
- eventInfo.source?.Slot.TryVibrate(HoverVibrate);
- if (HoverIndicator.Target != null)
- {
- if (eventInfo.hover == EventState.Begin || eventInfo.hover == EventState.Stay)
- HoverIndicator.Target.Value = true;
- else if (eventInfo.hover == EventState.End)
- HoverIndicator.Target.Value = false;
- }
- bool set = false;
- if(SetOnTouchBegin && eventInfo.touch == EventState.Begin)
- {
- Target.Target.Value = Value;
- set = true;
- }
- if (SetOnTouchStay && eventInfo.touch == EventState.Stay)
- {
- Target.Target.Value = Value;
- set = true;
- }
- if (SetOnTouchEnd && eventInfo.touch == EventState.End)
- {
- Target.Target.Value = Value;
- set = true;
- }
- if (set)
- eventInfo.source?.Slot.TryVibrate(Vibrate);
- }
- protected override void OnChanges()
- {
- if (ActiveIndicator.IsLinkValid)
- ActiveIndicator.Target.Value = Target.Target != null &&
- Coder<T>.Equals(Target.Target.Value, Value.Value);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement