// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. using System; using FlaxEditor.CustomEditors.Editors; using FlaxEngine; using FlaxEngine.Utilities; namespace FlaxEditor.Surface.Elements { /// /// Actors picking control. /// /// /// [HideInEditor] public class ActorSelect : FlaxObjectRefPickerControl, ISurfaceNodeElement { /// public SurfaceNode ParentNode { get; } /// public NodeElementArchetype Archetype { get; } /// /// Initializes a new instance of the class. /// /// The parent node. /// The archetype. public ActorSelect(SurfaceNode parentNode, NodeElementArchetype archetype) { ParentNode = parentNode; Archetype = archetype; Bounds = new Rectangle(Archetype.ActualPosition, archetype.Size); Type = TypeUtils.GetType(archetype.Text); ParentNode.ValuesChanged += OnNodeValuesChanged; OnNodeValuesChanged(); } private void OnNodeValuesChanged() { ValueID = (Guid)ParentNode.Values[Archetype.ValueIndex]; } /// protected override void OnValueChanged() { var selectedId = ValueID; if (ParentNode != null && (Guid)ParentNode.Values[Archetype.ValueIndex] != selectedId) { ParentNode.SetValue(Archetype.ValueIndex, selectedId); } base.OnValueChanged(); } } }