Initialer Upload neues Unity-Projekt
This commit is contained in:
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b71f6a8330eca3849a8ab895f86704f3
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,31 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
public class LocalizedHaptics : MonoBehaviour
|
||||
{
|
||||
[Header("Settings")]
|
||||
[SerializeField] private OVRInput.Handedness m_handedness = OVRInput.Handedness.LeftHanded;
|
||||
|
||||
private OVRInput.Controller m_controller;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
m_controller = m_handedness == OVRInput.Handedness.LeftHanded
|
||||
? OVRInput.Controller.LTouch
|
||||
: OVRInput.Controller.RTouch;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Build vibration for the frame based on device inputs
|
||||
float thumbAmp = OVRInput.Get(OVRInput.Axis1D.PrimaryThumbRestForce, m_controller) > 0.5f ? 1f : 0f;
|
||||
OVRInput.SetControllerLocalizedVibration(OVRInput.HapticsLocation.Thumb, 0f, thumbAmp, m_controller);
|
||||
|
||||
float indexAmp = OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, m_controller) > 0.5f ? 1f : 0f;
|
||||
OVRInput.SetControllerLocalizedVibration(OVRInput.HapticsLocation.Index, 0f, indexAmp, m_controller);
|
||||
|
||||
float handAmp = OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, m_controller) > 0.5f ? 1f : 0f;
|
||||
OVRInput.SetControllerLocalizedVibration(OVRInput.HapticsLocation.Hand, 0f, handAmp, m_controller);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a9934e1fe91ce6246bc5d27934aa09f8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,41 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
public class SceneSettings : MonoBehaviour
|
||||
{
|
||||
[Header("Time")]
|
||||
[SerializeField] private float m_fixedTimeStep = 0.01f;
|
||||
|
||||
[Header("Physics")]
|
||||
[SerializeField] private float m_gravityScalar = 0.75f;
|
||||
|
||||
[SerializeField] private float m_defaultContactOffset = 0.001f;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// Time
|
||||
Time.fixedDeltaTime = m_fixedTimeStep;
|
||||
|
||||
// Physics
|
||||
Physics.gravity = Vector3.down * 9.81f * m_gravityScalar;
|
||||
Physics.defaultContactOffset = m_defaultContactOffset;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// Update the contact offset for all existing colliders since setting
|
||||
// Physics.defaultContactOffset only applies to newly created colliders.
|
||||
CollidersSetContactOffset(m_defaultContactOffset);
|
||||
}
|
||||
|
||||
private static void CollidersSetContactOffset(float contactOffset)
|
||||
{
|
||||
// @Note: This does not find inactive objects.
|
||||
Collider[] allColliders = GameObject.FindObjectsOfType<Collider>();
|
||||
foreach (Collider collider in allColliders)
|
||||
{
|
||||
collider.contactOffset = contactOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 029a39db456d2904caf61d65c65512ff
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 94854e6b5488b6f4989456027cd743b7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,115 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
public class StylusTip : MonoBehaviour
|
||||
{
|
||||
private const int MaxBreadCrumbs = 60;
|
||||
private const float BreadCrumbMinSize = 0.005f;
|
||||
private const float BreadCrumbMaxSize = 0.02f;
|
||||
|
||||
[Header("External")]
|
||||
[SerializeField] private Transform m_trackingSpace;
|
||||
|
||||
[Header("Settings")]
|
||||
[SerializeField] private OVRInput.Handedness m_handedness = OVRInput.Handedness.LeftHanded;
|
||||
|
||||
[SerializeField] private GameObject m_breadCrumbPf;
|
||||
|
||||
private GameObject m_breadCrumbContainer;
|
||||
private GameObject[] m_breadCrumbs;
|
||||
|
||||
private int m_breadCrumbIndexPrev = -1;
|
||||
private int m_breadCrumbIndexCurr = 0;
|
||||
|
||||
private OVRInput.Controller m_controller;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
m_controller = m_handedness == OVRInput.Handedness.LeftHanded
|
||||
? OVRInput.Controller.LTouch
|
||||
: OVRInput.Controller.RTouch;
|
||||
|
||||
// Create the bread crumbs
|
||||
m_breadCrumbContainer = new GameObject($"BreadCrumbContainer ({m_handedness})");
|
||||
m_breadCrumbs = new GameObject[MaxBreadCrumbs];
|
||||
for (int i = 0; i < m_breadCrumbs.Length; ++i)
|
||||
{
|
||||
// Create bread crumb
|
||||
GameObject breadCrumb = GameObject.Instantiate(m_breadCrumbPf, m_breadCrumbContainer.transform);
|
||||
breadCrumb.name = $"BreadCrumb ({i})";
|
||||
breadCrumb.SetActive(false);
|
||||
|
||||
// Store bread crumb
|
||||
m_breadCrumbs[i] = breadCrumb;
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Update stylus tip position
|
||||
Pose T_device = new Pose(OVRInput.GetLocalControllerPosition(m_controller),
|
||||
OVRInput.GetLocalControllerRotation(m_controller));
|
||||
Pose T_world_device = T_device.GetTransformedBy(m_trackingSpace);
|
||||
Pose T_world_stylusTip = GetT_Device_StylusTip(m_controller).GetTransformedBy(T_world_device);
|
||||
this.transform.SetPositionAndRotation(T_world_stylusTip.position, T_world_stylusTip.rotation);
|
||||
|
||||
// Get stylus tip data
|
||||
float stylusTipForce = OVRInput.Get(OVRInput.Axis1D.PrimaryStylusForce, m_controller);
|
||||
bool isStylusTipTouching = stylusTipForce > 0;
|
||||
|
||||
// Set the next crumb position
|
||||
GameObject nextCrumb = m_breadCrumbs[m_breadCrumbIndexCurr];
|
||||
nextCrumb.transform.position = this.transform.position;
|
||||
|
||||
// Set next crumb visuals based on stylus tip force
|
||||
float nextCrumbSize = Mathf.Lerp(BreadCrumbMinSize, BreadCrumbMaxSize, stylusTipForce);
|
||||
nextCrumb.transform.localScale = new Vector3(nextCrumbSize, nextCrumbSize, nextCrumbSize);
|
||||
nextCrumb.GetComponent<MeshRenderer>().material.color = Color.Lerp(Color.white, Color.red, stylusTipForce);
|
||||
nextCrumb.SetActive(isStylusTipTouching);
|
||||
|
||||
float crumbSeparation = 0;
|
||||
float distanceToPrevCrumb = Mathf.Infinity;
|
||||
if (m_breadCrumbIndexPrev >= 0)
|
||||
{
|
||||
// Compute next crumb distance to stylus tip
|
||||
distanceToPrevCrumb = (this.transform.position - m_breadCrumbs[m_breadCrumbIndexPrev].transform.position)
|
||||
.magnitude;
|
||||
|
||||
// Compute next crumb separation by averaging the previous and next crumb sizes
|
||||
crumbSeparation = (nextCrumbSize + m_breadCrumbs[m_breadCrumbIndexPrev].transform.localScale.x) * 0.5f;
|
||||
}
|
||||
|
||||
// Determine if a new crumb should drop
|
||||
if (isStylusTipTouching && (distanceToPrevCrumb >= crumbSeparation))
|
||||
{
|
||||
// Drop the crumb
|
||||
m_breadCrumbIndexPrev = m_breadCrumbIndexCurr;
|
||||
m_breadCrumbIndexCurr = (m_breadCrumbIndexCurr + 1) % m_breadCrumbs.Length;
|
||||
}
|
||||
}
|
||||
|
||||
private static Pose GetT_Device_StylusTip(OVRInput.Controller controller)
|
||||
{
|
||||
// @Note: Only the next controller supports the stylus tip, but we compute the
|
||||
// transforms for all controllers so we can draw the tip at the correct location.
|
||||
Pose T_device_stylusTip = Pose.identity;
|
||||
|
||||
if (controller == OVRInput.Controller.LTouch || controller == OVRInput.Controller.RTouch)
|
||||
{
|
||||
T_device_stylusTip = new Pose(
|
||||
new Vector3(0.0094f, -0.07145f, -0.07565f),
|
||||
Quaternion.Euler(35.305f, 50.988f, 37.901f)
|
||||
);
|
||||
}
|
||||
|
||||
if (controller == OVRInput.Controller.LTouch)
|
||||
{
|
||||
T_device_stylusTip.position.x *= -1;
|
||||
T_device_stylusTip.rotation.y *= -1;
|
||||
T_device_stylusTip.rotation.z *= -1;
|
||||
}
|
||||
|
||||
return T_device_stylusTip;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7403a7cb4696f3043903f5a10961ee1a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5622c3221cbe1b546acfb55d9d5a6467
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,40 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
public class UiAxis1dInspector : MonoBehaviour
|
||||
{
|
||||
[Header("Settings")]
|
||||
[SerializeField] private float m_minExtent = 0;
|
||||
|
||||
[SerializeField] private float m_maxExtent = 1;
|
||||
|
||||
[Header("Components")]
|
||||
[SerializeField] private TextMeshProUGUI m_nameLabel = null;
|
||||
|
||||
[SerializeField] private TextMeshProUGUI m_valueLabel = null;
|
||||
[SerializeField] private Slider m_slider = null;
|
||||
|
||||
public void SetExtents(float minExtent, float maxExtent)
|
||||
{
|
||||
m_minExtent = minExtent;
|
||||
m_maxExtent = maxExtent;
|
||||
}
|
||||
|
||||
public void SetName(string name)
|
||||
{
|
||||
m_nameLabel.text = name;
|
||||
}
|
||||
|
||||
public void SetValue(float value)
|
||||
{
|
||||
m_valueLabel.text = string.Format("[{0}]", value.ToString("f2"));
|
||||
|
||||
m_slider.minValue = Mathf.Min(value, m_minExtent);
|
||||
m_slider.maxValue = Mathf.Max(value, m_maxExtent);
|
||||
|
||||
m_slider.value = value;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dcf3246473f1a024e8f952f2a56a10c2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,53 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
public class UiAxis2dInspector : MonoBehaviour
|
||||
{
|
||||
[Header("Settings")]
|
||||
[SerializeField] private Vector2 m_xExtent = new Vector2(-1, +1);
|
||||
|
||||
[SerializeField] private Vector2 m_yExtent = new Vector2(-1, +1);
|
||||
|
||||
[Header("Components")]
|
||||
[SerializeField] private TextMeshProUGUI m_nameLabel = null;
|
||||
|
||||
[SerializeField] private TextMeshProUGUI m_valueLabel = null;
|
||||
[SerializeField] private Image m_handle = null;
|
||||
|
||||
public void SetExtents(Vector2 xExtent, Vector2 yExtent)
|
||||
{
|
||||
m_xExtent = xExtent;
|
||||
m_yExtent = yExtent;
|
||||
}
|
||||
|
||||
public void SetName(string name)
|
||||
{
|
||||
m_nameLabel.text = name;
|
||||
}
|
||||
|
||||
public void SetValue(bool isTouching, Vector2 value)
|
||||
{
|
||||
m_handle.color = isTouching ? Color.white : new Color(0.2f, 0.2f, 0.2f);
|
||||
|
||||
Vector2 clampedValue = new Vector2(
|
||||
Mathf.Clamp(value.x, m_xExtent.x, m_xExtent.y),
|
||||
Mathf.Clamp(value.y, m_yExtent.x, m_yExtent.y)
|
||||
);
|
||||
|
||||
m_valueLabel.text = $"[{clampedValue.x.ToString("f2")}, {clampedValue.y.ToString("f2")}]";
|
||||
|
||||
RectTransform parentRect = m_handle.transform.parent.GetComponent<RectTransform>();
|
||||
Vector2 parentSize = (parentRect != null)
|
||||
? new Vector2(Mathf.Abs(parentRect.sizeDelta.x), Mathf.Abs(parentRect.sizeDelta.y))
|
||||
: new Vector2(Mathf.Abs(m_xExtent.y - m_xExtent.x), Mathf.Abs(m_yExtent.y - m_yExtent.x));
|
||||
|
||||
m_handle.transform.localPosition = new Vector3(
|
||||
clampedValue.x * parentSize.x * 0.5f,
|
||||
clampedValue.y * parentSize.y * 0.5f,
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c0717b533f75054d93d184c48b4b8d8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,23 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UiBoolInspector : MonoBehaviour
|
||||
{
|
||||
[Header("Components")]
|
||||
[SerializeField] private TextMeshProUGUI m_nameLabel = null;
|
||||
|
||||
[SerializeField] private Toggle m_toggle = null;
|
||||
|
||||
public void SetName(string name)
|
||||
{
|
||||
m_nameLabel.text = name;
|
||||
}
|
||||
|
||||
public void SetValue(bool value)
|
||||
{
|
||||
m_toggle.isOn = value;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c25d8f20d93560f47bf604ec2dfc098c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,106 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
public class UiDeviceInspector : MonoBehaviour
|
||||
{
|
||||
[Header("Settings")]
|
||||
[SerializeField] private OVRInput.Handedness m_handedness = OVRInput.Handedness.LeftHanded;
|
||||
|
||||
[Header("Left Column Components")]
|
||||
[SerializeField] private TextMeshProUGUI m_title;
|
||||
|
||||
[SerializeField] private TextMeshProUGUI m_status;
|
||||
|
||||
[SerializeField] private UiBoolInspector m_thumbRestTouch;
|
||||
[SerializeField] private UiAxis1dInspector m_thumbRestForce;
|
||||
[SerializeField] private UiAxis1dInspector m_indexTrigger;
|
||||
[SerializeField] private UiAxis1dInspector m_gripTrigger;
|
||||
[SerializeField] private UiAxis1dInspector m_stylusTipForce;
|
||||
|
||||
[SerializeField] private UiAxis1dInspector m_indexCurl1d;
|
||||
[SerializeField] private UiAxis1dInspector m_indexSlider1d;
|
||||
|
||||
[Header("Right Column Components")]
|
||||
[SerializeField] private UiBoolInspector m_ax;
|
||||
|
||||
[SerializeField] private UiBoolInspector m_axTouch;
|
||||
[SerializeField] private UiBoolInspector m_by;
|
||||
[SerializeField] private UiBoolInspector m_byTouch;
|
||||
[SerializeField] private UiBoolInspector m_indexTouch;
|
||||
|
||||
[SerializeField] private UiAxis2dInspector m_thumbstick;
|
||||
|
||||
private OVRInput.Controller m_controller;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
m_controller = m_handedness == OVRInput.Handedness.LeftHanded
|
||||
? OVRInput.Controller.LTouch
|
||||
: OVRInput.Controller.RTouch;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Set device title
|
||||
string deviceTitle = $"{ToDeviceModel()} [{ToHandednessString(m_handedness)}]";
|
||||
m_title.SetText(deviceTitle);
|
||||
|
||||
// Set status flags
|
||||
string connectionState = OVRInput.IsControllerConnected(m_controller)
|
||||
? "<color=#66ff87>o</color>"
|
||||
: "<color=#ff8991>x</color>";
|
||||
bool isTracked = OVRInput.GetControllerOrientationTracked(m_controller) &&
|
||||
OVRInput.GetControllerPositionTracked(m_controller);
|
||||
string trackingState = isTracked ? "<color=#66ff87>o</color>" : "<color=#ff8991>x</color>";
|
||||
m_status.SetText($"Connected [{connectionState}] Tracked [{trackingState}]");
|
||||
|
||||
// ThumbRest force and triggers
|
||||
m_thumbRestTouch.SetValue(OVRInput.Get(OVRInput.Touch.PrimaryThumbRest, m_controller));
|
||||
m_indexTrigger.SetValue(OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, m_controller));
|
||||
m_gripTrigger.SetValue(OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, m_controller));
|
||||
|
||||
m_thumbRestForce.SetValue(OVRInput.Get(OVRInput.Axis1D.PrimaryThumbRestForce, m_controller));
|
||||
|
||||
// Stylus tip
|
||||
m_stylusTipForce.SetValue(OVRInput.Get(OVRInput.Axis1D.PrimaryStylusForce, m_controller));
|
||||
|
||||
// Index capsense
|
||||
m_indexCurl1d.SetValue(OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTriggerCurl, m_controller));
|
||||
m_indexSlider1d.SetValue(OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTriggerSlide, m_controller));
|
||||
|
||||
// Face buttons
|
||||
m_ax.SetValue(OVRInput.Get(OVRInput.Button.One, m_controller));
|
||||
m_axTouch.SetValue(OVRInput.Get(OVRInput.Touch.One, m_controller));
|
||||
m_by.SetValue(OVRInput.Get(OVRInput.Button.Two, m_controller));
|
||||
m_byTouch.SetValue(OVRInput.Get(OVRInput.Touch.Two, m_controller));
|
||||
;
|
||||
|
||||
// Index touch
|
||||
m_indexTouch.SetValue(OVRInput.Get(OVRInput.Touch.PrimaryIndexTrigger, m_controller));
|
||||
|
||||
// Thumbstick position & touch
|
||||
m_thumbstick.SetValue(OVRInput.Get(OVRInput.Touch.PrimaryThumbstick, m_controller),
|
||||
OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, m_controller));
|
||||
}
|
||||
|
||||
private static string ToDeviceModel()
|
||||
{
|
||||
return "Touch";
|
||||
}
|
||||
|
||||
private static string ToHandednessString(OVRInput.Handedness handedness)
|
||||
{
|
||||
switch (handedness)
|
||||
{
|
||||
case OVRInput.Handedness.LeftHanded:
|
||||
return "L";
|
||||
|
||||
case OVRInput.Handedness.RightHanded:
|
||||
return "R";
|
||||
}
|
||||
|
||||
return "-";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e6c7e66b7c8ee684ab35e741ee622a32
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,113 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
public class UiSceneMenu : MonoBehaviour
|
||||
{
|
||||
[Header("Settings")]
|
||||
[SerializeField] private VerticalLayoutGroup m_layoutGroup = null;
|
||||
|
||||
[SerializeField] private TextMeshProUGUI m_labelPf = null;
|
||||
|
||||
private static Vector2 s_lastThumbstickL;
|
||||
private static Vector2 s_lastThumbstickR;
|
||||
|
||||
private Scene m_activeScene;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
m_activeScene = SceneManager.GetActiveScene();
|
||||
|
||||
// Build labels
|
||||
for (int i = 0; i < SceneManager.sceneCountInBuildSettings; ++i)
|
||||
{
|
||||
string scenePath = SceneUtility.GetScenePathByBuildIndex(i);
|
||||
CreateLabel(i, scenePath);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
int sceneCount = SceneManager.sceneCountInBuildSettings;
|
||||
if (InputPrevScene())
|
||||
{
|
||||
ChangeScene((m_activeScene.buildIndex - 1 + sceneCount) % sceneCount);
|
||||
}
|
||||
else if (InputNextScene())
|
||||
{
|
||||
ChangeScene((m_activeScene.buildIndex + 1) % sceneCount);
|
||||
}
|
||||
|
||||
s_lastThumbstickL = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, OVRInput.Controller.LTouch);
|
||||
s_lastThumbstickR = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, OVRInput.Controller.RTouch);
|
||||
}
|
||||
|
||||
private bool InputPrevScene()
|
||||
{
|
||||
return KeyboardPrevScene() || ThumbstickPrevScene(OVRInput.Controller.LTouch) ||
|
||||
ThumbstickPrevScene(OVRInput.Controller.RTouch);
|
||||
}
|
||||
|
||||
private bool InputNextScene()
|
||||
{
|
||||
return KeyboardNextScene() || ThumbstickNextScene(OVRInput.Controller.LTouch) ||
|
||||
ThumbstickNextScene(OVRInput.Controller.RTouch);
|
||||
}
|
||||
|
||||
private bool KeyboardPrevScene()
|
||||
{
|
||||
return Input.GetKeyDown(KeyCode.UpArrow);
|
||||
}
|
||||
|
||||
private bool KeyboardNextScene()
|
||||
{
|
||||
return Input.GetKeyDown(KeyCode.DownArrow);
|
||||
}
|
||||
|
||||
private bool ThumbstickPrevScene(OVRInput.Controller controller)
|
||||
{
|
||||
return (OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, controller).y >= 0.9f) &&
|
||||
(GetLastThumbstickValue(controller).y < 0.9f);
|
||||
}
|
||||
|
||||
private bool ThumbstickNextScene(OVRInput.Controller controller)
|
||||
{
|
||||
return (OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, controller).y <= -0.9f) &&
|
||||
(GetLastThumbstickValue(controller).y > -0.9f);
|
||||
}
|
||||
|
||||
private Vector2 GetLastThumbstickValue(OVRInput.Controller controller)
|
||||
{
|
||||
return controller == OVRInput.Controller.LTouch ? s_lastThumbstickL : s_lastThumbstickR;
|
||||
}
|
||||
|
||||
private void ChangeScene(int nextScene)
|
||||
{
|
||||
SceneManager.LoadScene(nextScene);
|
||||
}
|
||||
|
||||
private void CreateLabel(int sceneIndex, string scenePath)
|
||||
{
|
||||
// Get the scene name
|
||||
string sceneName = System.IO.Path.GetFileNameWithoutExtension(scenePath);
|
||||
|
||||
// Add spaces after capital letters
|
||||
sceneName = Regex.Replace(sceneName, "[A-Z]", " $0").Trim();
|
||||
|
||||
// Call attention to the active scene
|
||||
bool isActiveScene = m_activeScene.buildIndex == sceneIndex;
|
||||
if (isActiveScene)
|
||||
{
|
||||
sceneName = $"Open: {sceneName}";
|
||||
}
|
||||
|
||||
// Create and set the label
|
||||
TextMeshProUGUI label = GameObject.Instantiate(m_labelPf);
|
||||
label.SetText($"{sceneIndex + 1}. {sceneName}");
|
||||
label.transform.SetParent(m_layoutGroup.transform, false);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 04938183eea4b0f458db0fd0a977d53a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,22 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class UiVectorInspector : MonoBehaviour
|
||||
{
|
||||
[Header("Components")]
|
||||
[SerializeField] private TextMeshProUGUI m_nameLabel = null;
|
||||
|
||||
[SerializeField] private TextMeshProUGUI m_valueLabel = null;
|
||||
|
||||
public void SetName(string name)
|
||||
{
|
||||
m_nameLabel.text = name;
|
||||
}
|
||||
|
||||
public void SetValue(bool value)
|
||||
{
|
||||
m_valueLabel.text = string.Format("[{0}]", value);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b5b953c396f406b44bfcbce884437b85
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user