// Copyright (c) Wojciech Figat. All rights reserved. using System.Collections.Generic; using FlaxEditor.SceneGraph; using FlaxEngine; namespace FlaxEditor.Gizmo { /// /// Base class for all Gizmo controls that can be attached to the . /// [HideInEditor] public abstract class GizmoBase { private IGizmoOwner _owner; /// /// Gets the gizmo owner. /// public IGizmoOwner Owner => _owner; /// /// Gets a value indicating whether this gizmo is active. /// public bool IsActive => _owner.Gizmos.Active == this; /// /// Gets a value indicating whether this gizmo is using mouse currently (eg. user moving objects). /// public virtual bool IsControllingMouse => false; /// /// Gets the custom world-space bounds for current gizmo mode focus for used (eg. selected object part bounds). Returns if not used. /// public virtual BoundingSphere FocusBounds => BoundingSphere.Empty; /// /// Initializes a new instance of the class. /// /// The gizmos owner. protected GizmoBase(IGizmoOwner owner) { // Link _owner = owner; _owner.Gizmos.Add(this); } /// /// Called when selected objects collection gets changed. /// /// The new selection pool. public virtual void OnSelectionChanged(List newSelection) { } /// /// Called when gizmo gets activated. /// public virtual void OnActivated() { } /// /// Called when gizmo gets deactivated. /// public virtual void OnDeactivated() { } /// /// Updates the gizmo logic (called even if not active). /// /// Update delta time (in seconds). public virtual void Update(float dt) { } /// /// Performs scene object picking. Called by the viewport on left mouse button released. /// public virtual void Pick() { } /// /// Performs scene objects snapping to the ground. /// public virtual void SnapToGround() { } /// /// Draws the gizmo. /// /// The rendering context. public virtual void Draw(ref RenderContext renderContext) { } /// /// Activates thi gizmo mode. /// public void Activate() { _owner.Gizmos.Active = this; } /// /// Removes the gizmo from the owner. /// public void Destroy() { if (_owner != null) { _owner.Gizmos.Remove(this); _owner = null; } } } }