Added VR libraries
This commit is contained in:
19
Assets/Oculus/VR/Editor/AndroidManifest.OVRSubmission.xml
Normal file
19
Assets/Oculus/VR/Editor/AndroidManifest.OVRSubmission.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:installLocation="auto">
|
||||
<application
|
||||
android:allowBackup="false">
|
||||
<activity
|
||||
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
|
||||
android:configChanges="locale|fontScale|keyboard|keyboardHidden|mcc|mnc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|touchscreen|uiMode"
|
||||
android:launchMode="singleTask"
|
||||
android:name="com.unity3d.player.UnityPlayerActivity"
|
||||
android:excludeFromRecents="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.INFO"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<meta-data android:name="unityplayer.SkipPermissionsDialog" android:value="false" />
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a16cc136accf1f42bdc6f71f94b50ac
|
||||
timeCreated: 1475710636
|
||||
licenseType: Pro
|
||||
TextScriptImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
55
Assets/Oculus/VR/Editor/OVRBuild.cs
Normal file
55
Assets/Oculus/VR/Editor/OVRBuild.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
/************************************************************************************
|
||||
|
||||
Copyright : Copyright 2017 Oculus VR, LLC. All Rights reserved.
|
||||
|
||||
Licensed under the Oculus VR Rift SDK License Version 3.4.1 (the "License");
|
||||
you may not use the Oculus VR Rift SDK except in compliance with the License,
|
||||
which is provided at the time of installation or download, or which
|
||||
otherwise accompanies this software in either electronic or hard copy form.
|
||||
|
||||
You may obtain a copy of the License at
|
||||
|
||||
https://developer.oculus.com/licenses/sdk-3.4.1
|
||||
|
||||
Unless required by applicable law or agreed to in writing, the Oculus VR SDK
|
||||
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.
|
||||
|
||||
************************************************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
/// <summary>
|
||||
/// Allows Oculus to build apps from the command line.
|
||||
/// </summary>
|
||||
partial class OculusBuildApp
|
||||
{
|
||||
static void SetPCTarget()
|
||||
{
|
||||
if (EditorUserBuildSettings.activeBuildTarget != BuildTarget.StandaloneWindows)
|
||||
{
|
||||
EditorUserBuildSettings.SwitchActiveBuildTarget (BuildTargetGroup.Standalone, BuildTarget.StandaloneWindows);
|
||||
}
|
||||
UnityEditorInternal.VR.VREditor.SetVREnabledOnTargetGroup(BuildTargetGroup.Standalone, true);
|
||||
PlayerSettings.virtualRealitySupported = true;
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
|
||||
static void SetAndroidTarget()
|
||||
{
|
||||
EditorUserBuildSettings.androidBuildSubtarget = MobileTextureSubtarget.ASTC;
|
||||
EditorUserBuildSettings.androidBuildSystem = AndroidBuildSystem.Internal;
|
||||
|
||||
if (EditorUserBuildSettings.activeBuildTarget != BuildTarget.Android)
|
||||
{
|
||||
EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android);
|
||||
}
|
||||
|
||||
UnityEditorInternal.VR.VREditor.SetVREnabledOnTargetGroup(BuildTargetGroup.Standalone, true);
|
||||
PlayerSettings.virtualRealitySupported = true;
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
}
|
||||
8
Assets/Oculus/VR/Editor/OVRBuild.cs.meta
Normal file
8
Assets/Oculus/VR/Editor/OVRBuild.cs.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fef522d0247215a43be6b1a8819bd940
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
317
Assets/Oculus/VR/Editor/OVREngineConfigurationUpdater.cs
Normal file
317
Assets/Oculus/VR/Editor/OVREngineConfigurationUpdater.cs
Normal file
@@ -0,0 +1,317 @@
|
||||
/************************************************************************************
|
||||
|
||||
Copyright : Copyright 2017 Oculus VR, LLC. All Rights reserved.
|
||||
|
||||
Licensed under the Oculus VR Rift SDK License Version 3.4.1 (the "License");
|
||||
you may not use the Oculus VR Rift SDK except in compliance with the License,
|
||||
which is provided at the time of installation or download, or which
|
||||
otherwise accompanies this software in either electronic or hard copy form.
|
||||
|
||||
You may obtain a copy of the License at
|
||||
|
||||
https://developer.oculus.com/licenses/sdk-3.4.1
|
||||
|
||||
Unless required by applicable law or agreed to in writing, the Oculus VR SDK
|
||||
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.
|
||||
|
||||
************************************************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Callbacks;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
[InitializeOnLoad]
|
||||
class OVREngineConfigurationUpdater
|
||||
{
|
||||
private const string prefName = "OVREngineConfigurationUpdater_Enabled";
|
||||
private const string menuItemName = "Tools/Oculus/Use Required Project Settings";
|
||||
private const string androidAssetsPath = "Assets/Plugins/Android/assets";
|
||||
private const string androidManifestPath = "Assets/Plugins/Android/AndroidManifest.xml";
|
||||
static bool setPrefsForUtilities;
|
||||
|
||||
[MenuItem(menuItemName)]
|
||||
static void ToggleUtilities()
|
||||
{
|
||||
setPrefsForUtilities = !setPrefsForUtilities;
|
||||
Menu.SetChecked(menuItemName, setPrefsForUtilities);
|
||||
|
||||
int newValue = (setPrefsForUtilities) ? 1 : 0;
|
||||
PlayerPrefs.SetInt(prefName, newValue);
|
||||
PlayerPrefs.Save();
|
||||
|
||||
Debug.Log("Using required project settings: " + setPrefsForUtilities);
|
||||
}
|
||||
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
private static readonly string dashSupportEnableConfirmedKey = "Oculus_Utilities_OVREngineConfiguration_DashSupportEnableConfirmed_" + Application.unityVersion + OVRManager.utilitiesVersion;
|
||||
private static bool dashSupportEnableConfirmed
|
||||
{
|
||||
get
|
||||
{
|
||||
return PlayerPrefs.GetInt(dashSupportEnableConfirmedKey, 0) == 1;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
PlayerPrefs.SetInt(dashSupportEnableConfirmedKey, value ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
private static void DashSupportWarningPrompt()
|
||||
{
|
||||
/// <summary>
|
||||
/// Since Unity 2017.3.0f1 and 2017.3.0f2 have "Dash Support" enabled by default
|
||||
/// We need prompt developers in case they never test their app with dash
|
||||
/// </summary>
|
||||
///
|
||||
if (Application.unityVersion == "2017.3.0f1" || Application.unityVersion == "2017.3.0f2")
|
||||
{
|
||||
if (!dashSupportEnableConfirmed)
|
||||
{
|
||||
bool dialogResult = EditorUtility.DisplayDialog("Oculus Dash support", "Your current Unity engine " + Application.unityVersion +
|
||||
" has Oculus Dash Supporting enabled by default. please make sure to test your app with Dash enabled runtime 1.21 or newer," +
|
||||
" Otherwise, you can also turn it off under XR Settings -> Oculus", "Understand", "Learn more ");
|
||||
|
||||
if (!dialogResult)
|
||||
{
|
||||
Application.OpenURL("https://developer.oculus.com/documentation/unity/latest/concepts/unity-lifecycle/");
|
||||
}
|
||||
|
||||
dashSupportEnableConfirmed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static OVREngineConfigurationUpdater()
|
||||
{
|
||||
EditorApplication.delayCall += OnDelayCall;
|
||||
EditorApplication.update += OnUpdate;
|
||||
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
DashSupportWarningPrompt();
|
||||
#endif
|
||||
}
|
||||
|
||||
static void OnDelayCall()
|
||||
{
|
||||
setPrefsForUtilities = PlayerPrefs.GetInt(prefName, 1) != 0;
|
||||
Menu.SetChecked(menuItemName, setPrefsForUtilities);
|
||||
|
||||
if (!setPrefsForUtilities)
|
||||
return;
|
||||
|
||||
OVRPlugin.SendEvent("BuildTarget", EditorUserBuildSettings.activeBuildTarget.ToString());
|
||||
EnforceAndroidSettings();
|
||||
EnforceInputManagerBindings();
|
||||
#if UNITY_ANDROID
|
||||
EnforceOSIG();
|
||||
#endif
|
||||
}
|
||||
|
||||
static void OnUpdate()
|
||||
{
|
||||
if (!setPrefsForUtilities)
|
||||
return;
|
||||
|
||||
EnforceBundleId();
|
||||
EnforceVRSupport();
|
||||
EnforceInstallLocation();
|
||||
}
|
||||
|
||||
static void EnforceAndroidSettings()
|
||||
{
|
||||
if (EditorUserBuildSettings.activeBuildTarget != BuildTarget.Android)
|
||||
return;
|
||||
|
||||
if (PlayerSettings.defaultInterfaceOrientation != UIOrientation.LandscapeLeft)
|
||||
{
|
||||
Debug.Log("OVREngineConfigurationUpdater: Setting orientation to Landscape Left");
|
||||
// Default screen orientation must be set to landscape left.
|
||||
PlayerSettings.defaultInterfaceOrientation = UIOrientation.LandscapeLeft;
|
||||
}
|
||||
|
||||
if (!PlayerSettings.virtualRealitySupported)
|
||||
{
|
||||
// NOTE: This value should not affect the main window surface
|
||||
// when Built-in VR support is enabled.
|
||||
|
||||
// NOTE: On Adreno Lollipop, it is an error to have antiAliasing set on the
|
||||
// main window surface with front buffer rendering enabled. The view will
|
||||
// render black.
|
||||
// On Adreno KitKat, some tiling control modes will cause the view to render
|
||||
// black.
|
||||
if (QualitySettings.antiAliasing != 0 && QualitySettings.antiAliasing != 1)
|
||||
{
|
||||
Debug.Log("OVREngineConfigurationUpdater: Disabling antiAliasing");
|
||||
QualitySettings.antiAliasing = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (QualitySettings.vSyncCount != 0)
|
||||
{
|
||||
Debug.Log("OVREngineConfigurationUpdater: Setting vsyncCount to 0");
|
||||
// We sync in the TimeWarp, so we don't want unity syncing elsewhere.
|
||||
QualitySettings.vSyncCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void EnforceVRSupport()
|
||||
{
|
||||
if (PlayerSettings.virtualRealitySupported)
|
||||
return;
|
||||
|
||||
var mgrs = GameObject.FindObjectsOfType<OVRManager>();
|
||||
for (int i = 0; i < mgrs.Length; ++i)
|
||||
{
|
||||
if (mgrs [i].isActiveAndEnabled)
|
||||
{
|
||||
Debug.Log ("Enabling Unity VR support");
|
||||
PlayerSettings.virtualRealitySupported = true;
|
||||
|
||||
bool oculusFound = false;
|
||||
#if UNITY_2017_2_OR_NEWER
|
||||
foreach (var device in UnityEngine.XR.XRSettings.supportedDevices)
|
||||
#else
|
||||
foreach (var device in UnityEngine.VR.VRSettings.supportedDevices)
|
||||
#endif
|
||||
oculusFound |= (device == "Oculus");
|
||||
|
||||
if (!oculusFound)
|
||||
Debug.LogError("Please add Oculus to the list of supported devices to use the Utilities.");
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void EnforceBundleId()
|
||||
{
|
||||
if (!PlayerSettings.virtualRealitySupported)
|
||||
return;
|
||||
|
||||
if (PlayerSettings.applicationIdentifier == "" || PlayerSettings.applicationIdentifier == "com.Company.ProductName")
|
||||
{
|
||||
string defaultBundleId = "com.oculus.UnitySample";
|
||||
Debug.LogWarning("\"" + PlayerSettings.applicationIdentifier + "\" is not a valid bundle identifier. Defaulting to \"" + defaultBundleId + "\".");
|
||||
PlayerSettings.applicationIdentifier = defaultBundleId;
|
||||
}
|
||||
}
|
||||
|
||||
private static void EnforceInstallLocation()
|
||||
{
|
||||
if (PlayerSettings.Android.preferredInstallLocation != AndroidPreferredInstallLocation.Auto)
|
||||
PlayerSettings.Android.preferredInstallLocation = AndroidPreferredInstallLocation.Auto;
|
||||
}
|
||||
|
||||
private static void EnforceInputManagerBindings()
|
||||
{
|
||||
try
|
||||
{
|
||||
BindAxis(new Axis() { name = "Oculus_GearVR_LThumbstickX", axis = 0, });
|
||||
BindAxis(new Axis() { name = "Oculus_GearVR_LThumbstickY", axis = 1, invert = true });
|
||||
BindAxis(new Axis() { name = "Oculus_GearVR_RThumbstickX", axis = 2, });
|
||||
BindAxis(new Axis() { name = "Oculus_GearVR_RThumbstickY", axis = 3, invert = true });
|
||||
BindAxis(new Axis() { name = "Oculus_GearVR_DpadX", axis = 4, });
|
||||
BindAxis(new Axis() { name = "Oculus_GearVR_DpadY", axis = 5, invert = true });
|
||||
BindAxis(new Axis() { name = "Oculus_GearVR_LIndexTrigger", axis = 12, });
|
||||
BindAxis(new Axis() { name = "Oculus_GearVR_RIndexTrigger", axis = 11, });
|
||||
}
|
||||
catch
|
||||
{
|
||||
Debug.LogError("Failed to apply Oculus GearVR input manager bindings.");
|
||||
}
|
||||
}
|
||||
|
||||
private static void EnforceOSIG()
|
||||
{
|
||||
// Don't bug the user in play mode.
|
||||
if (Application.isPlaying)
|
||||
return;
|
||||
|
||||
// Don't warn if the project may be set up for submission or global signing.
|
||||
if (File.Exists(androidManifestPath))
|
||||
return;
|
||||
|
||||
bool foundPossibleOsig = false;
|
||||
if (Directory.Exists(androidAssetsPath))
|
||||
{
|
||||
var files = Directory.GetFiles(androidAssetsPath);
|
||||
for (int i = 0; i < files.Length; ++i)
|
||||
{
|
||||
if (!files[i].Contains(".txt"))
|
||||
{
|
||||
foundPossibleOsig = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundPossibleOsig)
|
||||
Debug.LogWarning("Missing Gear VR OSIG at " + androidAssetsPath + ". Please see https://dashboard.oculus.com/tools/osig-generator");
|
||||
}
|
||||
|
||||
private class Axis
|
||||
{
|
||||
public string name = String.Empty;
|
||||
public string descriptiveName = String.Empty;
|
||||
public string descriptiveNegativeName = String.Empty;
|
||||
public string negativeButton = String.Empty;
|
||||
public string positiveButton = String.Empty;
|
||||
public string altNegativeButton = String.Empty;
|
||||
public string altPositiveButton = String.Empty;
|
||||
public float gravity = 0.0f;
|
||||
public float dead = 0.001f;
|
||||
public float sensitivity = 1.0f;
|
||||
public bool snap = false;
|
||||
public bool invert = false;
|
||||
public int type = 2;
|
||||
public int axis = 0;
|
||||
public int joyNum = 0;
|
||||
}
|
||||
|
||||
private static void BindAxis(Axis axis)
|
||||
{
|
||||
SerializedObject serializedObject = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0]);
|
||||
SerializedProperty axesProperty = serializedObject.FindProperty("m_Axes");
|
||||
|
||||
SerializedProperty axisIter = axesProperty.Copy();
|
||||
axisIter.Next(true);
|
||||
axisIter.Next(true);
|
||||
while (axisIter.Next(false))
|
||||
{
|
||||
if (axisIter.FindPropertyRelative("m_Name").stringValue == axis.name)
|
||||
{
|
||||
// Axis already exists. Don't create binding.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
axesProperty.arraySize++;
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
SerializedProperty axisProperty = axesProperty.GetArrayElementAtIndex(axesProperty.arraySize - 1);
|
||||
axisProperty.FindPropertyRelative("m_Name").stringValue = axis.name;
|
||||
axisProperty.FindPropertyRelative("descriptiveName").stringValue = axis.descriptiveName;
|
||||
axisProperty.FindPropertyRelative("descriptiveNegativeName").stringValue = axis.descriptiveNegativeName;
|
||||
axisProperty.FindPropertyRelative("negativeButton").stringValue = axis.negativeButton;
|
||||
axisProperty.FindPropertyRelative("positiveButton").stringValue = axis.positiveButton;
|
||||
axisProperty.FindPropertyRelative("altNegativeButton").stringValue = axis.altNegativeButton;
|
||||
axisProperty.FindPropertyRelative("altPositiveButton").stringValue = axis.altPositiveButton;
|
||||
axisProperty.FindPropertyRelative("gravity").floatValue = axis.gravity;
|
||||
axisProperty.FindPropertyRelative("dead").floatValue = axis.dead;
|
||||
axisProperty.FindPropertyRelative("sensitivity").floatValue = axis.sensitivity;
|
||||
axisProperty.FindPropertyRelative("snap").boolValue = axis.snap;
|
||||
axisProperty.FindPropertyRelative("invert").boolValue = axis.invert;
|
||||
axisProperty.FindPropertyRelative("type").intValue = axis.type;
|
||||
axisProperty.FindPropertyRelative("axis").intValue = axis.axis;
|
||||
axisProperty.FindPropertyRelative("joyNum").intValue = axis.joyNum;
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c86538ded11bfe24c8c79818bb9ea66a
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
11
Assets/Oculus/VR/Editor/OVRLayerAttributeEditor.cs
Normal file
11
Assets/Oculus/VR/Editor/OVRLayerAttributeEditor.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
[CustomPropertyDrawer(typeof(OVRLayerAttribute))]
|
||||
class LayerAttributeEditor : PropertyDrawer {
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
// One line of oxygen free code.
|
||||
property.intValue = EditorGUI.LayerField(position, label, property.intValue);
|
||||
}
|
||||
}
|
||||
12
Assets/Oculus/VR/Editor/OVRLayerAttributeEditor.cs.meta
Normal file
12
Assets/Oculus/VR/Editor/OVRLayerAttributeEditor.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6c08392d306aac74a88ba571af63c985
|
||||
timeCreated: 1499749379
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
47
Assets/Oculus/VR/Editor/OVRManifestPreprocessor.cs
Normal file
47
Assets/Oculus/VR/Editor/OVRManifestPreprocessor.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
|
||||
class OVRManifestPreprocessor
|
||||
{
|
||||
[MenuItem("Tools/Oculus/Create store-compatible AndroidManifest.xml", false, 100000)]
|
||||
public static void GenerateManifestForSubmission()
|
||||
{
|
||||
var so = ScriptableObject.CreateInstance(typeof(OVRPluginUpdaterStub));
|
||||
var script = MonoScript.FromScriptableObject(so);
|
||||
string assetPath = AssetDatabase.GetAssetPath(script);
|
||||
string editorDir = Directory.GetParent(assetPath).FullName;
|
||||
string srcFile = editorDir + "/AndroidManifest.OVRSubmission.xml";
|
||||
|
||||
if (!File.Exists(srcFile))
|
||||
{
|
||||
Debug.LogError("Cannot find Android manifest template for submission." +
|
||||
" Please delete the OVR folder and reimport the Oculus Utilities.");
|
||||
return;
|
||||
}
|
||||
|
||||
string manifestFolder = Application.dataPath + "/Plugins/Android";
|
||||
|
||||
if (!Directory.Exists(manifestFolder))
|
||||
Directory.CreateDirectory(manifestFolder);
|
||||
|
||||
string dstFile = manifestFolder + "/AndroidManifest.xml";
|
||||
|
||||
if (File.Exists(dstFile))
|
||||
{
|
||||
Debug.LogWarning("Cannot create Oculus store-compatible manifest due to conflicting file: \""
|
||||
+ dstFile + "\". Please remove it and try again.");
|
||||
return;
|
||||
}
|
||||
|
||||
File.Copy(srcFile, dstFile);
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Oculus/Remove AndroidManifest.xml")]
|
||||
public static void RemoveAndroidManifest()
|
||||
{
|
||||
AssetDatabase.DeleteAsset("Assets/Plugins/Android/AndroidManifest.xml");
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
}
|
||||
13
Assets/Oculus/VR/Editor/OVRManifestPreprocessor.cs.meta
Normal file
13
Assets/Oculus/VR/Editor/OVRManifestPreprocessor.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fb6426f323b7f024ebb25886b5182c4c
|
||||
timeCreated: 1462825988
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- renderFrom: {fileID: 168286, guid: a5014611cefbb6b4398b7e4c82203d08, type: 2}
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
507
Assets/Oculus/VR/Editor/OVRPluginUpdater.cs
Normal file
507
Assets/Oculus/VR/Editor/OVRPluginUpdater.cs
Normal file
@@ -0,0 +1,507 @@
|
||||
/************************************************************************************
|
||||
|
||||
Copyright : Copyright 2017 Oculus VR, LLC. All Rights reserved.
|
||||
|
||||
Licensed under the Oculus VR Rift SDK License Version 3.4.1 (the "License");
|
||||
you may not use the Oculus VR Rift SDK except in compliance with the License,
|
||||
which is provided at the time of installation or download, or which
|
||||
otherwise accompanies this software in either electronic or hard copy form.
|
||||
|
||||
You may obtain a copy of the License at
|
||||
|
||||
https://developer.oculus.com/licenses/sdk-3.4.1
|
||||
|
||||
Unless required by applicable law or agreed to in writing, the Oculus VR SDK
|
||||
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.
|
||||
|
||||
************************************************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Callbacks;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.IO;
|
||||
using System.Diagnostics;
|
||||
|
||||
[InitializeOnLoad]
|
||||
class OVRPluginUpdater
|
||||
{
|
||||
class PluginPackage
|
||||
{
|
||||
public string RootPath;
|
||||
public System.Version Version;
|
||||
public Dictionary<BuildTarget, string> Plugins = new Dictionary<BuildTarget, string>();
|
||||
|
||||
public bool IsBundledPluginPackage()
|
||||
{
|
||||
return (RootPath == GetBundledPluginRootPath());
|
||||
}
|
||||
|
||||
public bool IsEnabled()
|
||||
{
|
||||
// TODO: Check each individual platform rather than using the Win64 DLL status for the overall package status.
|
||||
string win64PluginPath = "";
|
||||
if (Plugins.TryGetValue(BuildTarget.StandaloneWindows64, out win64PluginPath))
|
||||
{
|
||||
return File.Exists(win64PluginPath);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static OVRPluginUpdater()
|
||||
{
|
||||
EditorApplication.delayCall += OnDelayCall;
|
||||
}
|
||||
|
||||
static void OnDelayCall()
|
||||
{
|
||||
if (ShouldAttemptPluginUpdate())
|
||||
{
|
||||
AttemptPluginUpdate(true);
|
||||
}
|
||||
}
|
||||
|
||||
private static PluginPackage GetPluginPackage(string rootPath)
|
||||
{
|
||||
return new PluginPackage()
|
||||
{
|
||||
RootPath = rootPath,
|
||||
Version = GetPluginVersion(rootPath),
|
||||
Plugins = new Dictionary<BuildTarget, string>()
|
||||
{
|
||||
{ BuildTarget.Android, rootPath + GetPluginBuildTargetSubPath(BuildTarget.Android) },
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
{ BuildTarget.StandaloneOSX, rootPath + GetPluginBuildTargetSubPath(BuildTarget.StandaloneOSX) },
|
||||
#else
|
||||
{ BuildTarget.StandaloneOSXUniversal, rootPath + GetPluginBuildTargetSubPath(BuildTarget.StandaloneOSXUniversal) },
|
||||
#endif
|
||||
{ BuildTarget.StandaloneWindows, rootPath + GetPluginBuildTargetSubPath(BuildTarget.StandaloneWindows) },
|
||||
{ BuildTarget.StandaloneWindows64, rootPath + GetPluginBuildTargetSubPath(BuildTarget.StandaloneWindows64) },
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static PluginPackage GetBundledPluginPackage()
|
||||
{
|
||||
return GetPluginPackage(GetBundledPluginRootPath());
|
||||
}
|
||||
|
||||
private static List<PluginPackage> GetAllUtilitiesPluginPackages()
|
||||
{
|
||||
string pluginRootPath = GetUtilitiesPluginRootPath();
|
||||
List<PluginPackage> packages = new List<PluginPackage>();
|
||||
|
||||
if (Directory.Exists(pluginRootPath))
|
||||
{
|
||||
var dirs = Directory.GetDirectories(pluginRootPath);
|
||||
|
||||
foreach(string dir in dirs)
|
||||
{
|
||||
packages.Add(GetPluginPackage(dir));
|
||||
}
|
||||
}
|
||||
|
||||
return packages;
|
||||
}
|
||||
|
||||
private static string GetCurrentProjectPath()
|
||||
{
|
||||
return Directory.GetParent(Application.dataPath).FullName;
|
||||
}
|
||||
|
||||
private static string GetUtilitiesPluginRootPath()
|
||||
{
|
||||
return GetUtilitiesRootPath() + @"/Plugins";
|
||||
}
|
||||
|
||||
private static string GetUtilitiesRootPath()
|
||||
{
|
||||
var so = ScriptableObject.CreateInstance(typeof(OVRPluginUpdaterStub));
|
||||
var script = MonoScript.FromScriptableObject(so);
|
||||
string assetPath = AssetDatabase.GetAssetPath(script);
|
||||
string editorDir = Directory.GetParent(assetPath).FullName;
|
||||
string ovrDir = Directory.GetParent(editorDir).FullName;
|
||||
|
||||
return ovrDir;
|
||||
}
|
||||
|
||||
private static string GetBundledPluginRootPath()
|
||||
{
|
||||
string basePath = EditorApplication.applicationContentsPath;
|
||||
string pluginPath = @"/UnityExtensions/Unity/VR";
|
||||
|
||||
return basePath + pluginPath;
|
||||
}
|
||||
|
||||
private static string GetPluginBuildTargetSubPath(BuildTarget target)
|
||||
{
|
||||
string path = string.Empty;
|
||||
|
||||
switch (target)
|
||||
{
|
||||
case BuildTarget.Android:
|
||||
path = @"/Android/OVRPlugin.aar";
|
||||
break;
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
case BuildTarget.StandaloneOSX:
|
||||
#else
|
||||
case BuildTarget.StandaloneOSXUniversal:
|
||||
#endif
|
||||
path = @"/OSXUniversal/OVRPlugin.bundle";
|
||||
break;
|
||||
case BuildTarget.StandaloneWindows:
|
||||
path = @"/Win/OVRPlugin.dll";
|
||||
break;
|
||||
case BuildTarget.StandaloneWindows64:
|
||||
path = @"/Win64/OVRPlugin.dll";
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Attempted GetPluginBuildTargetSubPath() for unsupported BuildTarget: " + target);
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
private static string GetDisabledPluginSuffix()
|
||||
{
|
||||
return @".disabled";
|
||||
}
|
||||
|
||||
private static System.Version GetPluginVersion(string path)
|
||||
{
|
||||
System.Version invalidVersion = new System.Version("0.0.0");
|
||||
System.Version pluginVersion = invalidVersion;
|
||||
|
||||
try
|
||||
{
|
||||
pluginVersion = new System.Version(Path.GetFileName(path));
|
||||
}
|
||||
catch
|
||||
{
|
||||
pluginVersion = invalidVersion;
|
||||
}
|
||||
|
||||
if (pluginVersion == invalidVersion)
|
||||
{
|
||||
//Unable to determine version from path, fallback to Win64 DLL meta data
|
||||
path += GetPluginBuildTargetSubPath(BuildTarget.StandaloneWindows64);
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
path += GetDisabledPluginSuffix();
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
return invalidVersion;
|
||||
}
|
||||
}
|
||||
|
||||
FileVersionInfo pluginVersionInfo = FileVersionInfo.GetVersionInfo(path);
|
||||
if (pluginVersionInfo == null || pluginVersionInfo.ProductVersion == null || pluginVersionInfo.ProductVersion == "")
|
||||
{
|
||||
return invalidVersion;
|
||||
}
|
||||
|
||||
pluginVersion = new System.Version(pluginVersionInfo.ProductVersion);
|
||||
}
|
||||
|
||||
return pluginVersion;
|
||||
}
|
||||
|
||||
private static bool ShouldAttemptPluginUpdate()
|
||||
{
|
||||
return autoUpdateEnabled && !restartPending && !Application.isPlaying;
|
||||
}
|
||||
|
||||
private static void DisableAllUtilitiesPluginPackages()
|
||||
{
|
||||
List<PluginPackage> allUtilsPluginPkgs = GetAllUtilitiesPluginPackages();
|
||||
|
||||
foreach(PluginPackage pluginPkg in allUtilsPluginPkgs)
|
||||
{
|
||||
foreach(string path in pluginPkg.Plugins.Values)
|
||||
{
|
||||
if ((Directory.Exists(path)) || (File.Exists(path)))
|
||||
{
|
||||
string basePath = GetCurrentProjectPath();
|
||||
string relPath = path.Substring(basePath.Length + 1);
|
||||
|
||||
AssetDatabase.MoveAsset(relPath, relPath + GetDisabledPluginSuffix());
|
||||
AssetDatabase.ImportAsset(relPath + GetDisabledPluginSuffix(), ImportAssetOptions.ForceUpdate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AssetDatabase.Refresh();
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
|
||||
private static void EnablePluginPackage(PluginPackage pluginPkg)
|
||||
{
|
||||
foreach(var kvp in pluginPkg.Plugins)
|
||||
{
|
||||
BuildTarget platform = kvp.Key;
|
||||
string path = kvp.Value;
|
||||
|
||||
if ((Directory.Exists(path + GetDisabledPluginSuffix())) || (File.Exists(path + GetDisabledPluginSuffix())))
|
||||
{
|
||||
string basePath = GetCurrentProjectPath();
|
||||
string relPath = path.Substring(basePath.Length + 1);
|
||||
|
||||
AssetDatabase.MoveAsset(relPath + GetDisabledPluginSuffix(), relPath);
|
||||
AssetDatabase.ImportAsset(relPath, ImportAssetOptions.ForceUpdate);
|
||||
|
||||
PluginImporter pi = PluginImporter.GetAtPath(relPath) as PluginImporter;
|
||||
if (pi == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
pi.SetCompatibleWithAnyPlatform(false);
|
||||
|
||||
switch (platform)
|
||||
{
|
||||
case BuildTarget.Android:
|
||||
pi.SetCompatibleWithPlatform(BuildTarget.Android, true);
|
||||
pi.SetPlatformData(BuildTarget.Android, "CPU", "ARMv7");
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSX, false);
|
||||
#else
|
||||
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSXUniversal, false);
|
||||
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSXIntel, false);
|
||||
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSXIntel64, false);
|
||||
#endif
|
||||
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows, false);
|
||||
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows64, false);
|
||||
pi.SetCompatibleWithEditor(false);
|
||||
break;
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
case BuildTarget.StandaloneOSX:
|
||||
#else
|
||||
case BuildTarget.StandaloneOSXUniversal:
|
||||
#endif
|
||||
pi.SetCompatibleWithPlatform(BuildTarget.Android, false);
|
||||
pi.SetPlatformData(BuildTarget.Android, "CPU", "ARMv7");
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSX, true);
|
||||
#else
|
||||
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSXUniversal, true);
|
||||
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSXIntel, true);
|
||||
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSXIntel64, true);
|
||||
#endif
|
||||
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows, false);
|
||||
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows64, false);
|
||||
pi.SetCompatibleWithEditor(true);
|
||||
pi.SetEditorData("CPU", "AnyCPU");
|
||||
pi.SetEditorData("OS", "OSX");
|
||||
pi.SetPlatformData("Editor", "CPU", "AnyCPU");
|
||||
pi.SetPlatformData("Editor", "OS", "OSX");
|
||||
break;
|
||||
case BuildTarget.StandaloneWindows:
|
||||
pi.SetCompatibleWithPlatform(BuildTarget.Android, false);
|
||||
pi.SetPlatformData(BuildTarget.Android, "CPU", "ARMv7");
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSX, false);
|
||||
#else
|
||||
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSXUniversal, false);
|
||||
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSXIntel, false);
|
||||
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSXIntel64, false);
|
||||
#endif
|
||||
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows, true);
|
||||
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows64, false);
|
||||
pi.SetCompatibleWithEditor(true);
|
||||
pi.SetEditorData("CPU", "X86");
|
||||
pi.SetEditorData("OS", "Windows");
|
||||
pi.SetPlatformData("Editor", "CPU", "X86");
|
||||
pi.SetPlatformData("Editor", "OS", "Windows");
|
||||
break;
|
||||
case BuildTarget.StandaloneWindows64:
|
||||
pi.SetCompatibleWithPlatform(BuildTarget.Android, false);
|
||||
pi.SetPlatformData(BuildTarget.Android, "CPU", "ARMv7");
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSX, false);
|
||||
#else
|
||||
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSXUniversal, false);
|
||||
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSXIntel, false);
|
||||
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSXIntel64, false);
|
||||
#endif
|
||||
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows, false);
|
||||
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows64, true);
|
||||
pi.SetCompatibleWithEditor(true);
|
||||
pi.SetEditorData("CPU", "X86_64");
|
||||
pi.SetEditorData("OS", "Windows");
|
||||
pi.SetPlatformData("Editor", "CPU", "X86_64");
|
||||
pi.SetPlatformData("Editor", "OS", "Windows");
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Attempted EnablePluginPackage() for unsupported BuildTarget: " + platform);
|
||||
}
|
||||
|
||||
AssetDatabase.ImportAsset(relPath, ImportAssetOptions.ForceUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
AssetDatabase.Refresh();
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
|
||||
private static bool restartPending = false;
|
||||
private static readonly string autoUpdateEnabledKey = "Oculus_Utilities_OVRPluginUpdater_AutoUpdate_" + OVRManager.utilitiesVersion;
|
||||
private static bool autoUpdateEnabled
|
||||
{
|
||||
get {
|
||||
return PlayerPrefs.GetInt(autoUpdateEnabledKey, 1) == 1;
|
||||
}
|
||||
|
||||
set {
|
||||
PlayerPrefs.SetInt(autoUpdateEnabledKey, value ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Oculus/Disable OVR Utilities Plugin")]
|
||||
private static void AttemptPluginDisable()
|
||||
{
|
||||
PluginPackage bundledPluginPkg = GetBundledPluginPackage();
|
||||
List<PluginPackage> allUtilsPluginPkgs = GetAllUtilitiesPluginPackages();
|
||||
|
||||
PluginPackage enabledUtilsPluginPkg = null;
|
||||
|
||||
foreach(PluginPackage pluginPkg in allUtilsPluginPkgs)
|
||||
{
|
||||
if (pluginPkg.IsEnabled())
|
||||
{
|
||||
if ((enabledUtilsPluginPkg == null) || (pluginPkg.Version > enabledUtilsPluginPkg.Version))
|
||||
{
|
||||
enabledUtilsPluginPkg = pluginPkg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (enabledUtilsPluginPkg == null)
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Disable Oculus Utilities Plugin", "The OVRPlugin included with Oculus Utilities is already disabled. The OVRPlugin bundled with the Unity Editor will continue to be used.\n\nBundled version: " + bundledPluginPkg.Version, "Ok", ""))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Disable Oculus Utilities Plugin", "Do you want to disable the OVRPlugin included with Oculus Utilities and revert to the OVRPlugin bundled with the Unity Editor?\n\nCurrent version: " + enabledUtilsPluginPkg.Version + "\nBundled version: " + bundledPluginPkg.Version, "Yes", "No"))
|
||||
{
|
||||
DisableAllUtilitiesPluginPackages();
|
||||
|
||||
if (EditorUtility.DisplayDialog("Restart Unity", "OVRPlugin has been updated to " + bundledPluginPkg.Version + ".\n\nPlease restart the Unity Editor to complete the update process. You may need to manually relaunch Unity if you are using Unity 5.6 and higher.", "Restart", "Not Now"))
|
||||
{
|
||||
RestartUnityEditor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Oculus/Update OVR Utilities Plugin")]
|
||||
private static void RunPluginUpdate()
|
||||
{
|
||||
AttemptPluginUpdate(false);
|
||||
}
|
||||
|
||||
private static void AttemptPluginUpdate(bool triggeredByAutoUpdate)
|
||||
{
|
||||
autoUpdateEnabled = true;
|
||||
|
||||
PluginPackage bundledPluginPkg = GetBundledPluginPackage();
|
||||
List<PluginPackage> allUtilsPluginPkgs = GetAllUtilitiesPluginPackages();
|
||||
|
||||
PluginPackage enabledUtilsPluginPkg = null;
|
||||
PluginPackage newestUtilsPluginPkg = null;
|
||||
|
||||
foreach(PluginPackage pluginPkg in allUtilsPluginPkgs)
|
||||
{
|
||||
if ((newestUtilsPluginPkg == null) || (pluginPkg.Version > newestUtilsPluginPkg.Version))
|
||||
{
|
||||
newestUtilsPluginPkg = pluginPkg;
|
||||
}
|
||||
|
||||
if (pluginPkg.IsEnabled())
|
||||
{
|
||||
if ((enabledUtilsPluginPkg == null) || (pluginPkg.Version > enabledUtilsPluginPkg.Version))
|
||||
{
|
||||
enabledUtilsPluginPkg = pluginPkg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PluginPackage targetPluginPkg = null;
|
||||
|
||||
if ((newestUtilsPluginPkg != null) && (newestUtilsPluginPkg.Version > bundledPluginPkg.Version))
|
||||
{
|
||||
if ((enabledUtilsPluginPkg == null) || (enabledUtilsPluginPkg.Version != newestUtilsPluginPkg.Version))
|
||||
{
|
||||
targetPluginPkg = newestUtilsPluginPkg;
|
||||
}
|
||||
}
|
||||
else if ((enabledUtilsPluginPkg != null) && (enabledUtilsPluginPkg.Version < bundledPluginPkg.Version))
|
||||
{
|
||||
targetPluginPkg = bundledPluginPkg;
|
||||
}
|
||||
|
||||
System.Version currentVersion = (enabledUtilsPluginPkg != null) ? enabledUtilsPluginPkg.Version : bundledPluginPkg.Version;
|
||||
|
||||
if (targetPluginPkg == null)
|
||||
{
|
||||
if (!triggeredByAutoUpdate)
|
||||
{
|
||||
EditorUtility.DisplayDialog("Update Oculus Utilities Plugin", "OVRPlugin is already up to date.\n\nCurrent version: " + currentVersion + "\nBundled version: " + bundledPluginPkg.Version, "Ok", "");
|
||||
}
|
||||
|
||||
return; // No update necessary.
|
||||
}
|
||||
|
||||
System.Version targetVersion = targetPluginPkg.Version;
|
||||
|
||||
int dialogResult = EditorUtility.DisplayDialogComplex("Update Oculus Utilities Plugin", "Oculus Utilities has detected that a newer OVRPlugin is available. Using the newest version is recommended. Do you want to enable it?\n\nCurrent version: " + currentVersion + "\nAvailable version: " + targetVersion, "Yes", "No, Don't Ask Again", "No");
|
||||
|
||||
bool userAcceptsUpdate = false;
|
||||
|
||||
switch (dialogResult)
|
||||
{
|
||||
case 0: // "Yes"
|
||||
userAcceptsUpdate = true;
|
||||
break;
|
||||
case 1: // "No, Don't Ask Again"
|
||||
autoUpdateEnabled = false;
|
||||
|
||||
EditorUtility.DisplayDialog("Oculus Utilities OVRPlugin", "To manually update in the future, use the following menu option:\n\n[Tools -> Oculus -> Update OVR Utilities Plugin]", "Ok", "");
|
||||
return;
|
||||
case 2: // "No"
|
||||
return;
|
||||
}
|
||||
|
||||
if (userAcceptsUpdate)
|
||||
{
|
||||
DisableAllUtilitiesPluginPackages();
|
||||
|
||||
if (!targetPluginPkg.IsBundledPluginPackage())
|
||||
{
|
||||
EnablePluginPackage(targetPluginPkg);
|
||||
}
|
||||
|
||||
if (EditorUtility.DisplayDialog("Restart Unity", "OVRPlugin has been updated to " + targetPluginPkg.Version + ".\n\nPlease restart the Unity Editor to complete the update process. You may need to manually relaunch Unity if you are using Unity 5.6 and higher.", "Restart", "Not Now"))
|
||||
{
|
||||
RestartUnityEditor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void RestartUnityEditor()
|
||||
{
|
||||
restartPending = true;
|
||||
EditorApplication.OpenProject(GetCurrentProjectPath());
|
||||
}
|
||||
}
|
||||
12
Assets/Oculus/VR/Editor/OVRPluginUpdater.cs.meta
Normal file
12
Assets/Oculus/VR/Editor/OVRPluginUpdater.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e64a3a065da39f4caa17a7372962df6
|
||||
timeCreated: 1493086775
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
29
Assets/Oculus/VR/Editor/OVRPluginUpdaterStub.cs
Normal file
29
Assets/Oculus/VR/Editor/OVRPluginUpdaterStub.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
/************************************************************************************
|
||||
|
||||
Copyright : Copyright 2017 Oculus VR, LLC. All Rights reserved.
|
||||
|
||||
Licensed under the Oculus VR Rift SDK License Version 3.4.1 (the "License");
|
||||
you may not use the Oculus VR Rift SDK except in compliance with the License,
|
||||
which is provided at the time of installation or download, or which
|
||||
otherwise accompanies this software in either electronic or hard copy form.
|
||||
|
||||
You may obtain a copy of the License at
|
||||
|
||||
https://developer.oculus.com/licenses/sdk-3.4.1
|
||||
|
||||
Unless required by applicable law or agreed to in writing, the Oculus VR SDK
|
||||
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.
|
||||
|
||||
************************************************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class OVRPluginUpdaterStub : ScriptableObject
|
||||
{
|
||||
// Stub helper class to locate OVR Utilities Path through Unity Editor API.
|
||||
// Required to be a standalone class in a separate file or else MonoScript.FromScriptableObject() returns an empty string path.
|
||||
}
|
||||
12
Assets/Oculus/VR/Editor/OVRPluginUpdaterStub.cs.meta
Normal file
12
Assets/Oculus/VR/Editor/OVRPluginUpdaterStub.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 791840c2fc67dd3409b79f212fad7dd4
|
||||
timeCreated: 1493148044
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
195
Assets/Oculus/VR/Editor/OVRScreenshotWizard.cs
Normal file
195
Assets/Oculus/VR/Editor/OVRScreenshotWizard.cs
Normal file
@@ -0,0 +1,195 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
|
||||
/// <summary>
|
||||
/// From the selected transform, takes a cubemap screenshot that can be submitted with the application
|
||||
/// as a screenshot (or additionally used for reflection shaders).
|
||||
/// </summary>
|
||||
class OVRScreenshotWizard : ScriptableWizard
|
||||
{
|
||||
public enum TexFormat
|
||||
{
|
||||
JPEG, // 512kb at 1k x 1k resolution vs
|
||||
PNG, // 5.3mb
|
||||
}
|
||||
|
||||
public enum SaveMode {
|
||||
SaveCubemapScreenshot,
|
||||
SaveUnityCubemap,
|
||||
SaveBoth,
|
||||
}
|
||||
|
||||
public GameObject renderFrom = null;
|
||||
public int size = 2048;
|
||||
public SaveMode saveMode = SaveMode.SaveUnityCubemap;
|
||||
public string cubeMapFolder = "Assets/Textures/Cubemaps";
|
||||
public TexFormat textureFormat = TexFormat.PNG;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the user's input
|
||||
/// </summary>
|
||||
void OnWizardUpdate()
|
||||
{
|
||||
helpString = "Select a game object positioned in the place where\nyou want to render the cubemap screenshot from: ";
|
||||
isValid = (renderFrom != null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create the asset path if it is not available.
|
||||
/// Assuming the newFolderPath is stated with "Assets", which is a requirement.
|
||||
/// </summary>
|
||||
static bool CreateAssetPath( string newFolderPath )
|
||||
{
|
||||
const int maxFoldersCount = 32;
|
||||
string currentPath;
|
||||
string[] pathFolders;
|
||||
|
||||
pathFolders = newFolderPath.Split (new char[]{ '/' }, maxFoldersCount);
|
||||
|
||||
if (!string.Equals ("Assets", pathFolders [0], System.StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Debug.LogError( "Folder path has to be started with \" Assets \" " );
|
||||
return false;
|
||||
}
|
||||
|
||||
currentPath = "Assets";
|
||||
for (int i = 1; i < pathFolders.Length; i++)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(pathFolders[i]))
|
||||
{
|
||||
string newPath = currentPath + "/" + pathFolders[i];
|
||||
if (!AssetDatabase.IsValidFolder(newPath))
|
||||
AssetDatabase.CreateFolder(currentPath, pathFolders[i]);
|
||||
currentPath = newPath;
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Log( "Created path: " + currentPath );
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renders the cubemap
|
||||
/// </summary>
|
||||
void OnWizardCreate()
|
||||
{
|
||||
if ( !AssetDatabase.IsValidFolder( cubeMapFolder ) )
|
||||
{
|
||||
if (!CreateAssetPath(cubeMapFolder))
|
||||
{
|
||||
Debug.LogError( "Created path failed: " + cubeMapFolder );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool existingCamera = true;
|
||||
bool existingCameraStateSave = true;
|
||||
Camera camera = renderFrom.GetComponent<Camera>();
|
||||
if (camera == null)
|
||||
{
|
||||
camera = renderFrom.AddComponent<Camera>();
|
||||
camera.farClipPlane = 10000f;
|
||||
existingCamera = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
existingCameraStateSave = camera.enabled;
|
||||
camera.enabled = true;
|
||||
}
|
||||
// find the last screenshot saved
|
||||
if (cubeMapFolder[cubeMapFolder.Length-1] != '/')
|
||||
{
|
||||
cubeMapFolder += "/";
|
||||
}
|
||||
int idx = 0;
|
||||
string[] fileNames = Directory.GetFiles(cubeMapFolder);
|
||||
foreach(string fileName in fileNames)
|
||||
{
|
||||
if (!fileName.ToLower().EndsWith(".cubemap"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
string temp = fileName.Replace(cubeMapFolder + "vr_screenshot_", string.Empty);
|
||||
temp = temp.Replace(".cubemap", string.Empty);
|
||||
int tempIdx = 0;
|
||||
if (int.TryParse( temp, out tempIdx ))
|
||||
{
|
||||
if (tempIdx > idx)
|
||||
{
|
||||
idx = tempIdx;
|
||||
}
|
||||
}
|
||||
}
|
||||
string pathName = string.Format("{0}vr_screenshot_{1}.cubemap", cubeMapFolder, (++idx).ToString("d2"));
|
||||
Cubemap cubemap = new Cubemap(size, TextureFormat.RGB24, false);
|
||||
|
||||
// render into cubemap
|
||||
if ((camera != null) && (cubemap != null))
|
||||
{
|
||||
// set up cubemap defaults
|
||||
OVRCubemapCapture.RenderIntoCubemap(camera, cubemap);
|
||||
if (existingCamera)
|
||||
{
|
||||
camera.enabled = existingCameraStateSave;
|
||||
}
|
||||
else
|
||||
{
|
||||
DestroyImmediate(camera);
|
||||
}
|
||||
// generate a regular texture as well?
|
||||
if ( ( saveMode == SaveMode.SaveCubemapScreenshot ) || ( saveMode == SaveMode.SaveBoth ) )
|
||||
{
|
||||
GenerateTexture(cubemap, pathName);
|
||||
}
|
||||
|
||||
if ( ( saveMode == SaveMode.SaveUnityCubemap ) || ( saveMode == SaveMode.SaveBoth ) )
|
||||
{
|
||||
Debug.Log( "Saving: " + pathName );
|
||||
// by default the unity cubemap isn't saved
|
||||
AssetDatabase.CreateAsset( cubemap, pathName );
|
||||
// reimport as necessary
|
||||
AssetDatabase.SaveAssets();
|
||||
// select it in the project tree so developers can find it
|
||||
EditorGUIUtility.PingObject( cubemap );
|
||||
Selection.activeObject = cubemap;
|
||||
}
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a NPOT 6x1 cubemap in the following format PX NX PY NY PZ NZ
|
||||
/// </summary>
|
||||
void GenerateTexture(Cubemap cubemap, string pathName)
|
||||
{
|
||||
// Encode the texture and save it to disk
|
||||
pathName = pathName.Replace(".cubemap", (textureFormat == TexFormat.PNG) ? ".png" : ".jpg" ).ToLower();
|
||||
pathName = pathName.Replace( cubeMapFolder.ToLower(), "" );
|
||||
string format = textureFormat.ToString();
|
||||
string fullPath = EditorUtility.SaveFilePanel( string.Format( "Save Cubemap Screenshot as {0}", format ), "", pathName, format.ToLower() );
|
||||
if ( !string.IsNullOrEmpty( fullPath ) )
|
||||
{
|
||||
Debug.Log( "Saving: " + fullPath );
|
||||
OVRCubemapCapture.SaveCubemapCapture(cubemap, fullPath);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unity Editor menu option to take a screenshot
|
||||
/// </summary>
|
||||
[MenuItem("Tools/Oculus/OVR Screenshot Wizard",false,100000)]
|
||||
static void TakeOVRScreenshot()
|
||||
{
|
||||
OVRScreenshotWizard wizard = ScriptableWizard.DisplayWizard<OVRScreenshotWizard>("OVR Screenshot Wizard", "Render Cubemap");
|
||||
if (wizard != null)
|
||||
{
|
||||
if (Selection.activeGameObject != null)
|
||||
wizard.renderFrom = Selection.activeGameObject;
|
||||
else
|
||||
wizard.renderFrom = Camera.main.gameObject;
|
||||
|
||||
wizard.isValid = (wizard.renderFrom != null);
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Assets/Oculus/VR/Editor/OVRScreenshotWizard.cs.meta
Normal file
13
Assets/Oculus/VR/Editor/OVRScreenshotWizard.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8b9ee1d7b188284f90d944cd54eb026
|
||||
timeCreated: 1462825988
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- renderFrom: {fileID: 168286, guid: a5014611cefbb6b4398b7e4c82203d08, type: 2}
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user