// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using Microsoft.MixedReality.Toolkit.Editor; using System.Collections.Generic; using UnityEditor; using UnityEngine; namespace Microsoft.MixedReality.Toolkit.Physics.Editor { /// /// Renders the physics layer dropdown based on the current layers set in the Tag Manager. /// [CustomPropertyDrawer(typeof(PhysicsLayerAttribute))] public sealed class PhysicsLayerAttributeDrawer : PropertyDrawer { public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var guiContents = new List(); var layerIds = new List(); for (int i = 0; i < EditorLayerExtensions.TagManagerLayers.arraySize; i++) { var layer = EditorLayerExtensions.TagManagerLayers.GetArrayElementAtIndex(i); if (!string.IsNullOrWhiteSpace(layer.stringValue)) { guiContents.Add(new GUIContent($"{i}: {layer.stringValue}")); layerIds.Add(i); } } property.intValue = EditorGUI.IntPopup(position, label, property.intValue, guiContents.ToArray(), layerIds.ToArray()); } } }