diff --git a/Source/Editor/CustomEditors/Editors/GuidEditor.cs b/Source/Editor/CustomEditors/Editors/GuidEditor.cs index 28d93aa8e..4573def77 100644 --- a/Source/Editor/CustomEditors/Editors/GuidEditor.cs +++ b/Source/Editor/CustomEditors/Editors/GuidEditor.cs @@ -1,8 +1,12 @@ // Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. using System; +using System.Linq; using FlaxEditor.CustomEditors.Elements; +using FlaxEditor.GUI; +using FlaxEditor.Scripting; using FlaxEngine; +using FlaxEngine.Utilities; namespace FlaxEditor.CustomEditors.Editors { @@ -13,6 +17,9 @@ namespace FlaxEditor.CustomEditors.Editors public sealed class GuidEditor : CustomEditor { private TextBoxElement _element; + private AssetPicker _picker; + private bool _isReference; + private bool _isRefreshing; /// public override DisplayStyle Style => DisplayStyle.Inline; @@ -20,8 +27,55 @@ namespace FlaxEditor.CustomEditors.Editors /// public override void Initialize(LayoutElementsContainer layout) { - _element = layout.TextBox(); - _element.TextBox.EditEnd += OnEditEnd; + var attributes = Values.GetAttributes(); + var assetReference = (AssetReferenceAttribute)attributes?.FirstOrDefault(x => x is AssetReferenceAttribute); + if (assetReference != null) + { + _picker = layout.Custom().CustomControl; + ScriptType assetType = new ScriptType(); + + float height = 48; + if (assetReference.UseSmallPicker) + height = 32; + + if (string.IsNullOrEmpty(assetReference.TypeName)) + { + assetType = ScriptType.Void; + } + else if (assetReference.TypeName.Length > 1 && assetReference.TypeName[0] == '.') + { + // Generic file picker + assetType = ScriptType.Null; + _picker.Validator.FileExtension = assetReference.TypeName; + } + else + { + var customType = TypeUtils.GetType(assetReference.TypeName); + if (customType != ScriptType.Null) + assetType = customType; + else if (!Content.Settings.GameSettings.OptionalPlatformSettings.Contains(assetReference.TypeName)) + Debug.LogWarning(string.Format("Unknown asset type '{0}' to use for asset picker filter.", assetReference.TypeName)); + else + assetType = ScriptType.Void; + } + + _picker.Validator.AssetType = assetType; + _picker.Height = height; + _picker.SelectedItemChanged += OnSelectedItemChanged; + _isReference = true; + } + else + { + _element = layout.TextBox(); + _element.TextBox.EditEnd += OnEditEnd; + } + } + + private void OnSelectedItemChanged() + { + if (_isRefreshing) + return; + SetValue(_picker.Validator.SelectedID); } private void OnEditEnd() @@ -36,17 +90,32 @@ namespace FlaxEditor.CustomEditors.Editors public override void Refresh() { base.Refresh(); - + _isRefreshing = true; if (HasDifferentValues) { - _element.TextBox.Text = string.Empty; - _element.TextBox.WatermarkText = "Different values"; + if (_isReference) + { + // Not supported + } + else + { + _element.TextBox.Text = string.Empty; + _element.TextBox.WatermarkText = "Different values"; + } } else { - _element.TextBox.Text = ((Guid)Values[0]).ToString("D"); - _element.TextBox.WatermarkText = string.Empty; + if (_isReference) + { + _picker.Validator.SelectedID = (Guid)Values[0]; + } + else + { + _element.TextBox.Text = ((Guid)Values[0]).ToString("D"); + _element.TextBox.WatermarkText = string.Empty; + } } + _isRefreshing = false; } } }