Initialer Upload neues Unity-Projekt

This commit is contained in:
Daniel Ocks
2025-07-21 09:11:14 +02:00
commit eeca72985b
14558 changed files with 1508140 additions and 0 deletions

View File

@ -0,0 +1,62 @@
/*
* 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 Oculus.Interaction.DebugTree;
using System;
using System.Collections.Generic;
namespace Oculus.Interaction.PoseDetection.Debug
{
public class ActiveStateDebugTree : DebugTree<IActiveState>
{
public ActiveStateDebugTree(IActiveState root) : base(root)
{
}
private static Dictionary<Type, IActiveStateModel> _models =
new Dictionary<Type, IActiveStateModel>();
public static void RegisterModel<TType>(IActiveStateModel stateModel)
where TType : class, IActiveState
{
Type key = typeof(TType);
if (_models.ContainsKey(key))
{
_models[key] = stateModel;
}
else
{
_models.Add(key, stateModel);
}
}
protected override bool TryGetChildren(IActiveState node, out IEnumerable<IActiveState> children)
{
if (_models.TryGetValue(node.GetType(), out IActiveStateModel model)
&& model != null)
{
children = model.GetChildren(node);
return true;
}
children = null;
return false;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 98347ac4d9a23ac4c84b5eea4c0291d4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,57 @@
/*
* 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 Oculus.Interaction.DebugTree;
using UnityEngine;
namespace Oculus.Interaction.PoseDetection.Debug
{
public class ActiveStateDebugTreeUI : DebugTreeUI<IActiveState>
{
[Tooltip("The IActiveState to debug.")]
[SerializeField, Interface(typeof(IActiveState))]
private UnityEngine.Object _activeState;
[Tooltip("The node prefab which will be used to build the visual tree.")]
[SerializeField, Interface(typeof(INodeUI<IActiveState>))]
private UnityEngine.Component _nodePrefab;
protected override IActiveState Value
{
get => _activeState as IActiveState;
}
protected override INodeUI<IActiveState> NodePrefab
{
get => _nodePrefab as INodeUI<IActiveState>;
}
protected override DebugTree<IActiveState> InstantiateTree(IActiveState value)
{
return new ActiveStateDebugTree(value);
}
protected override string TitleForValue(IActiveState value)
{
Object obj = value as Object;
return obj != null ? obj.name : "";
}
}
}

View File

@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: 8ff3d6159be4e004f8ae25b5fcf864bb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- _activeState: {instanceID: 0}
- _nodePrefab: {fileID: 4289178980685552619, guid: bcb4af79d88c4af4a90fb6e19de13e70,
type: 3}
- _topLevel: {instanceID: 0}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,80 @@
/*
* 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;
namespace Oculus.Interaction.PoseDetection.Debug
{
public class ActiveStateDebugVisual : MonoBehaviour
{
[Tooltip("The IActiveState to debug.")]
[SerializeField, Interface(typeof(IActiveState))]
private UnityEngine.Object _activeState;
private IActiveState ActiveState { get; set; }
[Tooltip("The renderer used for the color change.")]
[SerializeField]
private Renderer _target;
[Tooltip("The renderer will be set to this color " +
"when ActiveState is inactive.")]
[SerializeField]
private Color _normalColor = Color.red;
[Tooltip("The renderer will be set to this color " +
"when ActiveState is active.")]
[SerializeField]
private Color _activeColor = Color.green;
private Material _material;
private bool _lastActiveValue = false;
protected virtual void Awake()
{
ActiveState = _activeState as IActiveState;
this.AssertField(ActiveState, nameof(ActiveState));
this.AssertField(_target, nameof(_target));
_material = _target.material;
SetMaterialColor(_lastActiveValue ? _activeColor : _normalColor);
}
private void OnDestroy()
{
Destroy(_material);
}
protected virtual void Update()
{
bool isActive = ActiveState.Active;
if (_lastActiveValue != isActive)
{
SetMaterialColor(isActive ? _activeColor : _normalColor);
_lastActiveValue = isActive;
}
}
private void SetMaterialColor(Color activeColor)
{
_material.color = activeColor;
_target.enabled = _material.color.a > 0.0f;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 38d73b2d0c0ee504587e0237ec474ca4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,45 @@
/*
* 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.Linq;
namespace Oculus.Interaction.PoseDetection.Debug
{
public interface IActiveStateModel
{
IEnumerable<IActiveState> GetChildren(IActiveState activeState);
}
public abstract class ActiveStateModel<TActiveState> : IActiveStateModel
where TActiveState : class, IActiveState
{
public IEnumerable<IActiveState> GetChildren(IActiveState activeState)
{
if (activeState is TActiveState type)
{
return GetChildren(type);
}
return Enumerable.Empty<IActiveState>();
}
protected abstract IEnumerable<IActiveState> GetChildren(TActiveState activeState);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3ed4598c08239c94fa439c2921b27349
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,93 @@
/*
* 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;
using TMPro;
using UnityEngine.UI;
using UnityEngine.Assertions;
using Oculus.Interaction.DebugTree;
namespace Oculus.Interaction.PoseDetection.Debug
{
public class ActiveStateNodeUIHorizontal : MonoBehaviour, INodeUI<IActiveState>
{
[SerializeField]
private RectTransform _childArea;
[SerializeField]
private RectTransform _connectingLine;
[SerializeField]
private TextMeshProUGUI _label;
[SerializeField]
private Image _activeImage;
[SerializeField]
private Color _activeColor = Color.green;
[SerializeField]
private Color _inactiveColor = Color.red;
private const string OBJNAME_FORMAT = "<color=#dddddd><size=85%>{0}</size></color>";
public RectTransform ChildArea => _childArea;
private ITreeNode<IActiveState> _boundNode;
private bool _isRoot = false;
private bool _isDuplicate = false;
public void Bind(ITreeNode<IActiveState> node, bool isRoot, bool isDuplicate)
{
Assert.IsNotNull(node);
_isRoot = isRoot;
_isDuplicate = isDuplicate;
_boundNode = node;
_label.text = GetLabelText(node);
}
protected virtual void Start()
{
this.AssertField(_childArea, nameof(_childArea));
this.AssertField(_connectingLine, nameof(_connectingLine));
this.AssertField(_activeImage, nameof(_activeImage));
this.AssertField(_label, nameof(_label));
}
protected virtual void Update()
{
_activeImage.color = _boundNode.Value.Active ? _activeColor : _inactiveColor;
_childArea.gameObject.SetActive(_childArea.childCount > 0);
_connectingLine.gameObject.SetActive(!_isRoot);
}
private string GetLabelText(ITreeNode<IActiveState> node)
{
string label = _isDuplicate ? "<i>" : "";
if (node.Value is UnityEngine.Object obj)
{
label += obj.name + System.Environment.NewLine;
}
label += string.Format(OBJNAME_FORMAT, node.Value.GetType().Name);
return label;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4bf41478a1af76e48b69aa772f7b81fd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,93 @@
/*
* 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;
using TMPro;
using UnityEngine.UI;
using UnityEngine.Assertions;
using Oculus.Interaction.DebugTree;
namespace Oculus.Interaction.PoseDetection.Debug
{
public class ActiveStateNodeUIVertical : MonoBehaviour, INodeUI<IActiveState>
{
[SerializeField]
private RectTransform _childArea;
[SerializeField]
private RectTransform _connectingLine;
[SerializeField]
private TextMeshProUGUI _label;
[SerializeField]
private Image _activeImage;
[SerializeField]
private Color _activeColor = Color.green;
[SerializeField]
private Color _inactiveColor = Color.red;
private const string OBJNAME_FORMAT = "<color=#dddddd><size=85%>{0}</size></color>";
public RectTransform ChildArea => _childArea;
private ITreeNode<IActiveState> _boundNode;
private bool _isRoot = false;
private bool _isDuplicate = false;
public void Bind(ITreeNode<IActiveState> node, bool isRoot, bool isDuplicate)
{
Assert.IsNotNull(node);
_isRoot = isRoot;
_isDuplicate = isDuplicate;
_boundNode = node;
_label.text = GetLabelText(node);
}
protected virtual void Start()
{
this.AssertField(_childArea, nameof(_childArea));
this.AssertField(_connectingLine, nameof(_connectingLine));
this.AssertField(_activeImage, nameof(_activeImage));
this.AssertField(_label, nameof(_label));
}
protected virtual void Update()
{
_activeImage.color = _boundNode.Value.Active ? _activeColor : _inactiveColor;
_childArea.gameObject.SetActive(_childArea.childCount > 0);
_connectingLine.gameObject.SetActive(!_isRoot);
}
private string GetLabelText(ITreeNode<IActiveState> node)
{
string label = _isDuplicate ? "<i>" : "";
if (node.Value is UnityEngine.Object obj)
{
label += obj.name + " - ";
}
label += string.Format(OBJNAME_FORMAT, node.Value.GetType().Name);
return label;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 10fca570a88ae124dbdb5dfda85fbbf6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,105 @@
/*
* 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 Oculus.Interaction.Input;
using TMPro;
using UnityEngine;
using UnityEngine.Assertions;
namespace Oculus.Interaction.PoseDetection.Debug
{
public class FingerFeatureDebugVisual : MonoBehaviour
{
[SerializeField]
private Renderer _target;
[SerializeField]
private Color _normalColor = Color.red;
[SerializeField]
private Color _activeColor = Color.green;
[SerializeField]
private TextMeshPro _targetText;
private IFingerFeatureStateProvider _fingerFeatureState;
private Material _material;
private bool _lastActiveValue;
private HandFinger _handFinger;
private ShapeRecognizer.FingerFeatureConfig _featureConfig;
private bool _initialized;
protected virtual void Awake()
{
_material = _target.material;
this.AssertField(_material, nameof(_material));
this.AssertField(_targetText, nameof(_targetText));
_material.color = _lastActiveValue ? _activeColor : _normalColor;
}
protected virtual void OnDestroy()
{
Destroy(_material);
}
public void Initialize(HandFinger handFinger,
ShapeRecognizer.FingerFeatureConfig config,
IFingerFeatureStateProvider fingerFeatureState)
{
_initialized = true;
_handFinger = handFinger;
_featureConfig = config;
_fingerFeatureState = fingerFeatureState;
}
protected virtual void Update()
{
if (!_initialized)
{
return;
}
FingerFeature feature = _featureConfig.Feature;
bool isActive = false;
if (_fingerFeatureState.GetCurrentState(_handFinger, feature,
out string currentState))
{
float? featureVal = _fingerFeatureState.GetFeatureValue(_handFinger, feature);
isActive = _fingerFeatureState.IsStateActive(_handFinger, feature, _featureConfig.Mode, _featureConfig.State);
string featureValStr = featureVal.HasValue ? featureVal.Value.ToString("F2") : "--";
_targetText.text = $"{_handFinger} {feature}" + $"{currentState} ({featureValStr})";
}
else
{
_targetText.text = $"{_handFinger} {feature}\n";
}
if (isActive != _lastActiveValue)
{
_material.color = isActive ? _activeColor : _normalColor;
_lastActiveValue = isActive;
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 89e8f8c35caba0c4abef1bdd8890c640
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,146 @@
/*
* 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 Oculus.Interaction.Input;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Assertions;
namespace Oculus.Interaction.PoseDetection.Debug
{
public class FingerFeatureSkeletalDebugVisual : MonoBehaviour
{
[SerializeField]
private FingerFeatureStateProvider _fingerFeatureStateProvider;
[SerializeField]
private LineRenderer _lineRenderer;
[SerializeField]
private Color _normalColor = Color.red;
[SerializeField]
private Color _activeColor = Color.green;
[SerializeField]
private float _lineWidth = 0.005f;
private IHand _hand;
private bool _lastFeatureActiveValue = false;
private IReadOnlyList<HandJointId> _jointsCovered = null;
private HandFinger _finger;
private ShapeRecognizer.FingerFeatureConfig _fingerFeatureConfig;
private bool _initializedPositions;
private bool _initialized;
protected virtual void Awake()
{
this.AssertField(_lineRenderer, nameof(_lineRenderer));
UpdateFeatureActiveValueAndVisual(false);
}
private void UpdateFeatureActiveValueAndVisual(bool newValue)
{
var colorToUse = newValue ? _activeColor : _normalColor;
_lineRenderer.startColor = colorToUse;
_lineRenderer.endColor = colorToUse;
_lastFeatureActiveValue = newValue;
}
public void Initialize(
IHand hand,
HandFinger finger,
ShapeRecognizer.FingerFeatureConfig fingerFeatureConfig)
{
_hand = hand;
_initialized = true;
this.AssertField(_fingerFeatureStateProvider, nameof(_fingerFeatureStateProvider));
var featureValueProvider = _fingerFeatureStateProvider.GetValueProvider(finger);
_jointsCovered = featureValueProvider.GetJointsAffected(
finger,
fingerFeatureConfig.Feature);
_finger = finger;
_fingerFeatureConfig = fingerFeatureConfig;
_initializedPositions = false;
}
protected virtual void Update()
{
if (!_initialized || !_hand.IsTrackedDataValid)
{
ToggleLineRendererEnableState(false);
return;
}
ToggleLineRendererEnableState(true);
UpdateDebugSkeletonLineRendererJoints();
UpdateFeatureActiveValue();
}
private void ToggleLineRendererEnableState(bool enableState)
{
if (_lineRenderer.enabled == enableState)
{
return;
}
_lineRenderer.enabled = enableState;
}
private void UpdateDebugSkeletonLineRendererJoints()
{
if (!_initializedPositions)
{
_lineRenderer.positionCount = _jointsCovered.Count;
_initializedPositions = true;
}
if (Mathf.Abs(_lineRenderer.startWidth - _lineWidth) > Mathf.Epsilon)
{
_lineRenderer.startWidth = _lineWidth;
_lineRenderer.endWidth = _lineWidth;
}
int numJoints = _jointsCovered.Count;
for (int i = 0; i < numJoints; i++)
{
if (_hand.GetJointPose(_jointsCovered[i], out Pose jointPose))
{
_lineRenderer.SetPosition(i, jointPose.position);
}
}
}
private void UpdateFeatureActiveValue()
{
bool isActive = _fingerFeatureStateProvider.IsStateActive(_finger, _fingerFeatureConfig.Feature,
_fingerFeatureConfig.Mode, _fingerFeatureConfig.State);
if (isActive != _lastFeatureActiveValue)
{
UpdateFeatureActiveValueAndVisual(isActive);
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: df12566059c64f34a8985d7383779198
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,154 @@
/*
* 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 Oculus.Interaction.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.Assertions;
namespace Oculus.Interaction.PoseDetection.Debug
{
public class HandShapeDebugVisual : MonoBehaviour
{
[SerializeField, Interface(typeof(IFingerFeatureStateProvider))]
private UnityEngine.Object _fingerFeatureStateProvider;
private IFingerFeatureStateProvider FingerFeatureStateProvider;
[SerializeField]
private ShapeRecognizerActiveState _shapeRecognizerActiveState;
[SerializeField]
private Renderer _target;
[SerializeField]
private Color _normalColor = Color.red;
[SerializeField]
private Color _activeColor = Color.green;
[SerializeField]
private GameObject _fingerFeatureDebugVisualPrefab;
[SerializeField]
private Transform _fingerFeatureParent;
[SerializeField]
private Vector3 _fingerSpacingVec = new Vector3(0.0f, -1.0f, 0.0f);
[SerializeField]
private Vector3 _fingerFeatureSpacingVec = new Vector3(1.0f, 0.0f, 0.0f);
[SerializeField]
private Vector3 _fingerFeatureDebugLocalScale = new Vector3(0.3f, 0.3f, 0.3f);
[SerializeField]
private TextMeshPro _targetText;
private Material _material;
private bool _lastActiveValue = false;
protected virtual void Awake()
{
FingerFeatureStateProvider = _fingerFeatureStateProvider as IFingerFeatureStateProvider;
this.AssertField(_shapeRecognizerActiveState, nameof(_shapeRecognizerActiveState));
this.AssertField(_target, nameof(_target));
this.AssertField(_fingerFeatureDebugVisualPrefab, nameof(_fingerFeatureDebugVisualPrefab));
this.AssertField(_targetText, nameof(_targetText));
_material = _target.material;
_material.color = _lastActiveValue ? _activeColor : _normalColor;
if (_fingerFeatureParent == null)
{
_fingerFeatureParent = transform;
}
}
protected virtual void Start()
{
this.AssertField(FingerFeatureStateProvider, nameof(FingerFeatureStateProvider));
Vector3 fingerOffset = Vector3.zero;
var statesByFinger = AllFeatureStates()
.GroupBy(s => s.Item1)
.Select(group => new
{
HandFinger = group.Key,
FingerFeatures = group.SelectMany(item => item.Item2)
});
foreach (var g in statesByFinger)
{
Vector3 fingerDebugFeatureTotalDisp = fingerOffset;
foreach (var config in g.FingerFeatures)
{
var fingerFeatureDebugVisInst = Instantiate(_fingerFeatureDebugVisualPrefab, _fingerFeatureParent);
var debugVisComp = fingerFeatureDebugVisInst.GetComponent<FingerFeatureDebugVisual>();
debugVisComp.Initialize(g.HandFinger, config, FingerFeatureStateProvider);
var debugVisTransform = debugVisComp.transform;
debugVisTransform.localScale = _fingerFeatureDebugLocalScale;
debugVisTransform.localRotation = Quaternion.identity;
debugVisTransform.localPosition = fingerDebugFeatureTotalDisp;
fingerDebugFeatureTotalDisp += _fingerFeatureSpacingVec;
}
fingerOffset += _fingerSpacingVec;
}
string shapeNames = "";
foreach (ShapeRecognizer shapeRecognizer in _shapeRecognizerActiveState.Shapes)
{
shapeNames += shapeRecognizer.ShapeName;
}
_targetText.text = $"{_shapeRecognizerActiveState.Handedness} Hand: {shapeNames} ";
}
private IEnumerable<ValueTuple<HandFinger, IReadOnlyList<ShapeRecognizer.FingerFeatureConfig>>> AllFeatureStates()
{
foreach (ShapeRecognizer shapeRecognizer in _shapeRecognizerActiveState.Shapes)
{
foreach (var handFingerConfigs in shapeRecognizer.GetFingerFeatureConfigs())
{
yield return handFingerConfigs;
}
}
}
protected virtual void OnDestroy()
{
Destroy(_material);
}
protected virtual void Update()
{
bool isActive = _shapeRecognizerActiveState.Active;
if (_lastActiveValue != isActive)
{
_material.color = isActive ? _activeColor : _normalColor;
_lastActiveValue = isActive;
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 53451bc1e24308a478c0a120ed9eae00
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,84 @@
/*
* 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 Oculus.Interaction.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Assertions;
namespace Oculus.Interaction.PoseDetection.Debug
{
public class HandShapeSkeletalDebugVisual : MonoBehaviour
{
[SerializeField]
private ShapeRecognizerActiveState _shapeRecognizerActiveState;
[SerializeField]
private GameObject _fingerFeatureDebugVisualPrefab;
protected virtual void Awake()
{
this.AssertField(_shapeRecognizerActiveState, nameof(_shapeRecognizerActiveState));
this.AssertField(_fingerFeatureDebugVisualPrefab, nameof(_fingerFeatureDebugVisualPrefab));
}
protected virtual void Start()
{
var statesByFinger = AllFeatureStates()
.GroupBy(s => s.Item1)
.Select(group => new
{
HandFinger = group.Key,
FingerFeatures = group.SelectMany(item => item.Item2)
});
foreach (var g in statesByFinger)
{
foreach (var feature in g.FingerFeatures)
{
var boneDebugObject = Instantiate(_fingerFeatureDebugVisualPrefab);
var skeletalComp = boneDebugObject.GetComponent<FingerFeatureSkeletalDebugVisual>();
skeletalComp.Initialize(_shapeRecognizerActiveState.Hand, g.HandFinger, feature);
var debugVisTransform = boneDebugObject.transform;
debugVisTransform.parent = this.transform;
debugVisTransform.localScale = Vector3.one;
debugVisTransform.localRotation = Quaternion.identity;
debugVisTransform.localPosition = Vector3.zero;
}
}
}
private IEnumerable<ValueTuple<HandFinger, IReadOnlyList<ShapeRecognizer.FingerFeatureConfig>>> AllFeatureStates()
{
foreach (ShapeRecognizer shapeRecognizer in _shapeRecognizerActiveState.Shapes)
{
foreach (var handFingerConfigs in shapeRecognizer.GetFingerFeatureConfigs())
{
yield return handFingerConfigs;
}
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 86fda5ce347f35d44a5c6faee65c6679
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,136 @@
/*
* 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;
using UnityEngine;
using System.Collections.Generic;
using UnityEngine.Assertions;
namespace Oculus.Interaction.PoseDetection.Debug
{
public class JointRotationDebugVisual : MonoBehaviour
{
[SerializeField]
private JointRotationActiveState _jointRotation;
[SerializeField]
private Material _lineRendererMaterial;
[SerializeField]
private float _rendererLineWidth = 0.005f;
[SerializeField]
private float _rendererLineLength = 0.1f;
private List<LineRenderer> _lineRenderers;
private int _enabledRendererCount;
protected bool _started = false;
protected virtual void Awake()
{
_lineRenderers = new List<LineRenderer>();
}
protected virtual void Start()
{
this.BeginStart(ref _started);
this.AssertField(_jointRotation, nameof(_jointRotation));
this.AssertField(_lineRendererMaterial, nameof(_lineRendererMaterial));
this.EndStart(ref _started);
}
protected virtual void OnDisable()
{
if (_started)
{
ResetLines();
}
}
protected virtual void Update()
{
ResetLines();
foreach (var config in _jointRotation.FeatureConfigs)
{
if (_jointRotation.Hand.GetJointPose(config.Feature, out Pose jointPose) &&
_jointRotation.FeatureStates.TryGetValue(config, out var state))
{
DrawDebugLine(jointPose.position, state.TargetAxis, state.Amount);
}
}
}
private void DrawDebugLine(Vector3 jointPos, Vector3 direction, float amount)
{
Vector3 fullLength = direction.normalized * _rendererLineLength;
bool metThreshold = amount >= 1f;
if (metThreshold)
{
AddLine(jointPos, jointPos + fullLength, Color.green);
}
else
{
Vector3 breakpoint = Vector3.Lerp(jointPos, jointPos + fullLength, amount);
AddLine(jointPos, breakpoint, Color.yellow);
AddLine(breakpoint, jointPos + fullLength, Color.red);
}
}
private void ResetLines()
{
foreach (var lineRenderer in _lineRenderers)
{
if (lineRenderer != null)
{
lineRenderer.enabled = false;
}
}
_enabledRendererCount = 0;
}
private void AddLine(Vector3 start, Vector3 end, Color color)
{
LineRenderer lineRenderer;
if (_enabledRendererCount == _lineRenderers.Count)
{
lineRenderer = new GameObject().AddComponent<LineRenderer>();
lineRenderer.startWidth = _rendererLineWidth;
lineRenderer.endWidth = _rendererLineWidth;
lineRenderer.positionCount = 2;
lineRenderer.material = _lineRendererMaterial;
_lineRenderers.Add(lineRenderer);
}
else
{
lineRenderer = _lineRenderers[_enabledRendererCount];
}
_enabledRendererCount++;
lineRenderer.enabled = true;
lineRenderer.SetPosition(0, start);
lineRenderer.SetPosition(1, end);
lineRenderer.startColor = color;
lineRenderer.endColor = color;
}
}
}

View File

@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: c4aa7ca7fb2a2214ead03b478fe55005
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- _jointRotation: {instanceID: 0}
- _lineRendererMaterial: {fileID: 10306, guid: 0000000000000000f000000000000000,
type: 0}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,136 @@
/*
* 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;
using UnityEngine;
using System.Collections.Generic;
using UnityEngine.Assertions;
namespace Oculus.Interaction.PoseDetection.Debug
{
public class JointVelocityDebugVisual : MonoBehaviour
{
[SerializeField]
private JointVelocityActiveState _jointVelocity;
[SerializeField]
private Material _lineRendererMaterial;
[SerializeField]
private float _rendererLineWidth = 0.005f;
[SerializeField]
private float _rendererLineLength = 0.1f;
private List<LineRenderer> _lineRenderers;
private int _enabledRendererCount;
protected bool _started = false;
protected virtual void Awake()
{
_lineRenderers = new List<LineRenderer>();
}
protected virtual void Start()
{
this.BeginStart(ref _started);
this.AssertField(_jointVelocity, nameof(_jointVelocity));
this.AssertField(_lineRendererMaterial, nameof(_lineRendererMaterial));
this.EndStart(ref _started);
}
protected virtual void OnDisable()
{
if (_started)
{
ResetLines();
}
}
protected virtual void Update()
{
ResetLines();
foreach (var config in _jointVelocity.FeatureConfigs)
{
if (_jointVelocity.Hand.GetJointPose(config.Feature, out Pose jointPose) &&
_jointVelocity.FeatureStates.TryGetValue(config, out var state))
{
DrawDebugLine(jointPose.position, state.TargetVector, state.Amount);
}
}
}
private void DrawDebugLine(Vector3 jointPos, Vector3 direction, float amount)
{
Vector3 fullLength = direction.normalized * _rendererLineLength;
bool metThreshold = amount >= 1f;
if (metThreshold)
{
AddLine(jointPos, jointPos + fullLength, Color.green);
}
else
{
Vector3 breakpoint = Vector3.Lerp(jointPos, jointPos + fullLength, amount);
AddLine(jointPos, breakpoint, Color.yellow);
AddLine(breakpoint, jointPos + fullLength, Color.red);
}
}
private void ResetLines()
{
foreach (var lineRenderer in _lineRenderers)
{
if (lineRenderer != null)
{
lineRenderer.enabled = false;
}
}
_enabledRendererCount = 0;
}
private void AddLine(Vector3 start, Vector3 end, Color color)
{
LineRenderer lineRenderer;
if (_enabledRendererCount == _lineRenderers.Count)
{
lineRenderer = new GameObject().AddComponent<LineRenderer>();
lineRenderer.startWidth = _rendererLineWidth;
lineRenderer.endWidth = _rendererLineWidth;
lineRenderer.positionCount = 2;
lineRenderer.material = _lineRendererMaterial;
_lineRenderers.Add(lineRenderer);
}
else
{
lineRenderer = _lineRenderers[_enabledRendererCount];
}
_enabledRendererCount++;
lineRenderer.enabled = true;
lineRenderer.SetPosition(0, start);
lineRenderer.SetPosition(1, end);
lineRenderer.startColor = color;
lineRenderer.endColor = color;
}
}
}

View File

@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: ad4c672f99cfab247af90b55917b90f5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- _jointVelocity: {instanceID: 0}
- _lineRendererMaterial: {fileID: 10306, guid: 0000000000000000f000000000000000,
type: 0}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,118 @@
/*
* 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 Oculus.Interaction.Input;
using TMPro;
using UnityEngine;
using UnityEngine.Assertions;
namespace Oculus.Interaction.PoseDetection.Debug
{
public class TransformFeatureDebugVisual : MonoBehaviour
{
[SerializeField]
private Renderer _target;
[SerializeField]
private Color _normalColor = Color.red;
[SerializeField]
private Color _activeColor = Color.green;
[SerializeField]
private TextMeshPro _targetText;
private TransformFeatureStateProvider _transformFeatureStateProvider;
private TransformRecognizerActiveState _transformRecognizerActiveState;
private Material _material;
private bool _lastActiveValue;
private TransformFeatureConfig _targetConfig;
private bool _initialized;
private Handedness _handedness;
protected virtual void Awake()
{
_material = _target.material;
this.AssertField(_material, nameof(_material));
this.AssertField(_targetText, nameof(_targetText));
_material.color = _lastActiveValue ? _activeColor : _normalColor;
}
private void OnDestroy()
{
Destroy(_material);
}
public void Initialize(
Handedness handedness,
TransformFeatureConfig targetConfig,
TransformFeatureStateProvider transformFeatureStateProvider,
TransformRecognizerActiveState transformActiveState)
{
_handedness = handedness;
_initialized = true;
_transformFeatureStateProvider = transformFeatureStateProvider;
_transformRecognizerActiveState = transformActiveState;
_targetConfig = targetConfig;
}
protected virtual void Update()
{
if (!_initialized)
{
return;
}
bool isActive = false;
TransformFeature feature = _targetConfig.Feature;
if (_transformFeatureStateProvider.GetCurrentState(
_transformRecognizerActiveState.TransformConfig,
feature,
out string currentState))
{
float? featureVal = _transformFeatureStateProvider.GetFeatureValue(
_transformRecognizerActiveState.TransformConfig, feature);
isActive = _transformFeatureStateProvider.IsStateActive(
_transformRecognizerActiveState.TransformConfig,
feature,
_targetConfig.Mode,
_targetConfig.State);
string featureValStr = featureVal.HasValue ? featureVal.Value.ToString("F2") : "--";
_targetText.text = $"{feature}\n" +
$"{currentState} ({featureValStr})";
}
else
{
_targetText.text = $"{feature}\n";
}
if (isActive != _lastActiveValue)
{
_material.color = isActive ? _activeColor : _normalColor;
_lastActiveValue = isActive;
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9390f6f5772c6d942a736437d338b667
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,69 @@
/*
* 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;
using UnityEngine.Assertions;
namespace Oculus.Interaction.PoseDetection.Debug
{
public class TransformFeatureVectorDebugParentVisual : MonoBehaviour
{
[SerializeField]
private TransformRecognizerActiveState _transformRecognizerActiveState;
[SerializeField]
private GameObject _vectorVisualPrefab;
public void GetTransformFeatureVectorAndWristPos(TransformFeature feature,
bool isHandVector, ref Vector3? featureVec, ref Vector3? wristPos)
{
_transformRecognizerActiveState.GetFeatureVectorAndWristPos(feature, isHandVector,
ref featureVec, ref wristPos);
}
protected virtual void Awake()
{
this.AssertField(_transformRecognizerActiveState, nameof(_transformRecognizerActiveState));
this.AssertField(_vectorVisualPrefab, nameof(_vectorVisualPrefab));
}
protected virtual void Start()
{
var featureConfigs = _transformRecognizerActiveState.FeatureConfigs;
foreach (var featureConfig in featureConfigs)
{
var feature = featureConfig.Feature;
CreateVectorDebugView(feature, false);
CreateVectorDebugView(feature, true);
}
}
private void CreateVectorDebugView(TransformFeature feature, bool trackingHandVector)
{
var featureDebugVis = Instantiate(_vectorVisualPrefab, this.transform);
var debugVisComp = featureDebugVis.GetComponent<TransformFeatureVectorDebugVisual>();
debugVisComp.Initialize(feature, trackingHandVector, this, trackingHandVector ?
Color.blue : Color.black);
var debugVisTransform = debugVisComp.transform;
debugVisTransform.localRotation = Quaternion.identity;
debugVisTransform.localPosition = Vector3.zero;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8cd27ccbb9a942e47a1b2bfd53f957e4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,101 @@
/*
* 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 Oculus.Interaction.Input;
using UnityEngine;
using UnityEngine.Assertions;
namespace Oculus.Interaction.PoseDetection.Debug
{
public class TransformFeatureVectorDebugVisual : MonoBehaviour
{
public IHand Hand { get; private set; }
[SerializeField]
private LineRenderer _lineRenderer;
[SerializeField]
private float _lineWidth = 0.005f;
[SerializeField]
private float _lineScale = 0.1f;
private bool _isInitialized = false;
private TransformFeature _feature;
private TransformFeatureVectorDebugParentVisual _parent;
private bool _trackingHandVector = false;
protected virtual void Awake()
{
this.AssertField(_lineRenderer, nameof(_lineRenderer));
_lineRenderer.enabled = false;
}
public void Initialize(TransformFeature feature,
bool trackingHandVector,
TransformFeatureVectorDebugParentVisual parent,
Color lineColor)
{
_isInitialized = true;
_lineRenderer.enabled = true;
_lineRenderer.positionCount = 2;
_lineRenderer.startColor = lineColor;
_lineRenderer.endColor = lineColor;
_feature = feature;
_trackingHandVector = trackingHandVector;
_parent = parent;
}
protected virtual void Update()
{
if (!_isInitialized)
{
return;
}
Vector3? featureVec = null;
Vector3? wristPos = null;
_parent.GetTransformFeatureVectorAndWristPos(_feature,
_trackingHandVector, ref featureVec, ref wristPos);
if (featureVec == null || wristPos == null)
{
if (_lineRenderer.enabled)
{
_lineRenderer.enabled = false;
}
return;
}
if (!_lineRenderer.enabled)
{
_lineRenderer.enabled = true;
}
if (Mathf.Abs(_lineRenderer.startWidth - _lineWidth) > Mathf.Epsilon)
{
_lineRenderer.startWidth = _lineWidth;
_lineRenderer.endWidth = _lineWidth;
}
_lineRenderer.SetPosition(0, wristPos.Value);
_lineRenderer.SetPosition(1, wristPos.Value + _lineScale*featureVec.Value);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e5b3b9e0179019c46a27bcc4ed7916ff
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,140 @@
/*
* 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 Oculus.Interaction.Input;
using System;
using TMPro;
using UnityEngine;
using UnityEngine.Assertions;
namespace Oculus.Interaction.PoseDetection.Debug
{
public class TransformRecognizerDebugVisual : MonoBehaviour
{
[SerializeField]
private Hand _hand;
[SerializeField]
private TransformFeatureStateProvider _transformFeatureStateProvider;
[SerializeField]
private TransformRecognizerActiveState _transformRecognizerActiveState;
[SerializeField]
private Renderer _target;
[SerializeField]
private Color _normalColor = Color.red;
[SerializeField]
private Color _activeColor = Color.green;
[SerializeField]
private GameObject _transformFeatureDebugVisualPrefab;
[SerializeField]
private Transform _debugVisualParent;
[SerializeField]
private Vector3 _featureSpacingVec = new Vector3(1.0f, 0.0f, 0.0f);
[SerializeField]
private Vector3 _featureDebugLocalScale = new Vector3(0.3f, 0.3f, 0.3f);
[SerializeField]
private TextMeshPro _targetText;
private Material _material;
private bool _lastActiveValue = false;
protected virtual void Awake()
{
this.AssertField(_hand, nameof(_hand));
this.AssertField(_transformRecognizerActiveState, nameof(_transformRecognizerActiveState));
this.AssertField(_target, nameof(_target));
this.AssertField(_transformFeatureDebugVisualPrefab, nameof(_transformFeatureDebugVisualPrefab));
this.AssertField(_targetText, nameof(_targetText));
_material = _target.material;
_material.color = _lastActiveValue ? _activeColor : _normalColor;
if (_debugVisualParent == null)
{
_debugVisualParent = transform;
}
}
protected virtual void Start()
{
Vector3 totalDisp = Vector3.zero;
string shapeNames = "";
this.AssertField(_transformFeatureStateProvider, nameof(_transformFeatureStateProvider));
var featureConfigs = _transformRecognizerActiveState.FeatureConfigs;
foreach (var featureConfig in featureConfigs)
{
var featureDebugVis = Instantiate(_transformFeatureDebugVisualPrefab, _debugVisualParent);
var debugVisComp = featureDebugVis.GetComponent<TransformFeatureDebugVisual>();
debugVisComp.Initialize(_transformRecognizerActiveState.Hand.Handedness,
featureConfig,
_transformFeatureStateProvider,
_transformRecognizerActiveState);
var debugVisTransform = debugVisComp.transform;
debugVisTransform.localScale = _featureDebugLocalScale;
debugVisTransform.localRotation = Quaternion.identity;
debugVisTransform.localPosition = totalDisp;
totalDisp += _featureSpacingVec;
if (!String.IsNullOrEmpty(shapeNames)) { shapeNames += "\n "; }
shapeNames += $"{featureConfig.Mode} {featureConfig.State} ({_transformRecognizerActiveState.Hand.Handedness})";
}
_targetText.text = $"{shapeNames}";
}
private void OnDestroy()
{
Destroy(_material);
}
private bool AllActive()
{
if (!_transformRecognizerActiveState.Active)
{
return false;
}
return true;
}
protected virtual void Update()
{
bool isActive = AllActive();
if (_lastActiveValue != isActive)
{
_material.color = isActive ? _activeColor : _normalColor;
_lastActiveValue = isActive;
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: aca13d9f89c0c904a8d62bde280f5b52
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: