Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by ignasky52 · Mar 02, 2019 at 09:01 AM · vrtouchpad

Trying to switch between 4 different cameras using mixed reality touchpad,Switching Between Four Different Cameras Using Mixed Reality TouchPad

I'm trying to utilize the windows mixed reality controller's touch pad to switch between four different cameras. Thinking about the way the touch pad uses Unity Axis Value Range, I want to divide the pad into four sections. When the user's finger moves over the section they want they would be able to click it and switch to a different camera.

There is a color wheel switcher that transforms the touchpad's input around line 90 that I think may be the key, but I cannot wrap my head around it. Also Sorry if this is too much/ terribly formatted

Color Wheel Script:

/ Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information.

using HoloToolkit.Unity.Controllers; using HoloToolkit.Unity.InputModule; using UnityEngine;

UNITY_WSA && UNITY_2017_2_OR_NEWER using UnityEngine.XR.WSA.Input;

namespace HoloToolkit.Unity.ControllerExamples { public class ColorPickerWheel : AttachToController, IPointerTarget { public bool Visible { get { return visible; } set { visible = value; if (value) { lastTimeVisible = Time.unscaledTime; } } }

     public Color SelectedColor
     {
         get { return selectedColor; }
     }

     [Header("ColorPickerWheel Elements")]
     [SerializeField]
     private bool visible = false;
     [SerializeField]
     private Transform selectorTransform;
     [SerializeField]
     private Renderer selectorRenderer;
     [SerializeField]
     private float inputScale = 1.1f;
     [SerializeField]
     private Color selectedColor = Color.white;
     [SerializeField]
     private Texture2D colorWheelTexture;
     [SerializeField]
     private GameObject colorWheelObject;
     [SerializeField]
     private Animator animator;
     [SerializeField]
     private float timeout = 2f;

     private Vector2 selectorPosition;
     private float lastTimeVisible;
     private bool visibleLastFrame = false;

     private void Update()
     {

UNITY_WSA && UNITY_2017_2_OR_NEWER if (ControllerInfo == null) { return; }

         if (Time.unscaledTime > lastTimeVisible + timeout)
         {
             visible = false;
         }

         if (visible != visibleLastFrame)
         {
             // Based on visible property, it triggers Show and Hide animation triggers in the color picker's animator component
             if (visible)
             {
                 animator.SetTrigger("Show");
             }
             else
             {
                 animator.SetTrigger("Hide");
             }
         }
         visibleLastFrame = visible;

         if (!visible)
         {
             return;
         }

         // Transform the touchpad's input x, y position information to ColorPickerWheel's local position x, z
         Vector3 localPosition = new Vector3(selectorPosition.x * inputScale, 0.15f, selectorPosition.y * inputScale);
         if (localPosition.magnitude > 1)
         {
             localPosition = localPosition.normalized;
         }
         selectorTransform.localPosition = localPosition;

         // Raycast the wheel mesh and get its UV coordinates
         Vector3 raycastStart = selectorTransform.position + selectorTransform.up * 0.15f;
         RaycastHit hit;
         Debug.DrawLine(raycastStart, raycastStart - (selectorTransform.up * 0.25f));

         if (Physics.Raycast(raycastStart, -selectorTransform.up, out hit, 0.25f, 1 << colorWheelObject.layer, QueryTriggerInteraction.Ignore))
         {
             // Get pixel from the color wheel texture using UV coordinates
             Vector2 uv = hit.textureCoord;
             int pixelX = Mathf.FloorToInt(colorWheelTexture.width * uv.x);
             int pixelY = Mathf.FloorToInt(colorWheelTexture.height * uv.y);
             selectedColor = colorWheelTexture.GetPixel(pixelX, pixelY);
             selectedColor.a = 1f;
         }
         // Set the selector's color and blend it with white to make it visible on top of the wheel
         selectorRenderer.material.color = Color.Lerp(selectedColor, Color.white, 0.5f);

     }

     protected override void OnAttachToController()
     {

UNITY_WSA && UNITY_2017_2_OR_NEWER // Subscribe to input now that we're parented under the controller InteractionManager.InteractionSourceUpdated += InteractionSourceUpdated;

     }

     protected override void OnDetachFromController()
     {
         Visible = false;

UNITY_WSA && UNITY_2017_2_OR_NEWER // Unsubscribe from input now that we've detached from the controller InteractionManager.InteractionSourceUpdated -= InteractionSourceUpdated;

     }

     public void OnPointerTarget(PhysicsPointer source)
     {
         Visible = true;

         // If we're opening or closing, don't set the color value
         AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);
         if (stateInfo.IsName("Show") || stateInfo.IsName("Hide"))
         {
             return;
         }

         Vector3 localHitPoint = selectorTransform.parent.InverseTransformPoint(source.TargetPoint);
         selectorPosition = new Vector2(localHitPoint.x, localHitPoint.z);
     }

UNITY_WSA && UNITY_2017_2_OR_NEWER private void InteractionSourceUpdated(InteractionSourceUpdatedEventArgs obj) { // Check if it is a touchpadTouched event and from the left controller if (obj.state.source.handedness == Handedness && obj.state.touchpadTouched) { // If both are true, Visible is set to true and the touchpad position is assigned to selectorPosition. Visible = true; selectorPosition = obj.state.touchpadPosition; } }

 }

},I'm trying to utilize the windows mixed reality controller's touch pad to switch between four different cameras. Thinking about the way the touch pad uses Unity Axis Value Range, I want to divide the pad into four sections. When the user's finger moves over the section they want they would be able to click it and switch to a different camera.

There is a color wheel switcher that transforms the touchpad's input around line 90 that I think may be the key, but I cannot wrap my head around it.

Color Wheel Script: // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information.

using HoloToolkit.Unity.Controllers; using HoloToolkit.Unity.InputModule; using UnityEngine;

if UNITY_WSA && UNITY_2017_2_OR_NEWER

sing UnityEngine.XR.WSA.Input; #endif

namespace HoloToolkit.Unity.ControllerExamples { public class ColorPickerWheel : AttachToController, IPointerTarget { public bool Visible { get { return visible; } set { visible = value; if (value) { lastTimeVisible = Time.unscaledTime; } } }

     public Color SelectedColor
     {
         get { return selectedColor; }
     }

     [Header("ColorPickerWheel Elements")]
     [SerializeField]
     private bool visible = false;
     [SerializeField]
     private Transform selectorTransform;
     [SerializeField]
     private Renderer selectorRenderer;
     [SerializeField]
     private float inputScale = 1.1f;
     [SerializeField]
     private Color selectedColor = Color.white;
     [SerializeField]
     private Texture2D colorWheelTexture;
     [SerializeField]
     private GameObject colorWheelObject;
     [SerializeField]
     private Animator animator;
     [SerializeField]
     private float timeout = 2f;

     private Vector2 selectorPosition;
     private float lastTimeVisible;
     private bool visibleLastFrame = false;

     private void Update()
     {

if UNITY_WSA && UNITY_2017_2_OR_NEWER

        if (ControllerInfo == null)
         {
             return;
         }

         if (Time.unscaledTime > lastTimeVisible + timeout)
         {
             visible = false;
         }

         if (visible != visibleLastFrame)
         {
             // Based on visible property, it triggers Show and Hide animation triggers in the color picker's animator component
             if (visible)
             {
                 animator.SetTrigger("Show");
             }
             else
             {
                 animator.SetTrigger("Hide");
             }
         }
         visibleLastFrame = visible;

         if (!visible)
         {
             return;
         }

         // Transform the touchpad's input x, y position information to ColorPickerWheel's local position x, z
         Vector3 localPosition = new Vector3(selectorPosition.x * inputScale, 0.15f, selectorPosition.y * inputScale);
         if (localPosition.magnitude > 1)
         {
             localPosition = localPosition.normalized;
         }
         selectorTransform.localPosition = localPosition;

         // Raycast the wheel mesh and get its UV coordinates
         Vector3 raycastStart = selectorTransform.position + selectorTransform.up * 0.15f;
         RaycastHit hit;
         Debug.DrawLine(raycastStart, raycastStart - (selectorTransform.up * 0.25f));

         if (Physics.Raycast(raycastStart, -selectorTransform.up, out hit, 0.25f, 1 << colorWheelObject.layer, QueryTriggerInteraction.Ignore))
         {
             // Get pixel from the color wheel texture using UV coordinates
             Vector2 uv = hit.textureCoord;
             int pixelX = Mathf.FloorToInt(colorWheelTexture.width * uv.x);
             int pixelY = Mathf.FloorToInt(colorWheelTexture.height * uv.y);
             selectedColor = colorWheelTexture.GetPixel(pixelX, pixelY);
             selectedColor.a = 1f;
         }
         // Set the selector's color and blend it with white to make it visible on top of the wheel
         selectorRenderer.material.color = Color.Lerp(selectedColor, Color.white, 0.5f);

endif

    }

     protected override void OnAttachToController()
     {

if UNITY_WSA && UNITY_2017_2_OR_NEWER

        // Subscribe to input now that we're parented under the controller
         InteractionManager.InteractionSourceUpdated += InteractionSourceUpdated;

endif

    }

     protected override void OnDetachFromController()
     {
         Visible = false;

if UNITY_WSA && UNITY_2017_2_OR_NEWER

        // Unsubscribe from input now that we've detached from the controller
         InteractionManager.InteractionSourceUpdated -= InteractionSourceUpdated;

endif

    }

     public void OnPointerTarget(PhysicsPointer source)
     {
         Visible = true;

         // If we're opening or closing, don't set the color value
         AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);
         if (stateInfo.IsName("Show") || stateInfo.IsName("Hide"))
         {
             return;
         }

         Vector3 localHitPoint = selectorTransform.parent.InverseTransformPoint(source.TargetPoint);
         selectorPosition = new Vector2(localHitPoint.x, localHitPoint.z);
     }

if UNITY_WSA && UNITY_2017_2_OR_NEWER

    private void InteractionSourceUpdated(InteractionSourceUpdatedEventArgs obj)
     {
         // Check if it is a touchpadTouched event and from the left controller
         if (obj.state.source.handedness == Handedness && obj.state.touchpadTouched)
         {
             // If both are true, Visible is set to true and the touchpad position is assigned to selectorPosition. 
             Visible = true;
             selectorPosition = obj.state.touchpadPosition;
         }
     }

endif

} }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

194 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Programming Touchpad Joystick on Oculus Go 0 Answers

enable VR on mobile 1 Answer

Playing a VR video on Android - Google Cardboard 0 Answers

SteamVR Interaction - Bug 0 Answers

Help with Vive, UI, and Arduino 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges