Initialer Upload neues Unity-Projekt
This commit is contained in:
54
Assets/Oculus/VR/Editor/Utils/OVRAnimatedContent.cs
Normal file
54
Assets/Oculus/VR/Editor/Utils/OVRAnimatedContent.cs
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus 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/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus 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;
|
||||
|
||||
public class OVRAnimatedContent : ScriptableObject
|
||||
{
|
||||
public Texture2D[] frames;
|
||||
public float frameDuration;
|
||||
|
||||
private int _currentIndex;
|
||||
private float _lastTimer = 0.0f;
|
||||
|
||||
public Texture2D CurrentFrame => frames[_currentIndex];
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (frameDuration == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var newTimer = Time.realtimeSinceStartup;
|
||||
var delta = newTimer - _lastTimer;
|
||||
if (delta > frameDuration)
|
||||
{
|
||||
var numberOfDeltas = Mathf.Floor(delta / frameDuration);
|
||||
_lastTimer = _lastTimer + numberOfDeltas * frameDuration;
|
||||
_currentIndex = (_currentIndex + 1) % frames.Length;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnValidate()
|
||||
{
|
||||
_lastTimer = Time.realtimeSinceStartup;
|
||||
}
|
||||
}
|
||||
11
Assets/Oculus/VR/Editor/Utils/OVRAnimatedContent.cs.meta
Normal file
11
Assets/Oculus/VR/Editor/Utils/OVRAnimatedContent.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3c84d40c65a252f4b98000235614545b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
143
Assets/Oculus/VR/Editor/Utils/OVRGuiContent.cs
Normal file
143
Assets/Oculus/VR/Editor/Utils/OVRGuiContent.cs
Normal file
@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus 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/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus 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 System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
internal class OVRGUIContent
|
||||
{
|
||||
public enum Source
|
||||
{
|
||||
BuiltIn,
|
||||
GenericIcons,
|
||||
ProjectSetupToolIcons,
|
||||
BuildingBlocksIcons,
|
||||
BuildingBlocksThumbnails,
|
||||
BuildingBlocksAnimations
|
||||
}
|
||||
|
||||
private static string _rootPath;
|
||||
private static readonly Dictionary<Source, string> RelativePaths = new Dictionary<Source, string>();
|
||||
|
||||
public static void RegisterContentPath(Source source, string relativePath)
|
||||
{
|
||||
RelativePaths.Add(source, relativePath);
|
||||
}
|
||||
|
||||
private static bool GetRootPath(out string rootPath)
|
||||
{
|
||||
if (_rootPath == null)
|
||||
{
|
||||
var g = AssetDatabase.FindAssets($"t:Script {nameof(OVRGUIContent)}");
|
||||
if (g.Length > 0)
|
||||
{
|
||||
_rootPath = AssetDatabase.GUIDToAssetPath(g[0]);
|
||||
_rootPath = Path.GetDirectoryName(_rootPath);
|
||||
_rootPath = Path.GetDirectoryName(_rootPath);
|
||||
}
|
||||
}
|
||||
|
||||
rootPath = _rootPath;
|
||||
return rootPath != null;
|
||||
}
|
||||
|
||||
public static bool BuildPath(string path, Source source, out string contentPath)
|
||||
{
|
||||
contentPath = null;
|
||||
if (GetRootPath(out var rootPath))
|
||||
{
|
||||
if (RelativePaths.TryGetValue(source, out var relativePath))
|
||||
{
|
||||
contentPath = Path.Combine(Path.Combine(rootPath, relativePath), path);
|
||||
}
|
||||
}
|
||||
return contentPath != null;
|
||||
}
|
||||
|
||||
public static implicit operator GUIContent(OVRGUIContent ovrContent)
|
||||
{
|
||||
return ovrContent.Content;
|
||||
}
|
||||
|
||||
private GUIContent _content;
|
||||
private readonly string _name;
|
||||
private readonly Source _source;
|
||||
private readonly bool _builtIn;
|
||||
private string _tooltip;
|
||||
|
||||
public string Tooltip
|
||||
{
|
||||
set
|
||||
{
|
||||
_tooltip = value;
|
||||
_content.tooltip = value;
|
||||
}
|
||||
}
|
||||
|
||||
public OVRGUIContent(string name, Source source, string tooltip = null)
|
||||
{
|
||||
_name = name;
|
||||
_tooltip = tooltip;
|
||||
_source = source;
|
||||
_content = new GUIContent
|
||||
{
|
||||
image = null,
|
||||
tooltip = _tooltip
|
||||
};
|
||||
}
|
||||
|
||||
public GUIContent Content
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_content.image == null)
|
||||
{
|
||||
LoadContent();
|
||||
}
|
||||
|
||||
return _content;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Valid => Content.image != null;
|
||||
|
||||
private void LoadContent()
|
||||
{
|
||||
if (!OVREditorUtils.IsMainEditor())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_source == Source.BuiltIn)
|
||||
{
|
||||
_content = EditorGUIUtility.TrIconContent(_name, _tooltip);
|
||||
}
|
||||
else if (BuildPath(_name, _source, out var fullPath))
|
||||
{
|
||||
var texture = AssetDatabase.LoadAssetAtPath<Texture2D>(fullPath);
|
||||
if (texture)
|
||||
{
|
||||
_content.image = texture;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Oculus/VR/Editor/Utils/OVRGuiContent.cs.meta
Normal file
11
Assets/Oculus/VR/Editor/Utils/OVRGuiContent.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5c060149b1ceb2c40a22a10ede3b2d8d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
116
Assets/Oculus/VR/Editor/Utils/OVRPassthroughHelper.cs
Normal file
116
Assets/Oculus/VR/Editor/Utils/OVRPassthroughHelper.cs
Normal file
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus 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/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus 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 System.Linq;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
internal static class OVRPassthroughHelper
|
||||
{
|
||||
internal static bool EnablePassthrough()
|
||||
{
|
||||
var ovrManager = OVRProjectSetupUtils.FindComponentInScene<OVRManager>();
|
||||
|
||||
if (ovrManager is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ovrManager.isInsightPassthroughEnabled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
internal static bool IsAnyPassthroughLayerUnderlay()
|
||||
{
|
||||
return OVRProjectSetupUtils.FindComponentsInScene<OVRPassthroughLayer>()
|
||||
.Any(p => p.overlayType == OVROverlay.OverlayType.Underlay);
|
||||
}
|
||||
|
||||
internal static bool InitPassthroughLayerUnderlay(GameObject ovrCameraRig)
|
||||
{
|
||||
var passthroughLayers = OVRProjectSetupUtils.FindComponentsInScene<OVRPassthroughLayer>().ToList();
|
||||
|
||||
// no PT layers
|
||||
if (passthroughLayers.Count == 0)
|
||||
{
|
||||
var underLay = ovrCameraRig.AddComponent<OVRPassthroughLayer>();
|
||||
underLay.overlayType = OVROverlay.OverlayType.Underlay;
|
||||
}
|
||||
// there are layers but non of them are Underlay
|
||||
else if (passthroughLayers.All(l => l.overlayType != OVROverlay.OverlayType.Underlay))
|
||||
{
|
||||
// if there is only one PT layer, change it to Underlay
|
||||
if (passthroughLayers.Count == 1)
|
||||
{
|
||||
passthroughLayers.First().overlayType = OVROverlay.OverlayType.Underlay;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError(
|
||||
"There are multiple OVRPassthroughLayer instances in the scene, but none of them is an Underlay. Set one of the layer's Placement to Underlay.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
SaveScene();
|
||||
return true;
|
||||
}
|
||||
|
||||
internal static bool HasCentralCamera(OVRCameraRig ovrCameraRig) =>
|
||||
(ovrCameraRig.centerEyeAnchor != null ? ovrCameraRig.centerEyeAnchor.GetComponent<Camera>() : null) != null;
|
||||
|
||||
internal static Camera GetCentralCamera(OVRCameraRig ovrCameraRig) =>
|
||||
ovrCameraRig.centerEyeAnchor != null ? ovrCameraRig.centerEyeAnchor.GetComponent<Camera>() : null;
|
||||
|
||||
internal static bool IsBackgroundClear(OVRCameraRig ovrCameraRig)
|
||||
{
|
||||
var centerCamera = GetCentralCamera(ovrCameraRig);
|
||||
|
||||
if (centerCamera is null)
|
||||
{
|
||||
throw new System.Exception("Central camera was not found");
|
||||
}
|
||||
|
||||
return centerCamera.clearFlags == CameraClearFlags.SolidColor && centerCamera.backgroundColor.a < 1;
|
||||
}
|
||||
|
||||
internal static void ClearBackground(OVRCameraRig ovrCameraRig)
|
||||
{
|
||||
var centerCamera = GetCentralCamera(ovrCameraRig);
|
||||
|
||||
if (centerCamera is null)
|
||||
{
|
||||
throw new System.Exception("Central camera was not found");
|
||||
}
|
||||
|
||||
centerCamera.clearFlags = CameraClearFlags.SolidColor;
|
||||
centerCamera.backgroundColor = Color.clear;
|
||||
|
||||
SaveScene();
|
||||
}
|
||||
|
||||
private static void SaveScene()
|
||||
{
|
||||
var activeScene = SceneManager.GetActiveScene();
|
||||
EditorSceneManager.MarkSceneDirty(activeScene);
|
||||
EditorSceneManager.SaveScene(activeScene);
|
||||
}
|
||||
}
|
||||
11
Assets/Oculus/VR/Editor/Utils/OVRPassthroughHelper.cs.meta
Normal file
11
Assets/Oculus/VR/Editor/Utils/OVRPassthroughHelper.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b85b74bb254fb14e9c2b48aa87cd4a1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
34
Assets/Oculus/VR/Editor/Utils/OVRReadOnlyDrawer.cs
Normal file
34
Assets/Oculus/VR/Editor/Utils/OVRReadOnlyDrawer.cs
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus 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/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus 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 UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
[CustomPropertyDrawer(typeof(OVRReadOnlyAttribute))]
|
||||
internal class OVRReadOnlyDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
var previousGUIState = GUI.enabled;
|
||||
GUI.enabled = false;
|
||||
EditorGUI.PropertyField(position, property, label);
|
||||
GUI.enabled = previousGUIState;
|
||||
}
|
||||
}
|
||||
11
Assets/Oculus/VR/Editor/Utils/OVRReadOnlyDrawer.cs.meta
Normal file
11
Assets/Oculus/VR/Editor/Utils/OVRReadOnlyDrawer.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca58c9ab30b88a947941a8e1ec5086e7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user