コード例 #1
0
        // ------------
        static public void AddSymbol(string symbol, UnityEditor.BuildTargetGroup tgt)
        {
#if !UNITY_PRE_5_4
            if (((int)tgt == 15) || ((int)tgt == 16))                   // Skip WP8 and Blackberry
            {
                return;
            }
#endif

            if (IsSymbolDefined(symbol, tgt))
            {
                return;
            }

            string symbolsStr = PlayerSettings.GetScriptingDefineSymbolsForGroup(tgt).Trim();

            if (symbolsStr.Length == 0)
            {
                symbolsStr = symbol;
            }
            else
            {
                symbolsStr += (";" + symbol);
            }

            PlayerSettings.SetScriptingDefineSymbolsForGroup(tgt, symbolsStr);
        }
コード例 #2
0
        // ----------
        static public void RemoveSymbol(string symbol, UnityEditor.BuildTargetGroup tgt)
        {
            string symbolsStr = "";

            string[] symbols = GetSymbols(tgt);
            if ((symbols == null) || (symbols.Length == 0))
            {
                return;
            }

            foreach (string sym in symbols)
            {
                if ((sym.Length == 0) || (sym == symbol))
                {
                    continue;
                }

                symbolsStr += ((symbolsStr.Length > 0) ? (";" + sym) : sym);
            }

            try {
                PlayerSettings.SetScriptingDefineSymbolsForGroup(tgt, symbolsStr);
            }
            catch (System.Exception)
            { }
        }
コード例 #3
0
        // ------------
        static public void AddSymbol(string symbol, UnityEditor.BuildTargetGroup tgt)
        {
////#if !UNITY_PRE_5_4
//		if (((int)tgt == 15) || ((int)tgt == 16))		// Skip WP8 and Blackberry
//			return;
//#endif

            if (!IsBuildTargetGroupSupported(tgt))
            {
                return;
            }

            if (IsSymbolDefined(symbol, tgt) != SymbolState.OFF)
            {
                return;
            }

            string symbolsStr = "";

            try { symbolsStr = PlayerSettings.GetScriptingDefineSymbolsForGroup(tgt).Trim(); }  catch (System.Exception) { return; }

            if (symbolsStr.Length == 0)
            {
                symbolsStr = symbol;
            }
            else
            {
                symbolsStr += (";" + symbol);
            }

            try { PlayerSettings.SetScriptingDefineSymbolsForGroup(tgt, symbolsStr); } catch (System.Exception) { return; }
        }
コード例 #4
0
        /**
         *  from build target group to human friendly string for display purpose.
         */
        public static string GroupToHumaneString(UnityEditor.BuildTargetGroup g)
        {
            switch (g)
            {
            case BuildTargetGroup.Android:
                return("Android");

            case BuildTargetGroup.iOS:
                return("iOS");

            case BuildTargetGroup.PS4:
                return("PlayStation 4");

            case BuildTargetGroup.PSM:
                return("PlayStation Mobile");

            case BuildTargetGroup.PSP2:
                return("PlayStation Vita");

            case BuildTargetGroup.SamsungTV:
                return("Samsung TV");

            case BuildTargetGroup.Standalone:
                return("PC/Mac/Linux Standalone");

            case BuildTargetGroup.Tizen:
                return("Tizen");

            case BuildTargetGroup.tvOS:
                return("tvOS");

            case BuildTargetGroup.WebGL:
                return("WebGL");

            case BuildTargetGroup.WiiU:
                return("Wii U");

            case BuildTargetGroup.WSA:
                return("Windows Store Apps");

            case BuildTargetGroup.XboxOne:
                return("Xbox One");

            case BuildTargetGroup.Unknown:
                return("Unknown");

#if !UNITY_5_5_OR_NEWER
            case BuildTargetGroup.Nintendo3DS:
                return("Nintendo 3DS");

            case BuildTargetGroup.PS3:
                return("PlayStation 3");

            case BuildTargetGroup.XBOX360:
                return("Xbox 360");
#endif
            default:
                return(g.ToString() + "(deprecated)");
            }
        }
コード例 #5
0
        private static void ReplaceInputs()
        {
            string path, backUpPath, upgradedInputPath;

            GetPaths(out path, out backUpPath, out upgradedInputPath);
            if (File.Exists(backUpPath))
            {
                EditorApplication.Beep();
                if (!EditorUtility.DisplayDialog("Overwrite BackUp", "Warning you are about to overwrite your back up Input Manger. Is this okay?", "Yes", "Cancel"))
                {
                    return;
                }
            }

            System.IO.File.Copy(path, backUpPath, true);
            AssetDatabase.Refresh();

            EditorApplication.Beep();
            if (!EditorUtility.DisplayDialog("Overwrite Inputs", "Warning you are about to overwrite your Input Manger. Is this okay?", "Yes", "Cancel"))
            {
                return;
            }

            System.IO.File.Copy(upgradedInputPath, path, true);
            AssetDatabase.Refresh();
            EditorWindow.GetWindow <EditorWindow>("Inspector").Repaint();
            UnityEditor.BuildTargetGroup selectedBuildTargetGroup = UnityEditor.EditorUserBuildSettings.selectedBuildTargetGroup;
            string scriptDefineSymbols = UnityEditor.PlayerSettings.GetScriptingDefineSymbolsForGroup(selectedBuildTargetGroup);
            string defineSymbolsToSet  = scriptDefineSymbols;

            defineSymbolsToSet = defineSymbolsToSet.Replace("FLEXINPUT", "");
            defineSymbolsToSet = defineSymbolsToSet + " FLEXINPUT";
            PlayerSettings.SetScriptingDefineSymbolsForGroup(selectedBuildTargetGroup, defineSymbolsToSet);
            //        System.IO.File.Open(Application.dataPath + EditorApplication.applicationContentsPath)
        }
コード例 #6
0
 public BuildSettingsCache()
 {
     appIdentifier           = PlayerSettings.applicationIdentifier;
     productName             = PlayerSettings.productName;
     seletedBuildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup;
     signPackage             = PlayerSettings.Lumin.signPackage;
     isPackageDebuggable     = UnityEditor.Lumin.UserBuildSettings.isPackageDebuggable;
 }
コード例 #7
0
        public static BuildTarget GroupToTarget(UnityEditor.BuildTargetGroup g)
        {
            switch (g)
            {
            case BuildTargetGroup.Android:
                return(BuildTarget.Android);

            case BuildTargetGroup.iOS:
                return(BuildTarget.iOS);

            case BuildTargetGroup.PS4:
                return(BuildTarget.PS4);

            case BuildTargetGroup.PSM:
                return(BuildTarget.PSM);

            case BuildTargetGroup.PSP2:
                return(BuildTarget.PSP2);

            case BuildTargetGroup.SamsungTV:
                return(BuildTarget.SamsungTV);

            case BuildTargetGroup.Standalone:
                return(BuildTarget.StandaloneWindows);

            case BuildTargetGroup.Tizen:
                return(BuildTarget.Tizen);

            case BuildTargetGroup.tvOS:
                return(BuildTarget.tvOS);

            case BuildTargetGroup.WebGL:
                return(BuildTarget.WebGL);

            case BuildTargetGroup.WiiU:
                return(BuildTarget.WiiU);

            case BuildTargetGroup.WSA:
                return(BuildTarget.WSAPlayer);

            case BuildTargetGroup.XboxOne:
                return(BuildTarget.XboxOne);

#if !UNITY_5_5_OR_NEWER
            case BuildTargetGroup.Nintendo3DS:
                return(BuildTarget.Nintendo3DS);

            case BuildTargetGroup.PS3:
                return(BuildTarget.PS3);

            case BuildTargetGroup.XBOX360:
                return(BuildTarget.XBOX360);
#endif
            default:
                // temporarily assigned for default value (BuildTargetGroup.Unknown)
                return((BuildTarget)int.MaxValue);
            }
        }
コード例 #8
0
        public static void DisableConsole()
        {
            UnityEditor.BuildTargetGroup selectedBuildTargetGroup = UnityEditor.EditorUserBuildSettings.selectedBuildTargetGroup;
            string scriptDefineSymbols = UnityEditor.PlayerSettings.GetScriptingDefineSymbolsForGroup(selectedBuildTargetGroup);
            string defineSymbolsToSet  = scriptDefineSymbols;

            defineSymbolsToSet = defineSymbolsToSet.Replace("CONSOLE", "");
            PlayerSettings.SetScriptingDefineSymbolsForGroup(selectedBuildTargetGroup, defineSymbolsToSet);
        }
コード例 #9
0
		public bool GetDebug ()
		{
			#if UNITY_EDITOR
			UnityEditor.BuildTargetGroup buildGroup = UnityEditor.EditorUserBuildSettings.selectedBuildTargetGroup;
			string defineSymbols = UnityEditor.PlayerSettings.GetScriptingDefineSymbolsForGroup(buildGroup);

			return (defineSymbols.Contains("WDEBUG;") || defineSymbols.EndsWith("WDEBUG"));
			#else
			return false;
			#endif
		}
コード例 #10
0
        // -------------
        static public bool IsSymbolDefined(string symbolStr, UnityEditor.BuildTargetGroup tgt)
        {
            string[] symbols = GetSymbols(tgt);
            if (symbols == null)
            {
                return(false);
            }

            foreach (string sym in symbols)
            {
                if (sym.Equals(symbolStr))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #11
0
		public void SetDebug (bool debug)
		{
			#if UNITY_EDITOR
			UnityEditor.BuildTargetGroup buildGroup = UnityEditor.EditorUserBuildSettings.selectedBuildTargetGroup;
			string defineSymbols = UnityEditor.PlayerSettings.GetScriptingDefineSymbolsForGroup(buildGroup);
			
			if (debug)
			{
				defineSymbols += (defineSymbols.Length!=0? ";" : "") + "WDEBUG";
			}
			else
			{
				defineSymbols = defineSymbols.Replace("WDEBUG",""); 
				defineSymbols = defineSymbols.Replace(";;", ";"); 
			}
			
			UnityEditor.PlayerSettings.SetScriptingDefineSymbolsForGroup(buildGroup, defineSymbols);
			#endif
		}
コード例 #12
0
        private static void UseOldInputs()
        {
            string path, backUpPath, empty;

            GetPaths(out path, out backUpPath, out empty);
            if (!File.Exists(backUpPath))
            {
                EditorApplication.Beep();
                EditorUtility.DisplayDialog("No Backup Found", "Sorry no backup of your input manager exists. Aborting.", "Okay");
                return;
            }
            System.IO.File.Copy(backUpPath, path, true);
            AssetDatabase.Refresh();
            EditorWindow.GetWindow <EditorWindow>("Inspector").Repaint();
            UnityEditor.BuildTargetGroup selectedBuildTargetGroup = UnityEditor.EditorUserBuildSettings.selectedBuildTargetGroup;
            string scriptDefineSymbols = UnityEditor.PlayerSettings.GetScriptingDefineSymbolsForGroup(selectedBuildTargetGroup);
            string defineSymbolsToSet  = scriptDefineSymbols;

            defineSymbolsToSet = defineSymbolsToSet.Replace("FLEXINPUT", "");
            PlayerSettings.SetScriptingDefineSymbolsForGroup(selectedBuildTargetGroup, defineSymbolsToSet);
        }
コード例 #13
0
        // -------------
        static public SymbolState IsSymbolDefined(string symbolStr, UnityEditor.BuildTargetGroup tgt)
        {
            if (!IsBuildTargetGroupSupported(tgt))
            {
                return(SymbolState.ERROR);
            }

            string[] symbols = GetSymbols(tgt);
            if (symbols == null)
            {
                return(SymbolState.ERROR);
            }

            foreach (string sym in symbols)
            {
                if (sym.Equals(symbolStr))
                {
                    return(SymbolState.ON);
                }
            }

            return(SymbolState.OFF);
        }
コード例 #14
0
        public static void Update()
        {
            if (!SteamVR_Settings.instance.autoEnableVR || Application.isPlaying)
            {
                End();
            }

            bool enabledVR = false;

            int shouldInstall = -1;

            if (UnityEditor.PlayerSettings.virtualRealitySupported == false)
            {
                shouldInstall = UnityEditor.EditorUtility.DisplayDialogComplex("SteamVR", "Would you like to enable Virtual Reality mode?\n\nThis will enable Virtual Reality in Player Settings and add OpenVR as a target.", "Yes", "No, and don't ask again", "No");

                switch (shouldInstall)
                {
                case 0:     //yes
                    UnityEditor.PlayerSettings.virtualRealitySupported = true;
                    break;

                case 1:     //no:
                    UnityEditor.EditorApplication.update -= Update;
                    return;

                case 2:     //no, don't ask
                    SteamVR_Settings.instance.autoEnableVR = false;
                    SteamVR_Settings.Save();
                    UnityEditor.EditorApplication.update -= Update;
                    return;
                }
            }

            UnityEditor.BuildTargetGroup currentTarget = UnityEditor.EditorUserBuildSettings.selectedBuildTargetGroup;

#if UNITY_5_6_OR_NEWER
            string[] devices = UnityEditorInternal.VR.VREditor.GetVREnabledDevicesOnTargetGroup(currentTarget);
#else
            string[] devices = UnityEditorInternal.VR.VREditor.GetVREnabledDevices(currentTarget);
#endif

            bool hasOpenVR = devices.Any(device => string.Equals(device, openVRString, System.StringComparison.CurrentCultureIgnoreCase));

            if (hasOpenVR == false || enabledVR)
            {
                string[] newDevices;
                if (enabledVR && hasOpenVR == false)
                {
                    newDevices = new string[] { openVRString }; //only list openvr if we enabled it
                }
                else
                {
                    List <string> devicesList = new List <string>(devices); //list openvr as the first option if it wasn't in the list.
                    if (hasOpenVR)
                    {
                        devicesList.Remove(openVRString);
                    }

                    devicesList.Insert(0, openVRString);
                    newDevices = devicesList.ToArray();
                }

                int shouldEnable = -1;
                if (shouldInstall == 0)
                {
                    shouldEnable = 0;
                }
                else
                {
                    shouldEnable = UnityEditor.EditorUtility.DisplayDialogComplex("SteamVR", "Would you like to enable OpenVR as a VR target?", "Yes", "No, and don't ask again", "No");
                }

                switch (shouldEnable)
                {
                case 0:     //yes
#if UNITY_5_6_OR_NEWER
                    UnityEditorInternal.VR.VREditor.SetVREnabledDevicesOnTargetGroup(currentTarget, newDevices);
#else
                    UnityEditorInternal.VR.VREditor.SetVREnabledDevices(currentTarget, newDevices);
#endif
                    Debug.Log("<b>[SteamVR Setup]</b> Added OpenVR to supported VR SDKs list.");
                    break;

                case 1:     //no:
                    break;

                case 2:     //no, don't ask
                    SteamVR_Settings.instance.autoEnableVR = false;
                    SteamVR_Settings.Save();
                    break;
                }
            }

            UnityEditor.EditorApplication.update -= Update;
        }
        public static void Update()
        {
            if (!SteamVR_Settings.instance.autoEnableVR || Application.isPlaying)
            {
                End();
            }

            if (UnityEditor.PlayerSettings.virtualRealitySupported == false)
            {
                if (forceInstall == false)
                {
                    int shouldInstall = UnityEditor.EditorUtility.DisplayDialogComplex("SteamVR", "Would you like to enable Virtual Reality mode?\n\nThis will install the OpenVR for Desktop package and enable it in Player Settings.", "Yes", "No, and don't ask again", "No");

                    switch (shouldInstall)
                    {
                    case 0:     //yes
                        UnityEditor.PlayerSettings.virtualRealitySupported = true;
                        break;

                    case 1:     //no
                        End();
                        return;

                    case 2:     //no, don't ask
                        SteamVR_Settings.instance.autoEnableVR = false;
                        SteamVR_Settings.Save();
                        End();
                        return;
                    }
                }

                Debug.Log("<b>[SteamVR Setup]</b> Enabled virtual reality support in Player Settings. (you can disable this by unchecking Assets/SteamVR/SteamVR_Settings.autoEnableVR)");
            }

            switch (updateState)
            {
            case PackageStates.None:
                //see if we have the package
                listRequest = UnityEditor.PackageManager.Client.List(true);
                updateState = PackageStates.WaitingForList;
                break;

            case PackageStates.WaitingForList:
                if (listRequest == null)
                {
                    listRequest = UnityEditor.PackageManager.Client.List(true);
                    updateState = PackageStates.WaitingForList;
                }
                else if (listRequest.IsCompleted)
                {
                    if (listRequest.Error != null || listRequest.Status == UnityEditor.PackageManager.StatusCode.Failure)
                    {
                        updateState = PackageStates.Failed;
                        break;
                    }

                    string packageName = unityOpenVRPackageString;

                    bool hasPackage = listRequest.Result.Any(package => package.name == packageName);

                    if (hasPackage == false)
                    {
                        //if we don't have the package - then install it
                        addRequest  = UnityEditor.PackageManager.Client.Add(packageName);
                        updateState = PackageStates.WaitingForAdd;
                        addTryCount++;

                        Debug.Log("<b>[SteamVR Setup]</b> Installing OpenVR package...");
                        addingPackageTime.Start();
                        addingPackageTimeTotal.Start();
                    }
                    else
                    {
                        //if we do have the package, make sure it's enabled.
                        updateState = PackageStates.Installed;     //already installed
                    }
                }
                break;

            case PackageStates.WaitingForAdd:
                if (addRequest.IsCompleted)
                {
                    if (addRequest.Error != null || addRequest.Status == UnityEditor.PackageManager.StatusCode.Failure)
                    {
                        updateState = PackageStates.Failed;
                        break;
                    }
                    else
                    {
                        //if the package manager says we added it then confirm that with the list
                        listRequest = UnityEditor.PackageManager.Client.List(true);
                        updateState = PackageStates.WaitingForAddConfirm;
                    }
                }
                else
                {
                    if (addingPackageTimeTotal.Elapsed.TotalSeconds > estimatedTimeToInstall)
                    {
                        if (addTryCount == 1)
                        {
                            estimatedTimeToInstall *= 2;     //give us more time to retry
                        }
                        else
                        {
                            updateState = PackageStates.Failed;
                        }
                    }

                    string dialogText;
                    if (addTryCount == 1)
                    {
                        dialogText = "Installing OpenVR from Unity Package Manager...";
                    }
                    else
                    {
                        dialogText = "Retrying OpenVR install from Unity Package Manager...";
                    }

                    bool cancel = UnityEditor.EditorUtility.DisplayCancelableProgressBar("SteamVR", dialogText, (float)addingPackageTimeTotal.Elapsed.TotalSeconds / estimatedTimeToInstall);
                    if (cancel)
                    {
                        updateState = PackageStates.Failed;
                    }

                    if (addingPackageTime.Elapsed.TotalSeconds > 10)
                    {
                        Debug.Log("<b>[SteamVR Setup]</b> Waiting for package manager to install OpenVR package...");
                        addingPackageTime.Stop();
                        addingPackageTime.Reset();
                        addingPackageTime.Start();
                    }
                }
                break;

            case PackageStates.WaitingForAddConfirm:
                if (listRequest.IsCompleted)
                {
                    if (listRequest.Error != null)
                    {
                        updateState = PackageStates.Failed;
                        break;
                    }
                    string packageName = unityOpenVRPackageString;

                    bool hasPackage = listRequest.Result.Any(package => package.name == packageName);

                    if (hasPackage == false)
                    {
                        if (addTryCount == 1)
                        {
                            addRequest  = UnityEditor.PackageManager.Client.Add(packageName);
                            updateState = PackageStates.WaitingForAdd;
                            addTryCount++;

                            Debug.Log("<b>[SteamVR Setup]</b> Retrying OpenVR package install...");
                        }
                        else
                        {
                            updateState = PackageStates.Failed;
                        }
                    }
                    else
                    {
                        updateState = PackageStates.Installed;     //installed successfully

                        Debug.Log("<b>[SteamVR Setup]</b> Successfully installed OpenVR Desktop package.");
                    }
                }
                break;

            case PackageStates.Installed:
                UnityEditor.BuildTargetGroup currentTarget = UnityEditor.EditorUserBuildSettings.selectedBuildTargetGroup;

                string[] devices = UnityEditorInternal.VR.VREditor.GetVREnabledDevicesOnTargetGroup(currentTarget);

                bool hasOpenVR = false;
                bool isFirst   = false;

                if (devices.Length != 0)
                {
                    int index = Array.FindIndex(devices, device => string.Equals(device, openVRString, System.StringComparison.CurrentCultureIgnoreCase));
                    hasOpenVR = index != -1;
                    isFirst   = index == 0;
                }

                //list openvr as the first option if it was in the list already
                List <string> devicesList = new List <string>(devices);
                if (isFirst == false)
                {
                    if (hasOpenVR == true)
                    {
                        devicesList.Remove(openVRString);
                    }

                    devicesList.Insert(0, openVRString);
                    string[] newDevices = devicesList.ToArray();

                    UnityEditorInternal.VR.VREditor.SetVREnabledDevicesOnTargetGroup(currentTarget, newDevices);
                    Debug.Log("<b>[SteamVR Setup]</b> Added OpenVR to supported VR SDKs list.");
                }

                End();
                break;

            case PackageStates.Failed:
                End();

                string failtext = "The Unity Package Manager failed to automatically install the OpenVR Desktop package. Please open the Package Manager Window and try to install it manually.";
                UnityEditor.EditorUtility.DisplayDialog("SteamVR", failtext, "Ok");
                Debug.Log("<b>[SteamVR Setup]</b> " + failtext);
                break;
            }
        }
コード例 #16
0
        public static void Update()
        {
            if (SteamVR_Settings.instance.autoEnableVR)
            {
                bool enabledVR = false;

                if (UnityEditor.PlayerSettings.virtualRealitySupported == false)
                {
                    UnityEditor.PlayerSettings.virtualRealitySupported = true;
                    enabledVR = true;
                    Debug.Log("<b>[SteamVR Setup]</b> Enabled virtual reality support in Player Settings. (you can disable this by unchecking Assets/SteamVR/SteamVR_Settings.autoEnableVR)");
                }

                UnityEditor.BuildTargetGroup currentTarget = UnityEditor.EditorUserBuildSettings.selectedBuildTargetGroup;

#if (UNITY_5_4 || UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0)
                string[] devices = UnityEditorInternal.VR.VREditor.GetVREnabledDevices(currentTarget);
#else
                string[] devices = UnityEditorInternal.VR.VREditor.GetVREnabledDevicesOnTargetGroup(currentTarget);
#endif

                bool hasOpenVR = devices.Any(device => string.Equals(device, openVRString, System.StringComparison.CurrentCultureIgnoreCase));

                if (hasOpenVR == false || enabledVR)
                {
                    string[] newDevices;
                    if (enabledVR && hasOpenVR == false)
                    {
                        newDevices = new string[] { openVRString }; //only list openvr if we enabled it
                    }
                    else
                    {
                        List <string> devicesList = new List <string>(devices); //list openvr as the first option if it wasn't in the list.
                        if (hasOpenVR)
                        {
                            devicesList.Remove(openVRString);
                        }

                        devicesList.Insert(0, openVRString);
                        newDevices = devicesList.ToArray();
                    }

#if (UNITY_5_6 || UNITY_5_4 || UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0)
                    UnityEditorInternal.VR.VREditor.SetVREnabledDevices(currentTarget, newDevices);
#else
                    UnityEditorInternal.VR.VREditor.SetVREnabledDevicesOnTargetGroup(currentTarget, newDevices);
#endif
                    Debug.Log("<b>[SteamVR Setup]</b> Added OpenVR to supported VR SDKs list.");
                }

#if UNITY_2018_1_OR_NEWER
                //2018+ requires us to manually add the OpenVR package

                switch (packageState)
                {
                case PackageStates.None:
                    //see if we have the package
                    listRequest  = UnityEditor.PackageManager.Client.List(true);
                    packageState = PackageStates.WaitingForList;
                    break;

                case PackageStates.WaitingForList:
                    if (listRequest.IsCompleted)
                    {
                        if (listRequest.Error != null || listRequest.Status == UnityEditor.PackageManager.StatusCode.Failure)
                        {
                            packageState = PackageStates.Failed;
                            break;
                        }

                        bool hasPackage = listRequest.Result.Any(package => package.name == openVRPackageString);

                        if (hasPackage == false)
                        {
                            //if we don't have the package - then install it
                            addRequest   = UnityEditor.PackageManager.Client.Add(openVRPackageString);
                            packageState = PackageStates.WaitingForAdd;
                            addTryCount++;

                            Debug.Log("<b>[SteamVR Setup]</b> Installing OpenVR package...");
                            addingPackageTime.Start();
                            addingPackageTimeTotal.Start();
                        }
                        else
                        {
                            //if we do have the package do nothing
                            packageState = PackageStates.Installed;     //already installed
                        }
                    }
                    break;

                case PackageStates.WaitingForAdd:
                    if (addRequest.IsCompleted)
                    {
                        if (addRequest.Error != null || addRequest.Status == UnityEditor.PackageManager.StatusCode.Failure)
                        {
                            packageState = PackageStates.Failed;
                            break;
                        }
                        else
                        {
                            //if the package manager says we added it then confirm that with the list
                            listRequest  = UnityEditor.PackageManager.Client.List(true);
                            packageState = PackageStates.WaitingForAddConfirm;
                        }
                    }
                    else
                    {
                        if (addingPackageTimeTotal.Elapsed.TotalSeconds > estimatedTimeToInstall)
                        {
                            estimatedTimeToInstall *= 2;     // :)
                        }
                        string dialogText;
                        if (addTryCount == 1)
                        {
                            dialogText = "Installing OpenVR from Unity Package Manager...";
                        }
                        else
                        {
                            dialogText = "Retrying OpenVR install from Unity Package Manager...";
                        }

                        bool cancel = UnityEditor.EditorUtility.DisplayCancelableProgressBar("SteamVR", dialogText, (float)addingPackageTimeTotal.Elapsed.TotalSeconds / estimatedTimeToInstall);
                        if (cancel)
                        {
                            packageState = PackageStates.Failed;
                        }

                        if (addingPackageTime.Elapsed.TotalSeconds > 10)
                        {
                            Debug.Log("<b>[SteamVR Setup]</b> Waiting for package manager to install OpenVR package...");
                            addingPackageTime.Stop();
                            addingPackageTime.Reset();
                            addingPackageTime.Start();
                        }
                    }
                    break;

                case PackageStates.WaitingForAddConfirm:
                    if (listRequest.IsCompleted)
                    {
                        if (listRequest.Error != null)
                        {
                            packageState = PackageStates.Failed;
                            break;
                        }

                        bool hasPackage = listRequest.Result.Any(package => package.name == openVRPackageString);

                        if (hasPackage == false)
                        {
                            if (addTryCount == 1)
                            {
                                addRequest   = UnityEditor.PackageManager.Client.Add(openVRPackageString);
                                packageState = PackageStates.WaitingForAdd;
                                addTryCount++;

                                Debug.Log("<b>[SteamVR Setup]</b> Retrying OpenVR package install...");
                            }
                            else
                            {
                                packageState = PackageStates.Failed;
                            }
                        }
                        else
                        {
                            packageState = PackageStates.Installed;     //installed successfully

                            Debug.Log("<b>[SteamVR Setup]</b> Successfully installed OpenVR package.");
                        }
                    }
                    break;
                }

                if (packageState == PackageStates.Failed || packageState == PackageStates.Installed)
                {
                    addingPackageTime.Stop();
                    addingPackageTimeTotal.Stop();
                    UnityEditor.EditorUtility.ClearProgressBar();
                    UnityEditor.EditorApplication.update -= Update; //we're done trying to auto-enable vr

                    if (packageState == PackageStates.Failed)
                    {
                        string failtext = "The Unity Package Manager failed to automatically install the OpenVR package. Please open the Package Manager Window and try to install it manually.";
                        UnityEditor.EditorUtility.DisplayDialog("SteamVR", failtext, "Ok");
                        Debug.Log("<b>[SteamVR Setup]</b> " + failtext);
                    }
                }
#else
                UnityEditor.EditorApplication.update -= Update;
#endif
            }
        }
コード例 #17
0
        public static void Update()
        {
            if (SteamVR_Settings.instance.autoEnableVR)
            {
                bool enabledVR = false;

#if UNITY_2020_1_OR_NEWER || OPENVR_XR_API
#if !UNITY_2020_2_OR_NEWER
                if (UnityEditor.PlayerSettings.virtualRealitySupported == true)
                {
                    UnityEditor.PlayerSettings.virtualRealitySupported = false;
                    enabledVR = true;
                    Debug.Log("<b>[SteamVR Setup]</b> Disabled virtual reality support in Player Settings. <b>Because you're using XR Manager. Make sure OpenVR Loader is enabled in XR Manager UI.</b> (you can disable this by unchecking Assets/SteamVR/SteamVR_Settings.autoEnableVR)");
                }
#endif

#if OPENVR_XR_API
                //little hacky, but the public methods weren't working.

                if (isLoaderAssignedMethodParameters == null)
                {
                    isLoaderAssignedMethodParameters = new Type[] { typeof(string), typeof(BuildTargetGroup) }
                }
                ;
                if (isLoaderAssignedCallParameters == null)
                {
                    isLoaderAssignedCallParameters = new object[] { valveOpenVRLoaderType, BuildTargetGroup.Standalone }
                }
                ;
                if (isLoaderAssigned == null)
                {
                    isLoaderAssigned = GetMethod("IsLoaderAssigned", isLoaderAssignedMethodParameters);
                }

                if (installPackageAndAssignLoaderForBuildTarget == null)
                {
                    installPackageAndAssignLoaderForBuildTarget = GetMethod("InstallPackageAndAssignLoaderForBuildTarget");
                }

                if (isLoaderAssigned != null && installPackageAndAssignLoaderForBuildTarget != null)
                {
                    bool isAssigned = (bool)isLoaderAssigned.Invoke(null, isLoaderAssignedCallParameters);

                    if (isAssigned == false)
                    {
                        if (enabledLoaderKey == null)
                        {
                            enabledLoaderKey = string.Format(valveEnabledLoaderKeyTemplate, SteamVR_Settings.instance.editorAppKey);
                        }

                        if (EditorPrefs.HasKey(enabledLoaderKey) == false)
                        {
                            installPackageAndAssignLoaderForBuildTarget.Invoke(null, new object[] { valveOpenVRPackageString, valveOpenVRLoaderType, BuildTargetGroup.Standalone });

                            isAssigned = (bool)isLoaderAssigned.Invoke(null, isLoaderAssignedCallParameters);
                            if (isAssigned)
                            {
                                EditorPrefs.SetBool(enabledLoaderKey, true);

                                Debug.Log("<b>[SteamVR Setup]</b> Enabled OpenVR Loader in XR Management");
                                UnityEditor.EditorApplication.update -= Update;
                            }
                        }
                        else
                        {
                            UnityEditor.EditorApplication.update -= Update;
                        }
                    }
                    else
                    {
                        UnityEditor.EditorApplication.update -= Update;
                    }
                }
#elif UNITY_2020_1_OR_NEWER
                StartAutoUpdater();
#endif
#else
                if (UnityEditor.PlayerSettings.virtualRealitySupported == false)
                {
                    UnityEditor.PlayerSettings.virtualRealitySupported = true;
                    enabledVR = true;
                    Debug.Log("<b>[SteamVR Setup]</b> Enabled virtual reality support in Player Settings. (you can disable this by unchecking Assets/SteamVR/SteamVR_Settings.autoEnableVR)");
                }

                UnityEditor.BuildTargetGroup currentTarget = UnityEditor.EditorUserBuildSettings.selectedBuildTargetGroup;

#if (UNITY_5_4 || UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0)
                string[] devices = UnityEditorInternal.VR.VREditor.GetVREnabledDevices(currentTarget);
#else
                string[] devices = UnityEditorInternal.VR.VREditor.GetVREnabledDevicesOnTargetGroup(currentTarget);
#endif

                bool hasOpenVR = devices.Any(device => string.Equals(device, openVRString, System.StringComparison.CurrentCultureIgnoreCase));

                if (hasOpenVR == false || enabledVR)
                {
                    string[] newDevices;
                    if (enabledVR && hasOpenVR == false)
                    {
                        newDevices = new string[] { openVRString }; //only list openvr if we enabled it
                    }
                    else
                    {
                        List <string> devicesList = new List <string>(devices); //list openvr as the first option if it wasn't in the list.
                        if (hasOpenVR)
                        {
                            devicesList.Remove(openVRString);
                        }

                        devicesList.Insert(0, openVRString);
                        newDevices = devicesList.ToArray();
                    }

#if (UNITY_5_6 || UNITY_5_4 || UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0)
                    UnityEditorInternal.VR.VREditor.SetVREnabledDevices(currentTarget, newDevices);
#else
                    UnityEditorInternal.VR.VREditor.SetVREnabledDevicesOnTargetGroup(currentTarget, newDevices);
#endif
                    Debug.Log("<b>[SteamVR Setup]</b> Added OpenVR to supported VR SDKs list.");
                }

#if UNITY_2018_2_OR_NEWER
                //2018+ requires us to manually add the OpenVR package
                //2020.1+ has a separate script that does installs

                switch (packageState)
                {
                case PackageStates.None:
                    //see if we have the package
                    listRequest  = UnityEditor.PackageManager.Client.List(true);
                    packageState = PackageStates.WaitingForList;
                    break;

                case PackageStates.WaitingForList:
                    if (listRequest.IsCompleted)
                    {
                        if (listRequest.Error != null || listRequest.Status == UnityEditor.PackageManager.StatusCode.Failure)
                        {
                            packageState = PackageStates.Failed;
                            break;
                        }

                        string packageName = null;

                        packageName = unityOpenVRPackageString;

                        bool hasPackage = listRequest.Result.Any(package => package.name == packageName);

                        if (hasPackage == false)
                        {
                            //if we don't have the package - then install it
                            addRequest   = UnityEditor.PackageManager.Client.Add(packageName);
                            packageState = PackageStates.WaitingForAdd;
                            addTryCount++;

                            Debug.Log("<b>[SteamVR Setup]</b> Installing OpenVR package...");
                            addingPackageTime.Start();
                            addingPackageTimeTotal.Start();
                        }
                        else
                        {
                            //if we do have the package, do nothing
                            packageState = PackageStates.Installed;     //already installed
                        }
                    }
                    break;

                case PackageStates.WaitingForAdd:
                    if (addRequest.IsCompleted)
                    {
                        if (addRequest.Error != null || addRequest.Status == UnityEditor.PackageManager.StatusCode.Failure)
                        {
                            packageState = PackageStates.Failed;
                            break;
                        }
                        else
                        {
                            //if the package manager says we added it then confirm that with the list
                            listRequest  = UnityEditor.PackageManager.Client.List(true);
                            packageState = PackageStates.WaitingForAddConfirm;
                        }
                    }
                    else
                    {
                        if (addingPackageTimeTotal.Elapsed.TotalSeconds > estimatedTimeToInstall)
                        {
                            estimatedTimeToInstall *= 2;     // :)
                        }
                        string dialogText;
                        if (addTryCount == 1)
                        {
                            dialogText = "Installing OpenVR from Unity Package Manager...";
                        }
                        else
                        {
                            dialogText = "Retrying OpenVR install from Unity Package Manager...";
                        }

                        bool cancel = UnityEditor.EditorUtility.DisplayCancelableProgressBar("SteamVR", dialogText, (float)addingPackageTimeTotal.Elapsed.TotalSeconds / estimatedTimeToInstall);
                        if (cancel)
                        {
                            packageState = PackageStates.Failed;
                        }

                        if (addingPackageTime.Elapsed.TotalSeconds > 10)
                        {
                            Debug.Log("<b>[SteamVR Setup]</b> Waiting for package manager to install OpenVR package...");
                            addingPackageTime.Stop();
                            addingPackageTime.Reset();
                            addingPackageTime.Start();
                        }
                    }
                    break;

                case PackageStates.WaitingForAddConfirm:
                    if (listRequest.IsCompleted)
                    {
                        if (listRequest.Error != null)
                        {
                            packageState = PackageStates.Failed;
                            break;
                        }
                        string packageName = unityOpenVRPackageString;

                        bool hasPackage = listRequest.Result.Any(package => package.name == packageName);

                        if (hasPackage == false)
                        {
                            if (addTryCount == 1)
                            {
                                addRequest   = UnityEditor.PackageManager.Client.Add(packageName);
                                packageState = PackageStates.WaitingForAdd;
                                addTryCount++;

                                Debug.Log("<b>[SteamVR Setup]</b> Retrying OpenVR package install...");
                            }
                            else
                            {
                                packageState = PackageStates.Failed;
                            }
                        }
                        else
                        {
                            packageState = PackageStates.Installed;     //installed successfully

                            Debug.Log("<b>[SteamVR Setup]</b> Successfully installed OpenVR package.");
                        }
                    }
                    break;
                }

                if (packageState == PackageStates.Failed || packageState == PackageStates.Installed)
                {
                    addingPackageTime.Stop();
                    addingPackageTimeTotal.Stop();
                    UnityEditor.EditorUtility.ClearProgressBar();
                    UnityEditor.EditorApplication.update -= Update; //we're done trying to auto-enable vr

                    if (packageState == PackageStates.Failed)
                    {
                        string failtext = "The Unity Package Manager failed to automatically install the OpenVR package. Please open the Package Manager Window and try to install it manually.";
                        UnityEditor.EditorUtility.DisplayDialog("SteamVR", failtext, "Ok");
                        Debug.Log("<b>[SteamVR Setup]</b> " + failtext);
                    }
                }
#else
                UnityEditor.EditorApplication.update -= Update;
#endif
#endif
            }
        }