/* * 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 { [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 = "{0}"; public RectTransform ChildArea => _childArea; private ITreeNode _boundNode; private bool _isRoot = false; private bool _isDuplicate = false; public void Bind(ITreeNode 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 node) { string label = _isDuplicate ? "" : ""; if (node.Value is UnityEngine.Object obj) { label += obj.name + " - "; } label += string.Format(OBJNAME_FORMAT, node.Value.GetType().Name); return label; } } }