public void Subscribe(string topic, GameObject parent) { if (!this.attachables.ContainsKey(topic)) { Debug.Log($"Subscribing {parent.name} to topic {topic}"); var visuals = parent.transform.Find("Visuals"); if (visuals != null) { var c = visuals.GetComponentsInChildren <Renderer>(); parent = c[0].gameObject; } ; // modify the parent's interactability (collision with the pointer) parent.GetComponent <Renderer>().material = activeMaterial; NearInteractionTouchable touchable = parent.AddComponent <NearInteractionTouchable>(); BoxCollider collider = parent.AddComponent <BoxCollider>(); touchable.SetTouchableCollider(collider); // instanciate an interactable that processes all kinds of events to the respective function. Interactable interactable = attachInteractible(topic, parent); PressableButton button = parent.AddComponent <PressableButton>(); // route physical presses to the interactable PhysicalPressEventRouter physicalEvents = parent.AddComponent <PhysicalPressEventRouter>(); physicalEvents.routingTarget = interactable; // create the 3d component GameObject attachable = Instantiate <GameObject>(this.externalPlotPrefab); ToolTipController toolTipController = attachable.GetComponent <ToolTipController>(); toolTipController.Topic = topic; var texture = attachable.AddComponent <TextureProvider>(); texture.InitRosSource(topic, toolTipController.ImageRenderer); ExternalPlot eplot = attachable.GetComponent <ExternalPlot>(); eplot.ToolTipText = topic; eplot.FontSize = 20; ExternalPlotConnector con = attachable.GetComponent <ExternalPlotConnector>(); con.Target = parent; attachable.transform.SetParent(this.attachablesRoot.transform); Vector3 offset = new Vector3(0.0f, 0.1f, 0.0f); attachable.transform.position = parent.transform.position + offset; // create the reference object AttachableReference aref; aref.attachable = attachable; aref.parent = parent; aref.active = true; aref.following = false; this.attachables.Add(topic, aref); } else { this.Show(topic); } }
/// <inheritdoc/> protected override void Start() { this.slateDecorator = new HoloGraphic(this.materialComponent.Material); if (!Application.Current.IsEditor) { this.nearInteractionTouchable = this.Owner.GetOrAddComponent <NearInteractionTouchable>(); this.soundEmitter = this.Owner.GetOrAddComponent <SoundEmitter3D>(); this.Owner.GetOrAddComponent <StaticBody3D>(); this.Owner.GetInChildrenOrAddComponent <BoxCollider3D>(); } }
public IEnumerator NearInteractionTouchableOverlapQuerySaturation() { // Use all the points int numTouchables = NumRandomPoints; var touchables = new NearInteractionTouchable[numTouchables]; var catchers = new TouchEventCatcher[numTouchables]; // Spread out touchables over a radius, decrease over time to increase density and fill the buffer float radiusStart = 1.0f; float radiusEnd = 0.01f; for (int i = 0; i < numTouchables; ++i) { Vector3 r = GetRandomPoint(i); touchables[i] = CreateTouchable <NearInteractionTouchable>(0.15f); touchables[i].SetLocalForward(touchNormal); touchables[i].SetBounds(new Vector2(0.5f, 0.5f)); touchables[i].transform.position = objectPosition + r * radiusStart; catchers[i] = CreateTouchEventCatcher(touchables[i]); } yield return(new WaitForFixedUpdate()); yield return(null); yield return(PlayModeTestUtilities.ShowHand(Handedness.Right, inputSim)); yield return(PlayModeTestUtilities.MoveHand(initialHandPosition, objectPosition, ArticulatedHandPose.GestureId.Open, Handedness.Right, inputSim, 1)); for (int i = 0; i < PlayModeTestUtilities.ControllerMoveSteps; ++i) { float scale = radiusStart + (radiusEnd - radiusStart) * (i + 1) / PlayModeTestUtilities.ControllerMoveSteps; for (int j = 0; j < numTouchables; ++j) { Vector3 r = GetRandomPoint(j + 10); touchables[j].transform.position = objectPosition + r * scale; } yield return(null); } yield return(PlayModeTestUtilities.HideHand(Handedness.Right, inputSim)); foreach (NearInteractionTouchable touchable in touchables) { Object.Destroy(touchable.gameObject); } }
public IEnumerator NearInteractionTouchableStack() { // Ignoring this test for now, as it needs fixing Assert.Ignore(); int numTouchables = 10; var touchables = new NearInteractionTouchable[numTouchables]; var catchers = new TouchEventCatcher[numTouchables]; for (int i = 0; i < numTouchables; ++i) { Vector3 r = GetRandomPoint(i); touchables[i] = CreateTouchable <NearInteractionTouchable>(0.15f); touchables[i].SetLocalForward(touchNormal); touchables[i].SetBounds(new Vector2(0.5f, 0.5f)); touchables[i].transform.position = objectPosition + new Vector3(0.02f * r.x, 0.015f * r.y, 0.1f * i - 0.5f); catchers[i] = CreateTouchEventCatcher(touchables[i]); } yield return(new WaitForFixedUpdate()); yield return(null); yield return(PlayModeTestUtilities.ShowHand(Handedness.Right, inputSim)); yield return(PlayModeTestUtilities.MoveHand(initialHandPosition, objectPosition, ArticulatedHandPose.GestureId.Open, Handedness.Right, inputSim)); // No. 0 is touched initially TestEvents(catchers, new int[] { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, new int[] { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }); yield return(PlayModeTestUtilities.MoveHand(objectPosition, rightPosition, ArticulatedHandPose.GestureId.Pinch, Handedness.Right, inputSim)); // Only No. 3 gets touched when moving through the row, because No. 0 is still active while inside the poke threshold TestEvents(catchers, new int[] { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, new int[] { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0 }); yield return(PlayModeTestUtilities.MoveHand(rightPosition, objectPosition, ArticulatedHandPose.GestureId.Pinch, Handedness.Right, inputSim)); // No. 3 touched a second time TestEvents(catchers, new int[] { 1, 0, 0, 2, 0, 0, 0, 0, 0, 0 }, new int[] { 1, 0, 0, 2, 0, 0, 0, 0, 0, 0 }); yield return(PlayModeTestUtilities.HideHand(Handedness.Right, inputSim)); foreach (NearInteractionTouchable touchable in touchables) { Object.Destroy(touchable.gameObject); } }
public IEnumerator TestHandInputOnRuntimeAssembled() { // Load interactable Interactable interactable; Transform translateTargetObject; AssembleInteractableButton( out interactable, out translateTargetObject); interactable.transform.position = new Vector3(0.025f, 0.05f, 0.65f); interactable.transform.eulerAngles = new Vector3(-90f, 0f, 0f); // Subscribe to interactable's on click so we know the click went through bool wasClicked = false; interactable.OnClick.AddListener(() => { wasClicked = true; }); Vector3 targetStartPosition = translateTargetObject.transform.localPosition; yield return(null); // Add a touchable and configure for touch events NearInteractionTouchable touchable = interactable.gameObject.AddComponent <NearInteractionTouchable>(); touchable.EventsToReceive = TouchableEventType.Touch; touchable.SetBounds(Vector2.one); touchable.SetLocalForward(Vector3.up); touchable.SetLocalUp(Vector3.forward); touchable.SetLocalCenter(Vector3.up * 2.75f); // Add a touch handler and link touch started / touch completed events TouchHandler touchHandler = interactable.gameObject.AddComponent <TouchHandler>(); touchHandler.OnTouchStarted.AddListener((HandTrackingInputEventData e) => interactable.SetInputDown()); touchHandler.OnTouchCompleted.AddListener((HandTrackingInputEventData e) => interactable.SetInputUp()); yield return(TestClickPushButton(targetStartPosition, translateTargetObject)); Assert.True(wasClicked, "Interactable was not clicked."); //Cleanup GameObject.Destroy(interactable.gameObject); }
private void OnEnable() { button = (PressableButton)target; transform = button.transform; touchCage = button.GetComponent <BoxCollider>(); if (labelStyle == null) { labelStyle = new GUIStyle(); labelStyle.normal.textColor = Color.white; } startPushDistance = serializedObject.FindProperty("startPushDistance"); maxPushDistance = serializedObject.FindProperty("maxPushDistance"); pressDistance = serializedObject.FindProperty("pressDistance"); releaseDistanceDelta = serializedObject.FindProperty("releaseDistanceDelta"); movingButtonVisuals = serializedObject.FindProperty("movingButtonVisuals"); touchable = button.GetComponent <NearInteractionTouchable>(); }
public IEnumerator TestSimulatedHandInputOnRuntimeAssembled() { // Load interactable prefab GameObject interactableObject; Interactable interactable; Transform translateTargetObject; AssembleInteractableButton( out interactableObject, out interactable, out translateTargetObject); interactableObject.transform.position = new Vector3(0.025f, 0.05f, 0.65f); interactableObject.transform.eulerAngles = new Vector3(-90f, 0f, 0f); // Subscribe to interactable's on click so we know the click went through bool wasClicked = false; interactable.OnClick.AddListener(() => { wasClicked = true; }); Vector3 targetStartPosition = translateTargetObject.transform.localPosition; yield return(null); // Add a touchable and configure for touch events NearInteractionTouchable touchable = interactableObject.AddComponent <NearInteractionTouchable>(); touchable.EventsToReceive = TouchableEventType.Touch; touchable.Bounds = Vector2.one; touchable.SetLocalForward(Vector3.up); touchable.SetLocalUp(Vector3.forward); touchable.LocalCenter = Vector3.up * 2.75f; // Add a touch handler and link touch started / touch completed events TouchHandler touchHandler = interactableObject.AddComponent <TouchHandler>(); touchHandler.OnTouchStarted.AddListener((HandTrackingInputEventData e) => interactable.SetInputDown()); touchHandler.OnTouchCompleted.AddListener((HandTrackingInputEventData e) => interactable.SetInputUp()); // Move the hand forward to intersect the interactable var inputSimulationService = PlayModeTestUtilities.GetInputSimulationService(); int numSteps = 32; Vector3 p1 = new Vector3(0.0f, 0f, 0f); Vector3 p2 = new Vector3(0.05f, 0f, 0.51f); Vector3 p3 = new Vector3(0.0f, 0f, 0.0f); yield return(PlayModeTestUtilities.ShowHand(Handedness.Right, inputSimulationService)); yield return(PlayModeTestUtilities.MoveHandFromTo(p1, p2, numSteps, ArticulatedHandPose.GestureId.Poke, Handedness.Right, inputSimulationService)); float pressStartTime = Time.time; bool wasTranslated = false; while (Time.time < pressStartTime + buttonPressAnimationDelay) { // If the transform is moved at any point during this interval, we were successful yield return(new WaitForFixedUpdate()); wasTranslated |= targetStartPosition != translateTargetObject.localPosition; } // Move the hand back yield return(PlayModeTestUtilities.MoveHandFromTo(p2, p3, numSteps, ArticulatedHandPose.GestureId.Poke, Handedness.Right, inputSimulationService)); yield return(PlayModeTestUtilities.HideHand(Handedness.Right, inputSimulationService)); yield return(new WaitForSeconds(buttonReleaseAnimationDelay)); Assert.True(wasClicked, "Interactable was not clicked."); Assert.True(wasTranslated, "Transform target object was not translated by action."); }
public IEnumerator TestHandInputOnRuntimeAssembled() { // Load interactable Interactable interactable; Transform translateTargetObject; AssembleInteractableButton( out interactable, out translateTargetObject); interactable.transform.position = new Vector3(0.025f, 0.05f, 0.65f); interactable.transform.eulerAngles = new Vector3(-90f, 0f, 0f); // Subscribe to interactable's on click so we know the click went through bool wasClicked = false; interactable.OnClick.AddListener(() => { wasClicked = true; }); Vector3 targetStartPosition = translateTargetObject.transform.localPosition; yield return(null); // Add a touchable and configure for touch events NearInteractionTouchable touchable = interactable.gameObject.AddComponent <NearInteractionTouchable>(); touchable.EventsToReceive = TouchableEventType.Touch; touchable.SetBounds(Vector2.one); touchable.SetLocalForward(Vector3.up); touchable.SetLocalUp(Vector3.forward); touchable.SetLocalCenter(Vector3.up * 2.75f); // Add a touch handler and link touch started / touch completed events TouchHandler touchHandler = interactable.gameObject.AddComponent <TouchHandler>(); touchHandler.OnTouchStarted.AddListener((HandTrackingInputEventData e) => interactable.SetInputDown()); touchHandler.OnTouchCompleted.AddListener((HandTrackingInputEventData e) => interactable.SetInputUp()); // Move the hand forward to intersect the interactable var inputSimulationService = PlayModeTestUtilities.GetInputSimulationService(); int numSteps = 32; Vector3 p1 = Vector3.zero; Vector3 p2 = new Vector3(0.05f, 0f, 0.51f); Vector3 p3 = Vector3.zero; yield return(PlayModeTestUtilities.ShowHand(Handedness.Right, inputSimulationService)); yield return(PlayModeTestUtilities.MoveHandFromTo(p1, p2, numSteps, ArticulatedHandPose.GestureId.Poke, Handedness.Right, inputSimulationService)); yield return(CheckButtonTranslation(targetStartPosition, translateTargetObject)); // Move the hand back yield return(PlayModeTestUtilities.MoveHandFromTo(p2, p3, numSteps, ArticulatedHandPose.GestureId.Poke, Handedness.Right, inputSimulationService)); yield return(PlayModeTestUtilities.HideHand(Handedness.Right, inputSimulationService)); yield return(new WaitForSeconds(ButtonReleaseAnimationDelay)); Assert.True(wasClicked, "Interactable was not clicked."); //Cleanup GameObject.Destroy(interactable.gameObject); }