Mercurial > hg > Game > Games
comparison Orchestland/Assets/OVR/Editor/OVRShimLoader.cs @ 1:f7675884f2a1
Add Orchestland project
author | Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 17 Jul 2015 23:09:20 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:347d21cdfc22 | 1:f7675884f2a1 |
---|---|
1 /************************************************************************************ | |
2 | |
3 Copyright : Copyright 2014 Oculus VR, LLC. All Rights reserved. | |
4 | |
5 Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); | |
6 you may not use the Oculus VR Rift SDK except in compliance with the License, | |
7 which is provided at the time of installation or download, or which | |
8 otherwise accompanies this software in either electronic or hard copy form. | |
9 | |
10 You may obtain a copy of the License at | |
11 | |
12 http://www.oculusvr.com/licenses/LICENSE-3.2 | |
13 | |
14 Unless required by applicable law or agreed to in writing, the Oculus VR SDK | |
15 distributed under the License is distributed on an "AS IS" BASIS, | |
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
17 See the License for the specific language governing permissions and | |
18 limitations under the License. | |
19 | |
20 ************************************************************************************/ | |
21 | |
22 using UnityEngine; | |
23 using UnityEditor; | |
24 using UnityEditor.Callbacks; | |
25 using System; | |
26 using System.Linq; | |
27 using System.Text.RegularExpressions; | |
28 using System.IO; | |
29 | |
30 //------------------------------------------------------------------------------------- | |
31 // ***** OculusBuildDemo | |
32 // | |
33 // OculusBuild allows for command line building of the Oculus main demo (Tuscany). | |
34 // | |
35 [InitializeOnLoad] | |
36 class OVRShimLoader | |
37 { | |
38 static OVRShimLoader() | |
39 { | |
40 if (EditorUserBuildSettings.activeBuildTarget != BuildTarget.StandaloneWindows && | |
41 EditorUserBuildSettings.activeBuildTarget != BuildTarget.StandaloneWindows64) | |
42 return; | |
43 | |
44 PlayerSettings.displayResolutionDialog = ResolutionDialogSetting.HiddenByDefault; | |
45 | |
46 // forcibly enable exclusive mode only in 4.6.0b22+ and Unity 4.5.5p3+ | |
47 #if (UNITY_4_6 || (UNITY_4_5 && !(UNITY_4_5_0 || UNITY_4_5_1 || UNITY_4_5_2 || UNITY_4_5_3 || UNITY_4_5_4))) | |
48 bool unity_4_6 = false; | |
49 bool unity_4_5_5 = false; | |
50 | |
51 #if (UNITY_4_6) | |
52 unity_4_6 = true; | |
53 #elif (UNITY_4_5_5) | |
54 unity_4_5_5 = true; | |
55 #endif | |
56 | |
57 // Detect correct Unity releases which contain the fix for D3D11 exclusive mode. | |
58 string version = Application.unityVersion; | |
59 int releaseNumber; | |
60 bool releaseNumberFound = Int32.TryParse(Regex.Match(version, @"\d+$").Value, out releaseNumber); | |
61 | |
62 bool unsupportedUnityVersion = (unity_4_6 && version.Last(char.IsLetter) == 'b' && releaseNumberFound && releaseNumber < 22) | |
63 || (unity_4_5_5 && version.Last(char.IsLetter) == 'f') | |
64 || (unity_4_5_5 && version.Last(char.IsLetter) == 'p' && releaseNumberFound && releaseNumber < 3); | |
65 | |
66 bool useExclusiveModeD3D11 = true; | |
67 if (unsupportedUnityVersion) | |
68 { | |
69 useExclusiveModeD3D11 = false; | |
70 } | |
71 | |
72 PlayerSettings.d3d11ForceExclusiveMode = useExclusiveModeD3D11; | |
73 PlayerSettings.d3d9FullscreenMode = D3D9FullscreenMode.ExclusiveMode; | |
74 PlayerSettings.visibleInBackground = true; | |
75 #endif | |
76 } | |
77 | |
78 [PreferenceItem("Oculus VR")] | |
79 static void PreferencesGUI() | |
80 { | |
81 // Load the preferences | |
82 if (!_prefsLoaded) { | |
83 _isEnabled = EditorPrefs.GetBool("OculusBuild", false); | |
84 _prefsLoaded = true; | |
85 } | |
86 | |
87 // Preferences GUI | |
88 | |
89 bool isEnabled = EditorGUILayout.Toggle("Optimize Builds for Rift", _isEnabled); | |
90 | |
91 if (isEnabled && !_isEnabled && | |
92 (EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneWindows || | |
93 EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneWindows64)) | |
94 PlayerSettings.displayResolutionDialog = ResolutionDialogSetting.HiddenByDefault; | |
95 | |
96 _isEnabled = isEnabled; | |
97 | |
98 // Save the preferences | |
99 if (GUI.changed) | |
100 EditorPrefs.SetBool("OculusBuild", _isEnabled); | |
101 } | |
102 | |
103 /// <summary> | |
104 /// Replaces the built standalone with an auto-patcher for the same architecture. | |
105 /// </summary> | |
106 [PostProcessBuild] | |
107 public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject) | |
108 { | |
109 // Figure out which architecture we're building for. | |
110 int arch; | |
111 if (target == BuildTarget.StandaloneWindows) | |
112 arch = 32; | |
113 else if (target == BuildTarget.StandaloneWindows64) | |
114 arch = 64; | |
115 else | |
116 return; | |
117 | |
118 // Rename the target to a .bin file for the auto-patcher to find later. | |
119 string autoPatcherPath = Application.dataPath + "/OVR/Editor/OculusUnityPatcher_" + arch.ToString() + ".exe"; | |
120 string targetPath = pathToBuiltProject.Replace(".exe", "_DirectToRift.exe"); | |
121 | |
122 if (File.Exists(targetPath)) | |
123 File.Delete(targetPath); | |
124 | |
125 File.Copy(autoPatcherPath, targetPath); | |
126 | |
127 string appInfoPath = pathToBuiltProject.Replace(".exe", "_Data/OVRAppInfo"); | |
128 var file = new System.IO.StreamWriter(appInfoPath); | |
129 file.Write(PlayerSettings.companyName + "\\" + PlayerSettings.productName); | |
130 file.Dispose(); | |
131 } | |
132 | |
133 static bool _isEnabled = true; | |
134 static bool _prefsLoaded = false; | |
135 } |