// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using System;
using System.Collections.Generic;
using FlaxEngine;
namespace FlaxEditor.Gizmo
{
///
/// Represents collection of gizmo tools where one is active and in use.
///
///
[HideInEditor]
public class GizmosCollection : List
{
private GizmoBase _active;
///
/// Occurs when active gizmo tool gets changed.
///
public event Action ActiveChanged;
///
/// Gets or sets the active gizmo.
///
public GizmoBase Active
{
get => _active;
set
{
if (_active == value)
return;
if (value != null && !Contains(value))
throw new InvalidOperationException("Invalid Gizmo.");
_active?.OnDeactivated();
_active = value;
_active?.OnActivated();
ActiveChanged?.Invoke();
}
}
///
/// Removes the specified item.
///
/// The item.
public new void Remove(GizmoBase item)
{
if (item == _active)
Active = null;
base.Remove(item);
}
///
/// Clears the collection.
///
public new void Clear()
{
Active = null;
base.Clear();
}
}
}