예제 #1
0
    //Инициализация начального состояния
    public void Init()
    {
        FibrumController.useAntiDrift           = useAntiDrift;
        FibrumController.useCompassForAntiDrift = useCompassForAntiDrift;

        Screen.sleepTimeout = SleepTimeout.NeverSleep;
        Screen.orientation  = ScreenOrientation.LandscapeLeft;

        if (!SystemInfo.supportsGyroscope)
        {
            noGyroscope = true;
        }
        else
        {
            noGyroscope = false;
        }

        FibrumController.Init();

        gyroBiasArray = new float[128]; for (int k = 0; k < gyroBiasArray.Length; k++)
        {
            gyroBiasArray[k] = 0f;
        }

        InvokeRepeating("RecalculateGyroBias", 0.1f, 0.2f);

        FibrumInput.LoadJoystickPrefs();

        meanAcceleration = Input.acceleration;

        if (FibrumController.vrSetup == null)
        {
            GameObject _setup = GameObject.Instantiate((GameObject)Resources.Load("FibrumResources/VRSetup", typeof(GameObject))) as GameObject;
            FibrumController.vrSetup = _setup;
        }
    }
예제 #2
0
    public void Init()
    {
        if (initialized)
        {
            return;
        }

        NewLensCorrection[] nlc = GetComponentsInChildren <NewLensCorrection>();
        cameras = new Camera[nlc.Length];
        for (int k = 0; k < cameras.Length; k++)
        {
            cameras[k] = nlc[k].gameObject.GetComponent <Camera>();
        }

        FibrumController.useAntiDrift           = useAntiDrift;
        FibrumController.useCompassForAntiDrift = useCompassForAntiDrift;

        FPStimeleft = FPSupdateInterval;

        /*if( blackFadeTex==null ) checkFPS=false;
         * if( checkFPS )
         * {
         *      blackScreen = 1f;
         *      needBlackScreen = 1f;
         *      Invoke ("CheckFPS",1.6f);
         * } */


        if (transform.Find("VRCamera"))
        {
            vrCameraLocal = transform.Find("VRCamera").transform;
        }
        else
        {
            vrCameraLocal = transform;
        }

        Screen.sleepTimeout = SleepTimeout.NeverSleep;
        Screen.orientation  = ScreenOrientation.LandscapeLeft;

#if !UNITY_STANDALONE && !UNITY_EDITOR
        if (!SystemInfo.supportsGyroscope)
        {
            noGyroscope = true;
        }
        else
        {
            noGyroscope = false;
        }
#endif

        FibrumController.Init();

                #if UNITY_ANDROID && !UNITY_EDITOR
        gyroBiasArray = new float[128]; for (int k = 0; k < gyroBiasArray.Length; k++)
        {
            gyroBiasArray[k] = 0f;
        }

        if (noGyroscope)
        {
            transform.Find("VRCamera/WarningPlane").gameObject.SetActive(true);
            EnableCompass(true);
        }

        InvokeRepeating("RecalculateGyroBias", 0.1f, 0.2f);

        if (FibrumController.useCompassForAntiDrift)
        {
            EnableCompass(true);
        }
                #endif

                #if UNITY_IPHONE
        //transform.localRotation = Quaternion.Euler(90, 0 ,0);
                #elif (UNITY_WP8 || UNITY_WP_8_1) && !UNITY_EDITOR
        Input.gyro.enabled = true;
        //transform.localRotation = Quaternion.Euler(90, 0 ,0);
        c        = new WindowsPhoneVRController.Controller();
        rotation = Quaternion.identity;
                #endif

        FibrumController.vrCamera = this;

        bool     noDummyUI  = true;
        Camera[] allCameras = GetComponentsInChildren <Camera>();
        for (int k = 0; k < allCameras.Length; k++)
        {
            if (allCameras[k].rect.width <= 0.5f)
            {
                if (allCameras[k].gameObject.GetComponent <ChangeCameraEye>() == null)
                {
                    allCameras[k].gameObject.AddComponent <ChangeCameraEye>();
                }
            }
            else if (allCameras[k].clearFlags == CameraClearFlags.Color && allCameras[k].depth == -100)
            {
                noDummyUI = false;
            }
        }
        if (noDummyUI)
        {
            GameObject dummyGO = GameObject.Instantiate((GameObject)Resources.Load("FibrumResources/VR_UI_dummyCamera", typeof(GameObject))) as GameObject;
            dummyGO.transform.parent        = vrCameraLocal;
            dummyGO.transform.localPosition = Vector3.zero;
            dummyGO.transform.localRotation = Quaternion.identity;
        }


        if (!noGyroscope)
        {
            Invoke("SensorCalibration", 0.1f);
        }
        FibrumInput.LoadJoystickPrefs();

        meanAcceleration = Input.acceleration;

        if (FibrumController.vrSetup == null)
        {
            GameObject _setup = GameObject.Instantiate((GameObject)Resources.Load("FibrumResources/VRSetup", typeof(GameObject))) as GameObject;
            FibrumController.vrSetup = _setup;
        }

        useLensCorrection = useLensCorrection;

        initialized = true;
    }