/* * 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. */ #nullable enable using System.Collections; using Oculus.Avatar2; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.SceneManagement; using UnityEngine.UI; public class UIWindowController : MonoBehaviour { private const string logScope = "UIWindowController"; [System.Serializable] public enum UISectionType { Overview, Scenes, Settings, Controls, Logs, [HideInInspector] Invalid, } [System.Serializable] public struct UISection { public UISectionType sectionType; public GameObject sectionPanel; public GameObject tabButton; public ScrollRect scrollArea; } [SerializeField] private UISection[]? sections; [SerializeField] private Text? sceneNameText; [SerializeField] private GameObject? uiInstructionTextGameObject; [SerializeField] private GameObject? uiSectionTabsParentGameObject; private int _currentActiveSectionIndex = 0; private bool _initialized; private void Awake() { if (sections == null || sections.Length < 1) { OvrAvatarLog.LogError("UIWindowController::Awake : Empty 'Sections'. This could be due to an empty field from the inspector.", logScope); return; } if (uiInstructionTextGameObject == null) { OvrAvatarLog.LogError("UIWindowController::Awake : Null uiInstructionTextGameObject. This could be due to an empty field from the inspector.", logScope); return; } if (uiSectionTabsParentGameObject == null) { OvrAvatarLog.LogError("UIWindowController::Awake : Null uiSectionTabsParentGameObject. This could be due to an empty field from the inspector.", logScope); return; } uiInstructionTextGameObject.SetActive(true); uiSectionTabsParentGameObject.SetActive(true); foreach (var section in sections) { var textComponent = section.tabButton.GetComponentInChildren(); if (textComponent) { textComponent.text = section.sectionType.ToString(); } section.sectionPanel.SetActive(false); } if (sceneNameText != null) { sceneNameText.gameObject.SetActive(true); sceneNameText.text = SceneManager.GetActiveScene().name; } } private void UpdateTabHighlight(int index) { if (sections == null || sections.Length < 1) { OvrAvatarLog.LogError("UIWindowController::UpdateTabHighlight : Empty 'Sections'. This could be due to an empty 'Sections' field from the inspector.", logScope); return; } if (index >= sections.Length || index < 0) { OvrAvatarLog.LogError($"UIWindowController::UpdateTabHighlights : index '{index}' out of bounds.", logScope); return; } var button = sections[index].tabButton.GetComponentInChildren