Initial Commit
This commit is contained in:
+93
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user