diff --git a/Source/Editor/CustomEditors/Editors/ControlReferenceEditor.cs b/Source/Editor/CustomEditors/Editors/ControlReferenceEditor.cs index 8a0595a0f..d7bbf1502 100644 --- a/Source/Editor/CustomEditors/Editors/ControlReferenceEditor.cs +++ b/Source/Editor/CustomEditors/Editors/ControlReferenceEditor.cs @@ -85,7 +85,7 @@ public class UIControlRefPickerControl : Control // Update tooltip if (_value is SceneObject sceneObject) - TooltipText = FlaxEditor.Utilities.Utils.GetTooltip(sceneObject); + TooltipText = Utilities.Utils.GetTooltip(sceneObject); else TooltipText = string.Empty; @@ -93,6 +93,15 @@ public class UIControlRefPickerControl : Control } } + /// + /// Gets or sets the selected object value by identifier. + /// + public Guid ValueID + { + get => _value ? _value.ID : Guid.Empty; + set => Value = Object.Find(ref value); + } + /// /// Initializes a new instance of the class. /// @@ -123,7 +132,7 @@ public class UIControlRefPickerControl : Control private bool IsValid(Actor actor) { - return actor is UIControl a && a.Control.GetType() == _controlType; + return actor == null || actor is UIControl a && a.Control.GetType() == _controlType; } /// @@ -263,7 +272,7 @@ public class UIControlRefPickerControl : Control _isMouseDown = false; // Highlight actor or script reference - if (!_hasValidDragOver && !IsDragOver) + if (!_hasValidDragOver && !IsDragOver && nameRect.Contains(location)) { Actor actor = _value; if (actor != null) @@ -275,7 +284,7 @@ public class UIControlRefPickerControl : Control } else { - _linkedTreeNode = FlaxEditor.Editor.Instance.Scene.GetActorNode(actor).TreeNode; + _linkedTreeNode = Editor.Instance.Scene.GetActorNode(actor).TreeNode; _linkedTreeNode.ExpandAllParents(); Editor.Instance.Windows.SceneWin.SceneTreePanel.ScrollViewTo(_linkedTreeNode, true); _linkedTreeNode.StartHighlight(); @@ -455,7 +464,7 @@ public class ControlReferenceEditor : CustomEditor }; } } - + /// public override void Refresh() { @@ -464,9 +473,7 @@ public class ControlReferenceEditor : CustomEditor if (!HasDifferentValues) { if (Values[0] is IControlReference cr) - { _element.CustomControl.Value = cr.UIControl; - } } } } diff --git a/Source/Engine/UI/ControlReference.cs b/Source/Engine/UI/ControlReference.cs index a708e48fa..efcc42362 100644 --- a/Source/Engine/UI/ControlReference.cs +++ b/Source/Engine/UI/ControlReference.cs @@ -36,25 +36,34 @@ public struct ControlReference : IControlReference where T : Control { [Serialize, ShowInEditor] private UIControl _uiControl; - + + /// + /// Default constructor for ControlReference; + /// + public ControlReference() + { + _uiControl = null; + } + /// public Type GetControlType() { return typeof(T); } - + /// /// The Control attached to the UI Control. /// + [HideInEditor] public T Control { get { - if (_uiControl.Control is T t) + if (_uiControl != null && _uiControl.Control is T t) return t; else { - Debug.LogWarning("Trying to get Control from ControlReference but UIControl.Control is null or UIControl.Control is not the correct type."); + Debug.LogWarning("Trying to get Control from ControlReference but UIControl is null, or UIControl.Control is null, or UIControl.Control is not the correct type."); return null; } } @@ -85,14 +94,14 @@ public struct ControlReference : IControlReference where T : Control { _uiControl = null; } - + /// /// The implicit operator for the Control. /// /// The ControlReference /// The Control. public static implicit operator T(ControlReference reference) => reference.Control; - + /// /// The implicit operator for the UIControl ///