// Use this for initialization
    void Start()
    {
        lastLaserMode = DataLoader.Settings.Lasermode;

        this.Head = GameObject.Find("Camera (head)");

        HOTK_Overlay overlay = GetComponent <HOTK_Overlay>();

        OwnOverlay = overlay;
        if (overlay.AnchorDevice == HOTK_Overlay.AttachmentDevice.LeftController)
        {
            this.Hand = GameObject.Find("Controller (left)");
        }
        else if (overlay.AnchorDevice == HOTK_Overlay.AttachmentDevice.RightController)
        {
            this.Hand = GameObject.Find("Controller (right)");
        }
        else
        {
            Debug.LogError("Hand billboard on wrong object");
            Debug.Assert(false);
        }
        Device = Hand.GetComponent <HOTK_TrackedDevice>();

        ButtonOverlay = ButtonOverlayObject.GetComponent <HOTK_Overlay>();
        HandOverlay   = HandOverlayObject.GetComponent <HOTK_Overlay>();

        HandComponents components = new HandComponents(this.Hand, this);

        DataLoader.HandComponents.Add(components);

        UpdateLaserMode();
    }
Example #2
0
    private void OverlayScaleChanges(HOTK_Overlay o, float scale)
    {
        _scale = scale;
        SetPivotOffset(o);
        if (OverlayMode == CompanionMode.VRInterface)
        {
            switch (_attachMode)
            {
            case InterfaceAttachMode.Free:
                gameObject.transform.localPosition = _companionOffset;
                break;

            case InterfaceAttachMode.PivotTop:
            case InterfaceAttachMode.PivotRight:
            case InterfaceAttachMode.PivotBottom:
            case InterfaceAttachMode.PivotLeft:
                gameObject.transform.localPosition = _companionOffset + _pivotOffset;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        updateCompanion = true;
    }
    /// <summary>
    /// Create a new Save
    /// </summary>
    private PortalSettings ConvertToTwitchSettings(HOTK_Overlay o) // Create a new save state
    {
        return(new PortalSettings()
        {
            SaveFileVersion = PortalSettings.CurrentSaveVersion,

            X = o.AnchorOffset.x,
            Y = o.AnchorOffset.y,
            Z = o.AnchorOffset.z,
            RX = o.transform.eulerAngles.x,
            RY = o.transform.eulerAngles.y,
            RZ = o.transform.eulerAngles.z,

            Device = o.AnchorDevice,
            Point = o.AnchorPoint,
            Animation = o.AnimateOnGaze,

            AlphaStart = o.Alpha,
            AlphaEnd = o.Alpha2,
            AlphaSpeed = o.AlphaSpeed,
            ScaleStart = o.Scale,
            ScaleEnd = o.Scale2,
            ScaleSpeed = o.ScaleSpeed,
        });
    }
Example #4
0
    private void SetPivotOffset(HOTK_Overlay overlay)
    {
        switch (_attachMode)
        {
        case InterfaceAttachMode.Free:
            _pivotOffset = Vector3.zero;
            break;

        case InterfaceAttachMode.PivotTop:
            Pivot.transform.localPosition = new Vector3(0f, -(overlay.GetCurrentHeight() / 2f), 0f);
            _pivotOffset = new Vector3(0f, -(GetCurrentHeight() / 2f), 0f);
            break;

        case InterfaceAttachMode.PivotRight:
            Pivot.transform.localPosition = new Vector3((overlay.GetCurrentWidth() / 2f), 0f, 0f);
            _pivotOffset = new Vector3((GetCurrentWidth() / 2f), 0f, 0f);
            break;

        case InterfaceAttachMode.PivotBottom:
            Pivot.transform.localPosition = new Vector3(0f, (overlay.GetCurrentHeight() / 2f), 0f);
            _pivotOffset = new Vector3(0f, (GetCurrentHeight() / 2f), 0f);
            break;

        case InterfaceAttachMode.PivotLeft:
            Pivot.transform.localPosition = new Vector3(-(overlay.GetCurrentWidth() / 2f), 0f, 0f);
            _pivotOffset = new Vector3(-(GetCurrentWidth() / 2f), 0f, 0f);
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }
        //Pivot.transform.localRotation = Quaternion.Euler(PivotEuler);
    }
 public void ShowButtonOverlay(GridButton button, HOTK_Overlay overlay)
 {
     overlay.Scale = Mathf.Min(this.Width * button.width / this.ButtonGrid.gridWidth, this.Height * button.height / this.ButtonGrid.gridHeight);
     overlay.transform.position = transform.position + transform.rotation * new Vector3(-this.Width / 2 + (this.Width / this.ButtonGrid.gridWidth) * (button.x + button.width * 0.5f), -(-this.Height / 2 + (this.Height / this.ButtonGrid.gridHeight) * (button.y + button.height * 0.5f)), 0);
     overlay.transform.rotation = transform.rotation;
     overlay.enabled            = true;
 }
    /// <summary>
    /// Create a new Save
    /// </summary>
    private ProfileSettings ConvertToTwitchSettings(HOTK_Overlay o) // Create a new save state
    {
        var backgroundColor = GetMaterialTexture().GetPixel(0, 0);

        return(new ProfileSettings()
        {
            SaveFileVersion = ProfileSettings.CurrentSaveVersion,

            // Username = UsernameField.text,
            Channel = ChannelField.text,
            X = o.AnchorOffset.x,
            Y = o.AnchorOffset.y,
            Z = o.AnchorOffset.z,
            RX = o.transform.eulerAngles.x,
            RY = o.transform.eulerAngles.y,
            RZ = o.transform.eulerAngles.z,

            Device = o.AnchorDevice,
            Point = o.AnchorPoint,
            Animation = o.AnimateOnGaze,

            BackgroundR = backgroundColor.r,
            BackgroundG = backgroundColor.g,
            BackgroundB = backgroundColor.b,
            BackgroundA = backgroundColor.a,

            AlphaStart = o.Alpha,
            AlphaEnd = o.AnimationAlpha,
            AlphaSpeed = o.AnimationAlphaSpeed,
            ScaleStart = o.Scale,
            ScaleEnd = o.AnimationScale,
            ScaleSpeed = o.AnimationScaleSpeed,
        });
    }
 private void OverlayRotationChanges(HOTK_Overlay o, Quaternion rot)
 {
     if (OverlayMode == CompanionMode.DodgeOnGaze)
     {
         if (_anchorDevice == HOTK_Overlay.AttachmentDevice.World)
         {
             gameObject.transform.localRotation = rot;
         }
     }
     OverlayRotationChanges();
 }
Example #8
0
    /// <summary>
    /// Create a new Save
    /// </summary>
    private PortalSettings ConvertToPortalSettings(HOTK_Overlay o) // Create a new save state
    {
        return(new PortalSettings()
        {
            SaveFileVersion = PortalSettings.CurrentSaveVersion,

            X = o.AnchorOffset.x,
            Y = o.AnchorOffset.y,
            Z = o.AnchorOffset.z,
            RX = o.transform.eulerAngles.x,
            RY = o.transform.eulerAngles.y,
            RZ = o.transform.eulerAngles.z,

            Device = o.AnchorDevice,
            Point = o.AnchorPoint,
            Animation = o.AnimateOnGaze,

            AlphaStart = o.Alpha,
            AlphaEnd = o.Alpha2,
            AlphaSpeed = o.AlphaSpeed,
            ScaleStart = o.Scale,
            ScaleEnd = o.Scale2,
            ScaleSpeed = o.ScaleSpeed,

            ScreenOffsetPerformed = DesktopPortalController.Instance.ScreenOffsetPerformed,

            OutlineDefaultR = DesktopPortalController.Instance.OutlineColorDefault.r,
            OutlineDefaultG = DesktopPortalController.Instance.OutlineColorDefault.g,
            OutlineDefaultB = DesktopPortalController.Instance.OutlineColorDefault.b,
            OutlineDefaultA = DesktopPortalController.Instance.OutlineColorDefault.a,
            OutlineAimingR = DesktopPortalController.Instance.OutlineColorAiming.r,
            OutlineAimingG = DesktopPortalController.Instance.OutlineColorAiming.g,
            OutlineAimingB = DesktopPortalController.Instance.OutlineColorAiming.b,
            OutlineAimingA = DesktopPortalController.Instance.OutlineColorAiming.a,
            OutlineTouchingR = DesktopPortalController.Instance.OutlineColorTouching.r,
            OutlineTouchingG = DesktopPortalController.Instance.OutlineColorTouching.g,
            OutlineTouchingB = DesktopPortalController.Instance.OutlineColorTouching.b,
            OutlineTouchingA = DesktopPortalController.Instance.OutlineColorTouching.a,
            OutlineScalingR = DesktopPortalController.Instance.OutlineColorScaling.r,
            OutlineScalingG = DesktopPortalController.Instance.OutlineColorScaling.g,
            OutlineScalingB = DesktopPortalController.Instance.OutlineColorScaling.b,
            OutlineScalingA = DesktopPortalController.Instance.OutlineColorScaling.a,

            Backside = DesktopPortalController.Instance.CurrentBacksideTexture,

            GrabEnabled = DesktopPortalController.Instance.GrabEnabledToggle.isOn,
            ScaleEnabled = DesktopPortalController.Instance.ScaleEnabledToggle.isOn,
            HapticsEnabled = DesktopPortalController.Instance.HapticsEnabledToggle.isOn,

            DodgeOffsetX = o.DodgeGazeOffset.x,
            DodgeOffsetY = o.DodgeGazeOffset.y,
            DodgeOffsetSpeed = o.DodgeGazeSpeed,
        });
    }
 private void OverlayPositionChanges(HOTK_Overlay o, Vector3 pos)
 {
     if (OverlayMode != CompanionMode.DodgeOnGaze)
     {
         return;
     }
     if (_anchorDevice == HOTK_Overlay.AttachmentDevice.World)
     {
         gameObject.transform.localPosition = pos;
     }
     updateCompanion = true;
 }
Example #10
0
 public void SetOverlayCanGaze(HOTK_Overlay overlay, bool isInteractable = true)
 {
     if (isInteractable)
     {
         if (!_gazeableOverlays.Contains(overlay))
         {
             _gazeableOverlays.Add(overlay);
         }
     }
     else
     {
         if (_gazeableOverlays.Contains(overlay))
         {
             _gazeableOverlays.Remove(overlay);
         }
     }
 }
    /// <summary>
    /// Create a new Save
    /// </summary>
    private TwitchSettings ConvertToTwitchSettings(HOTK_Overlay o) // Create a new save state
    {
        var backgroundColor = GetMaterialTexture().GetPixel(0, 0);

        return(new TwitchSettings()
        {
            SaveFileVersion = TwitchSettings.CurrentSaveVersion,

            Username = UsernameField.text,
            Channel = ChannelField.text,
            X = o.AnchorOffset.x,
            Y = o.AnchorOffset.y,
            Z = o.AnchorOffset.z,
            RX = o.transform.eulerAngles.x,
            RY = o.transform.eulerAngles.y,
            RZ = o.transform.eulerAngles.z,

            ChatSound = ChatSoundDropdown.Dropdown.options[ChatSoundDropdown.Dropdown.value].text,
            Volume = VolumeSlider.Slider.value,
            Pitch = PitchSlider.Slider.value,

            FollowerSound = NewFollowerSoundDropdown.Dropdown.options[NewFollowerSoundDropdown.Dropdown.value].text,
            FollowerVolume = NewFollowerVolumeSlider.Slider.value,
            FollowerPitch = NewFollowerPitchSlider.Slider.value,

            Device = o.AnchorDevice,
            Point = o.AnchorPoint,
            Animation = o.AnimateOnGaze,

            BackgroundR = backgroundColor.r,
            BackgroundG = backgroundColor.g,
            BackgroundB = backgroundColor.b,
            BackgroundA = backgroundColor.a,

            AlphaStart = o.Alpha,
            AlphaEnd = o.Alpha2,
            AlphaSpeed = o.AlphaSpeed,
            ScaleStart = o.Scale,
            ScaleEnd = o.Scale2,
            ScaleSpeed = o.ScaleSpeed,
        });
    }
Example #12
0
    private void SetupPivot(HOTK_Overlay o)
    {
        Pivot.hideFlags = HideFlags.None;
        Pivot.SetActive(true);
        PivotEuler = Pivot.transform.localEulerAngles;
        switch (o.AnchorDevice)
        {
        case HOTK_Overlay.AttachmentDevice.World:
        case HOTK_Overlay.AttachmentDevice.Screen:
            Pivot.transform.parent = o.gameObject.transform;
            break;

        case HOTK_Overlay.AttachmentDevice.LeftController:
        case HOTK_Overlay.AttachmentDevice.RightController:
            Pivot.transform.parent = o.OverlayReference.transform;
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }
        Pivot.transform.localRotation = Quaternion.Euler(PivotEuler);
    }
    // Use this for initialization
    void Start()
    {
        if (this != DataLoader.ProfileOverlay)
        {
            DataLoader.Overlays.Add(this);
        }

        if (ButtonGrid.alpha > 0)
        {
            WWW file = new WWW("file:///" + Path.Combine(ButtonGrid.parent.directory, ButtonGrid.filename));
            file.LoadImageIntoTexture((Texture2D)this.GetComponent <HOTK_Overlay>().OverlayTexture);
        }

        transform.position = new Vector3((float)ButtonGrid.x, (float)ButtonGrid.y, (float)ButtonGrid.z);
        transform.rotation = Quaternion.Euler((float)ButtonGrid.pitch, (float)ButtonGrid.yaw, (float)ButtonGrid.roll);

        Overlay       = GetComponent <HOTK_Overlay>();
        Overlay.Scale = (float)ButtonGrid.width;
        Overlay.Alpha = (float)ButtonGrid.alpha;
        this.Width    = (float)ButtonGrid.width;
        this.Height   = (float)ButtonGrid.height;
    }
Example #14
0
    private void AttachToPivot(HOTK_Overlay o)
    {
        switch (o.AnchorDevice)
        {
        case HOTK_Overlay.AttachmentDevice.World:
        case HOTK_Overlay.AttachmentDevice.Screen:
            gameObject.transform.parent        = Pivot.transform;
            gameObject.transform.localPosition = _companionOffset + _pivotOffset;
            gameObject.transform.localRotation = Quaternion.identity;
            break;

        case HOTK_Overlay.AttachmentDevice.LeftController:
        case HOTK_Overlay.AttachmentDevice.RightController:
            OverlayReference.transform.parent        = Pivot.transform;
            OverlayReference.transform.localPosition = _companionOffset + _pivotOffset;
            OverlayReference.transform.localRotation = Quaternion.identity;
            gameObject.transform.parent = o.gameObject.transform;
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }
    }
Example #15
0
    private void UpdateAnchor(HOTK_Overlay o, HOTK_Overlay.AttachmentDevice d)
    {
        switch (d)
        {
        case HOTK_Overlay.AttachmentDevice.World:
        case HOTK_Overlay.AttachmentDevice.Screen:
            gameObject.transform.parent = root;
            break;

        case HOTK_Overlay.AttachmentDevice.LeftController:
            gameObject.transform.parent = HOTK_TrackedDeviceManager.Instance.LeftTracker.gameObject.transform;
            break;

        case HOTK_Overlay.AttachmentDevice.RightController:
            gameObject.transform.parent = HOTK_TrackedDeviceManager.Instance.RightTracker.gameObject.transform;
            break;

        default:
            throw new ArgumentOutOfRangeException("d", d, null);
        }
        gameObject.transform.localPosition = Vector3.zero;
        gameObject.transform.localRotation = Quaternion.identity;
    }
 private void OverlayRotationChanges(HOTK_Overlay o, Quaternion rot)
 {
     //_anchorRotation = rot;
     OverlayRotationChanges();
 }
 private void OverlayPositionChanges(HOTK_Overlay o, Vector3 pos)
 {
     gameObject.transform.localPosition = pos;
     updateCompanion = true;
 }
 private void OverlayScaleChanges(HOTK_Overlay o, float scale)
 {
     _scale          = scale;
     updateCompanion = true;
 }
 private void OverlayAlphaChanges(HOTK_Overlay o, float alpha)
 {
     _alpha          = alpha;
     updateCompanion = true;
 }
Example #20
0
 public void SpawnOverlay(HOTK_Overlay overlay)
 {
     overlay.gameObject.SetActive(true);
 }
Example #21
0
    private void UpdateGaze()
    {
        FindTracker(ref _hmdTracker, HOTK_TrackedDevice.EType.HMD);
        HOTK_Overlay     hitOverlay     = null;
        HOTK_OverlayBase hitOverlayBase = null;

        SteamVR_Overlay.IntersectionResults?hitResult = null;

        // Test Overlays
        foreach (var overlay in _gazeableOverlays)
        {
            if (overlay.AnimateOnGaze == HOTK_Overlay.AnimationType.None)
            {
                continue;
            }
            if (overlay.GazeLocked || _hmdTracker == null || !_hmdTracker.IsValid)
            {
                continue;
            }
            if (!(Vector3.Angle(_hmdTracker.transform.forward, overlay.RotationTracker.transform.forward) <= 90f))
            {
                continue;
            }
            var result = new SteamVR_Overlay.IntersectionResults();
            var hit    = ComputeIntersection(overlay, _hmdTracker.gameObject.transform.position, _hmdTracker.gameObject.transform.forward, ref result);
            if (!hit || (hitResult != null && !(result.distance < hitResult.Value.distance)))
            {
                continue;
            }
            hitOverlay = overlay;
            hitResult  = result;
        }
        // Test Companions
        foreach (var overlay in _gazeableCompanionOverlays)
        {
            if (_hmdTracker == null || !_hmdTracker.IsValid)
            {
                continue;
            }
            if (!(Vector3.Angle(_hmdTracker.transform.forward, overlay.RotationTracker.transform.forward) <= 90f))
            {
                continue;
            }
            var result = new SteamVR_Overlay.IntersectionResults();
            var hit    = ComputeIntersection(overlay, _hmdTracker.gameObject.transform.position, _hmdTracker.gameObject.transform.forward, ref result);
            if (!hit || (hitResult != null && !(result.distance < hitResult.Value.distance)))
            {
                continue;
            }
            hitOverlay     = null;
            hitOverlayBase = overlay;
            hitResult      = result;
        }

        if (hitOverlay != null)
        {
            foreach (var overlay in _gazeableOverlays)
            {
                overlay.UpdateGaze((overlay.GazeLocked && overlay.GazeLockedOn) || (!overlay.GazeLocked && overlay == hitOverlay));
            }
            foreach (var companion in _gazeableCompanionOverlays)
            {
                companion.UpdateGaze(false);
            }
        }
        else if (hitOverlayBase != null)
        {
            foreach (var overlay in _gazeableOverlays)
            {
                overlay.UpdateGaze(overlay.GazeLocked && overlay.GazeLockedOn);
            }
            foreach (var companion in _gazeableCompanionOverlays.Where(o => o != hitOverlayBase))
            {
                companion.UpdateGaze(false);
            }
            hitOverlayBase.UpdateGaze(true);
        }
        else
        {
            foreach (var overlay in _gazeableOverlays)
            {
                overlay.UpdateGaze(overlay.GazeLocked && overlay.GazeLockedOn);
            }
            foreach (var companion in _gazeableCompanionOverlays)
            {
                companion.UpdateGaze(false);
            }
        }
    }
 public void OnParentDisabled(HOTK_Overlay o)
 {
     gameObject.SetActive(false);
 }
Example #23
0
 private void UpdateRotation(HOTK_Overlay o, Quaternion r)
 {
     _baseRotation = r;
 }
Example #24
0
    /// <summary>
    /// Push Updates to our Overlay to the OpenVR System
    /// </summary>
    private void UpdateOverlay()
    {
        var overlay = OpenVR.Overlay;

        if (overlay == null)
        {
            return;
        }

        if (OverlayTexture != null)
        {
            var error = overlay.ShowOverlay(_handle);
            if (error == EVROverlayError.InvalidHandle || error == EVROverlayError.UnknownOverlay)
            {
                if (overlay.FindOverlay(Key, ref _handle) != EVROverlayError.None)
                {
                    return;
                }
            }

            var tex = new Texture_t
            {
                handle      = OverlayTexture.GetNativeTexturePtr(),
                eType       = SteamVR.instance.textureType,
                eColorSpace = EColorSpace.Auto
            };
            overlay.SetOverlayColor(_handle, 1f, 1f, 1f);
            //overlay.SetOverlayGamma(_handle, 2.2f); // Doesn't exist yet :(
            overlay.SetOverlayTexture(_handle, ref tex);
            overlay.SetOverlayAlpha(_handle, AnimateOnGaze == AnimationType.Alpha || AnimateOnGaze == AnimationType.AlphaAndScale ? _alpha : Alpha);
            overlay.SetOverlayWidthInMeters(_handle, AnimateOnGaze == AnimationType.Scale || AnimateOnGaze == AnimationType.AlphaAndScale ? _scale : Scale);
            overlay.SetOverlayAutoCurveDistanceRangeInMeters(_handle, CurvedRange.x, CurvedRange.y);

            var textureBounds = new VRTextureBounds_t
            {
                uMin = (0 + UvOffset.x) * UvOffset.z,
                vMin = (1 + UvOffset.y) * UvOffset.w,
                uMax = (1 + UvOffset.x) * UvOffset.z,
                vMax = (0 + UvOffset.y) * UvOffset.w
            };
            overlay.SetOverlayTextureBounds(_handle, ref textureBounds);

            var vecMouseScale = new HmdVector2_t
            {
                v0 = MouseScale.x,
                v1 = MouseScale.y
            };
            overlay.SetOverlayMouseScale(_handle, ref vecMouseScale);

            if (_anchor != OpenVR.k_unTrackedDeviceIndexInvalid) // Attached to some HOTK_TrackedDevice, used for Controllers
            {
                var t = GetOverlayPosition();
                overlay.SetOverlayTransformTrackedDeviceRelative(_handle, _anchor, ref t);
            }
            else if (AnchorDevice == MountDevice.World) // Attached to World
            {
                var t = GetOverlayPosition();
                overlay.SetOverlayTransformAbsolute(_handle, SteamVR_Render.instance.trackingSpace, ref t);
            }
            else
            {
                var vrcam = SteamVR_Render.Top();
                if (vrcam != null && vrcam.origin != null) // Attached to Camera (We are Rendering)
                {
                    var offset = new SteamVR_Utils.RigidTransform(vrcam.origin, transform);
                    offset.pos.x /= vrcam.origin.localScale.x;
                    offset.pos.y /= vrcam.origin.localScale.y;
                    offset.pos.z /= vrcam.origin.localScale.z;

                    var t = offset.ToHmdMatrix34();
                    overlay.SetOverlayTransformAbsolute(_handle, SteamVR_Render.instance.trackingSpace, ref t);
                }
                else // Attached to Camera (We are Not Rendering)
                {
                    var t = GetOverlayPosition();
                    overlay.SetOverlayTransformTrackedDeviceRelative(_handle, 0, ref t);
                }
            }

            overlay.SetOverlayInputMethod(_handle, InputMethod);

            if (Highquality)
            {
                if (HighQualityOverlay != this && HighQualityOverlay != null)
                {
                    if (HighQualityOverlay.Highquality)
                    {
                        Debug.LogWarning("Only one Overlay can be in HighQuality mode as per the OpenVR API.");
                        HighQualityOverlay.Highquality = false;
                    }
                    HighQualityOverlay = this;
                }
                else if (HighQualityOverlay == null)
                {
                    HighQualityOverlay = this;
                }

                overlay.SetHighQualityOverlay(_handle);
                overlay.SetOverlayFlag(_handle, VROverlayFlags.Curved, Curved);
                overlay.SetOverlayFlag(_handle, VROverlayFlags.RGSS4X, Antialias);
            }
            else if (overlay.GetHighQualityOverlay() == _handle)
            {
                overlay.SetHighQualityOverlay(OpenVR.k_ulOverlayHandleInvalid);
            }
        }
        else
        {
            overlay.HideOverlay(_handle);
        }
    }
 public void OnParentEnabled(HOTK_Overlay o)
 {
     gameObject.SetActive(OverlayMode != CompanionMode.DodgeOnGaze || Overlay.AnimateOnGaze == HOTK_Overlay.AnimationType.DodgeGaze);
 }