Skip to content

Instantly share code, notes, and snippets.

@doofmars
Created July 12, 2016 16:12
Show Gist options
  • Save doofmars/d8cb97e19ed3ad03a847b46d818c6820 to your computer and use it in GitHub Desktop.
Save doofmars/d8cb97e19ed3ad03a847b46d818c6820 to your computer and use it in GitHub Desktop.

Revisions

  1. doofmars created this gist Jul 12, 2016.
    96 changes: 96 additions & 0 deletions StandaloneDevice.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,96 @@
    // Custom modified unity client for standalone purposes
    //
    // Orginal copiright left intact...
    //
    // Copyright 2015 Google Inc. All rights reserved.
    //
    // Licensed under the Apache License, Version 2.0 (the "License");
    // you may not use this file except in compliance with the License.
    // You may obtain a copy of the License at
    //
    // http://www.apache.org/licenses/LICENSE-2.0
    //
    // Unless required by applicable law or agreed to in writing, software
    // distributed under the License is distributed on an "AS IS" BASIS,
    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    // See the License for the specific language governing permissions and
    // limitations under the License.
    #if UNITY_STANDALONE

    using UnityEngine;
    using System.Collections.Generic;

    // Sends simulated values for use when testing within the Unity Editor.
    public class StandaloneDevice : BaseVRDevice {
    // Simulated neck model. Vector from the neck pivot point to the point between the eyes.
    private static readonly Vector3 neckOffset = new Vector3(0, 0.075f, 0.08f);

    // Use mouse to emulate head in the editor.
    private float mouseX = 0;
    private float mouseY = 0;
    private float mouseZ = 0;

    public override void Init() {
    Input.gyro.enabled = true;
    }

    public override bool SupportsNativeDistortionCorrection(List<string> diagnostics) {
    return false; // No need for diagnostic message.
    }

    public override bool SupportsNativeUILayer(List<string> diagnostics) {
    return false; // No need for diagnostic message.
    }

    // Since we can check all these settings by asking Cardboard.SDK, no need
    // to keep a separate copy here.
    public override void SetUILayerEnabled(bool enabled) {}
    public override void SetVRModeEnabled(bool enabled) {}
    public override void SetDistortionCorrectionEnabled(bool enabled) {}
    public override void SetStereoScreen(RenderTexture stereoScreen) {}
    public override void SetSettingsButtonEnabled(bool enabled) {}
    public override void SetAlignmentMarkerEnabled(bool enabled) {}
    public override void SetVRBackButtonEnabled(bool enabled) {}
    public override void SetShowVrBackButtonOnlyInVR(bool only) {}
    public override void SetNeckModelScale(float scale) {}
    public override void SetAutoDriftCorrectionEnabled(bool enabled) {}
    public override void SetElectronicDisplayStabilizationEnabled(bool enabled) {}
    public override void SetTapIsTrigger(bool enabled) {}

    private Quaternion initialRotation = Quaternion.identity;

    private bool remoteCommunicating = false;
    private bool RemoteCommunicating {
    get {
    if (!remoteCommunicating) {

    remoteCommunicating = Vector3.Dot(Input.gyro.rotationRate, Input.gyro.rotationRate) > 0.05;
    }
    return remoteCommunicating;
    }
    }

    public override void UpdateState() {
    triggered = Input.GetMouseButtonDown(0);
    tilted = Input.GetKeyUp(KeyCode.Escape);
    }

    public override void PostRender() {
    // Do nothing.
    }

    public override void UpdateScreenData() {
    Profile = CardboardProfile.GetKnownProfile(Cardboard.SDK.ScreenSize, Cardboard.SDK.DeviceType);
    ComputeEyesFromProfile();
    profileChanged = true;
    }

    public override void Recenter() {
    mouseX = mouseZ = 0; // Do not reset pitch, which is how it works on the phone.
    if (RemoteCommunicating) {
    //initialRotation = Quaternion.Inverse(Input.gyro.attitude);
    }
    }
    }

    #endif