Пример #1
0
    void SetCameraConfiguration()
    {
        if (!PlayerPrefs.HasKey("config"))
        {
            int needConfigurationNumber = 0;
#if UNITY_IOS
            using (var configurations = m_CameraManager.GetConfigurations(Allocator.Temp))
            {
                Debug.Log("configurations.Length =   " + configurations.Length);

                needConfigurationNumber = 0;
                for (int i = 0; i < configurations.Length; i++)
                {
                    Debug.Log("Conf.height = " + configurations[i].height + ";  Conf.width = " + configurations[i].width + ";  conf.framerate = " + configurations[i].framerate);
                    if (configurations[i].height == 720)
                    {
                        needConfigurationNumber = i;
                    }
                }
                Debug.Log("Config number: " + needConfigurationNumber);
                // Get that configuration by index
                var configuration = configurations[needConfigurationNumber];
                // Make it the active one
                m_CameraManager.currentConfiguration = configuration;
            }
#endif

#if PLATFORM_ANDROID
            using (var configurations = m_CameraManager.GetConfigurations(Allocator.Temp))
            {
                Debug.Log("configurations.Length =   " + configurations.Length);
                bool needConfFounded = false;
                needConfigurationNumber = configurations.Length - 1;
                for (int i = 0; i < configurations.Length; i++)
                {
                    Debug.Log("Conf.height = " + configurations[i].height + ";  Conf.width = " + configurations[i].width + ";  conf.framerate = " + configurations[i].framerate);
                    if ((configurations[i].height == 1080) && (!needConfFounded))
                    {
                        needConfigurationNumber = i; needConfFounded = true;
                    }
                }
                Debug.Log("Config number: " + needConfigurationNumber);
                // Get that configuration by index
                var configuration = configurations[needConfigurationNumber];
                // Make it the active one
                m_CameraManager.currentConfiguration = configuration;
            }
#endif
            PlayerPrefs.SetInt("config", needConfigurationNumber);
        }
        configurationSetted = true;
    }
Пример #2
0
    void SetCameraConfiguration()
    {
        #if UNITY_IOS
        using (var configurations = m_CameraManager.GetConfigurations(Allocator.Temp))
        {
            Debug.Log("configurations.Length =   " + configurations.Length);

            int needConfingurationNumber = 0;
            for (int i = 0; i < configurations.Length; i++)
            {
                Debug.Log("Conf.height = " + configurations[i].height + ";  Conf.width = " + configurations[i].width + ";  conf.framerate = " + configurations[i].framerate);
                if (configurations[i].height == 1080)
                {
                    needConfingurationNumber = i;
                }
            }
            Debug.Log("Config number: " + needConfingurationNumber);
            // Get that configuration by index
            var configuration = configurations[needConfingurationNumber];
            // Make it the active one
            m_CameraManager.currentConfiguration = configuration;
        }
        #endif

        #if PLATFORM_ANDROID
        using (var configurations = m_CameraManager.GetConfigurations(Allocator.Temp))
        {
            Debug.Log("configurations.Length =   " + configurations.Length);

            int needConfingurationNumber = configurations.Length - 1;

            for (int i = 0; i < configurations.Length; i++)
            {
                Debug.Log("Conf.height = " + configurations[i].height + ";  Conf.width = " + configurations[i].width + ";  conf.framerate = " + configurations[i].framerate);
                if (configurations[i].height == 1080)
                {
                    needConfingurationNumber = i;
                }
            }
            Debug.Log("Config number: " + needConfingurationNumber);
            // Get that configuration by index
            var configuration = configurations[needConfingurationNumber];
            // Make it the active one
            m_CameraManager.currentConfiguration = configuration;
        }
        #endif
        configurationSetted = true;
    }
Пример #3
0
        private void SelectCameraConfig()
        {
            if (CameraManager == null)
            {
                return;
            }

            using (var configurations = CameraManager.GetConfigurations(Allocator.Temp))
            {
                if (configurations.Length == 0)
                {
                    Debug.LogWarning(
                        "Unable to choose a custom camera configuration " +
                        "because none are available.");
                    return;
                }

                int configIndex = 0;
                if (OnChooseXRCameraConfiguration != null)
                {
                    configIndex = OnChooseXRCameraConfiguration(configurations.ToList());
                }

                if (configIndex < 0 || configIndex >= configurations.Length)
                {
                    Debug.LogWarning(
                        "Failed to find a valid config index with " +
                        "the custom selection function.");
                    return;
                }

                CameraManager.currentConfiguration = configurations[configIndex];
            }
        }
Пример #4
0
    protected IEnumerator InitCameraConf()
    {
        //https://forum.unity.com/threads/ar-foundation-camera-resolution.866743/
        yield return(new WaitForSeconds(2)); //Dirty way : Wait for 2s to let time to camera to be enabled

        if (!cameraConfInited)
        {
            NativeArray <XRCameraConfiguration> confs = arCameraManager.GetConfigurations(Allocator.Temp);

            if (confs.Length == 0)
            {
                Debug.LogError("No Camera config found - Are you using an Android device?");
            }
            else
            {
                XRCameraConfiguration bestConf = confs[0];
                int bestPixels = bestConf.width * bestConf.height;

                foreach (XRCameraConfiguration conf in confs)   //1 loop useless
                {
                    int curPixels = conf.width * conf.height;
                    if (curPixels > bestPixels)
                    {
                        bestPixels = curPixels;
                        bestConf   = conf;
                    }
                    Debug.Log("Conf: " + conf);
                }

                arCameraManager.subsystem.currentConfiguration = bestConf;
                cameraConfInited = true;
                Debug.Log("Init Best conf camera");
            }
        }
    }
Пример #5
0
        //accessing subsystem camera config data
        private NativeArray <XRCameraConfiguration> GetXRCameraConfigurations()
        {
            NativeArray <XRCameraConfiguration> xrCameraConfigurations;

            xrCameraConfigurations = arCameraManager.GetConfigurations(allocator: Unity.Collections.Allocator.Temp);

            return(xrCameraConfigurations);
        }
        //getting a list of strings based on the available camera configs
        public List <string> GetAvailableConfiguartionStrings()
        {
            List <string> availableConfigs = new List <string>();

            if (cameraManager.descriptor.supportsCameraConfigurations)
            {
                using (var configs = cameraManager.GetConfigurations(Allocator.Temp))
                {
                    for (int i = 0; i < configs.Length; i++)
                    {
                        availableConfigs.Add(configs[i].ToString());
                    }
                }
            }

            return(availableConfigs);
        }