// Copyright (c) Meta Platforms, Inc. and affiliates. using System; using System.Collections.Generic; using UnityEngine; namespace Oculus.Movement.Utils { /// /// Used to label lists and arrays with an Enum instead of the default 'Element #' /// public class EnumNamedArrayAttribute : PropertyAttribute { /// /// values replacing "Element X" when rendering lists in Unity Editor /// public Type TargetEnum; /// /// Cached names, to avoid multiple reflection invocations and allocations /// private static Dictionary _cachedNames = new Dictionary(); /// /// Used to label lists and arrays with an Enum instead of the default 'Element #' /// /// Which to use as a label public EnumNamedArrayAttribute(Type targetEnum) { TargetEnum = targetEnum; } /// /// Get cached names of enums. This method reduces memory thrash at Unity editor time /// public string[] GetNames() { return GetNames(TargetEnum); } private static string[] GetNames(Type enumType) { if (!_cachedNames.TryGetValue(enumType, out string[] names)) { _cachedNames[enumType] = names = Enum.GetNames(enumType); } return names; } } }