/* * SPDX-License-Identifier: AGPL-3.0-or-later * Copyright (C) 2025 Sergej Görzen * This file is part of OmiLAXR. */ using OmiLAXR.Extensions; using UnityEngine; namespace OmiLAXR.Components { /// /// Component that allows setting a custom tracking name for a GameObject. /// This overrides the default tracking name behavior. /// [AddComponentMenu("OmiLAXR / Game Objects / Custom Tracking Name")] [DisallowMultipleComponent] public sealed class CustomTrackingName : MonoBehaviour { /// /// The custom tracking name to use for this GameObject. /// If empty, falls back to default tracking name behavior. /// [Tooltip("Alternative tracking name.")] public string customTrackingName = ""; } /// /// Extension methods for handling custom tracking names on Unity Objects. /// public static class ObjectExtCustomTrackingName { /// /// Gets the CustomTrackingName component from a Unity Object. /// /// The Unity Object to get the component from. /// The CustomTrackingName component if found; null otherwise. public static CustomTrackingName GetCustomTrackingNameComponent(this Object obj) { if (obj is Component comp) { return comp.GetComponent(); } return ((GameObject)obj).GetComponent(); } /// /// Gets the tracking name for a Unity Object, considering custom tracking names and global settings. /// /// The Unity Object to get the tracking name for. /// /// The custom tracking name if set; otherwise returns either the full hierarchy path /// or the object's name based on global settings. /// public static string GetTrackingName(this Object obj) { var customTrackingNameComp = GetCustomTrackingNameComponent(obj); if (customTrackingNameComp) return customTrackingNameComp.customTrackingName; var trackingNameBehaviour = GlobalSettings.Instance.trackingNameBehaviour; return trackingNameBehaviour == GlobalSettings.TrackingNameBehaviour.HierarchyTreePath ? obj.GetFullHierarchyPath() : obj.name; } } }