/// <inheritdoc /> public override DragDropEffect OnDragEnter(ref Vector2 location, DragData data) { var result = base.OnDragEnter(ref location, data); if (result == DragDropEffect.None) { if (_dragHandlers == null) { _dragHandlers = new DragHandlers(); } if (_dragAssets == null) { _dragAssets = new DragAssets(ValidateDragAsset); _dragHandlers.Add(_dragAssets); } if (_dragAssets.OnDragEnter(data)) { return(_dragAssets.Effect); } if (_dragActorType == null) { _dragActorType = new DragActorType(ValidateDragActorType); _dragHandlers.Add(_dragActorType); } if (_dragActorType.OnDragEnter(data)) { return(_dragActorType.Effect); } } return(result); }
/// <inheritdoc /> public override DragDropEffect OnDragEnter(ref Float2 location, DragData data) { var result = base.OnDragEnter(ref location, data); if (Editor.StateMachine.CurrentState.CanEditScene) { if (_dragHandlers == null) { _dragHandlers = new DragHandlers(); } if (_dragAssets == null) { _dragAssets = new DragAssets(ValidateDragAsset); _dragHandlers.Add(_dragAssets); } if (_dragAssets.OnDragEnter(data) && result == DragDropEffect.None) { return(_dragAssets.Effect); } if (_dragActorType == null) { _dragActorType = new DragActorType(ValidateDragActorType); _dragHandlers.Add(_dragActorType); } if (_dragActorType.OnDragEnter(data) && result == DragDropEffect.None) { return(_dragActorType.Effect); } } return(result); }
/// <inheritdoc /> protected override DragDropEffect OnDragEnterHeader(DragData data) { // Check if cannot edit scene or there is no scene loaded (handle case for actors in prefab editor) if (_actorNode?.ParentScene != null) { if (!Editor.Instance.StateMachine.CurrentState.CanEditScene || !Level.IsAnySceneLoaded) { return(DragDropEffect.None); } } else { if (!Editor.Instance.StateMachine.CurrentState.CanEditContent) { return(DragDropEffect.None); } } if (_dragHandlers == null) { _dragHandlers = new DragHandlers(); } // Check if drop actors if (_dragActors == null) { _dragActors = new DragActors(ValidateDragActor); _dragHandlers.Add(_dragActors); } if (_dragActors.OnDragEnter(data)) { return(_dragActors.Effect); } // Check if drag assets if (_dragAssets == null) { _dragAssets = new DragAssets(ValidateDragAsset); _dragHandlers.Add(_dragAssets); } if (_dragAssets.OnDragEnter(data)) { return(_dragAssets.Effect); } // Check if drag actor type if (_dragActorType == null) { _dragActorType = new DragActorType(ValidateDragActorType); _dragHandlers.Add(_dragActorType); } if (_dragActorType.OnDragEnter(data)) { return(_dragActorType.Effect); } return(DragDropEffect.None); }
public override void OnDestroy() { _window = null; _dragAssets = null; _dragActorType = null; _dragHandlers?.Clear(); _dragHandlers = null; base.OnDestroy(); }
/// <inheritdoc /> public override void OnDestroy() { _dragAssets = null; _dragActorType = null; _dragHandlers?.Clear(); _dragHandlers = null; _tree = null; _searchBox = null; base.OnDestroy(); }
/// <inheritdoc /> public override DragDropEffect OnDragEnter(ref Float2 location, DragData data) { var result = base.OnDragEnter(ref location, data); if (result != DragDropEffect.None) { return(result); } if (_dragHandlers == null) { _dragScripts = new DragScriptItems(ValidateScript); _dragAssets = new DragAssets(ValidateAsset); _dragHandlers = new DragHandlers { _dragScripts, _dragAssets, }; } return(_dragHandlers.OnDragEnter(data)); }
/// <inheritdoc /> protected override DragDropEffect OnDragEnterHeader(DragData data) { // Check if cannot edit scene or there is no scene loaded if (!Editor.Instance.StateMachine.CurrentState.CanEditScene || !SceneManager.IsAnySceneLoaded) { return(DragDropEffect.None); } // Check if drop actors if (_dragActors == null) { _dragActors = new DragActors(); } if (_dragActors.OnDragEnter(data, ValidateDragActor)) { return(_dragActors.Effect); } // Check if drag assets if (_dragAssets == null) { _dragAssets = new DragAssets(); } if (_dragAssets.OnDragEnter(data, ValidateDragAsset)) { return(_dragAssets.Effect); } // Check if drag actor type if (_dragActorType == null) { _dragActorType = new DragActorType(); } if (_dragActorType.OnDragEnter(data, ValidateDragActorType)) { return(_dragActorType.Effect); } return(DragDropEffect.None); }
/// <summary> /// Initializes a new instance of the <see cref="PrefabWindowViewport"/> class. /// </summary> /// <param name="window">Editor window.</param> public PrefabWindowViewport(PrefabWindow window) : base(true) { _window = window; _window.SelectionChanged += OnSelectionChanged; Undo = window.Undo; ViewportCamera = new FPSCamera(); _dragAssets = new DragAssets(ValidateDragItem); ShowDebugDraw = true; ShowEditorPrimitives = true; // Prepare rendering task Task.ActorsSource = ActorsSources.CustomActors; Task.ViewFlags = ViewFlags.DefaultEditor; Task.Begin += OnBegin; Task.CollectDrawCalls += OnCollectDrawCalls; Task.PostRender += OnPostRender; // Create post effects SelectionOutline = FlaxEngine.Object.New <SelectionOutline>(); SelectionOutline.SelectionGetter = () => TransformGizmo.SelectedParents; Task.CustomPostFx.Add(SelectionOutline); _spritesRenderer = FlaxEngine.Object.New <PrefabSpritesRenderer>(); _spritesRenderer.Task = Task; _spritesRenderer.Viewport = this; Task.CustomPostFx.Add(_spritesRenderer); // Add transformation gizmo TransformGizmo = new TransformGizmo(this); TransformGizmo.ApplyTransformation += ApplyTransform; TransformGizmo.ModeChanged += OnGizmoModeChanged; TransformGizmo.Duplicate += _window.Duplicate; Gizmos.Active = TransformGizmo; // Transform space widget var transformSpaceWidget = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight); var transformSpaceToggle = new ViewportWidgetButton(string.Empty, window.Editor.Icons.Globe32, null, true) { Checked = TransformGizmo.ActiveTransformSpace == TransformGizmoBase.TransformSpace.World, TooltipText = "Gizmo transform space (world or local)", Parent = transformSpaceWidget }; transformSpaceToggle.Toggled += OnTransformSpaceToggle; transformSpaceWidget.Parent = this; // Scale snapping widget var scaleSnappingWidget = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight); var enableScaleSnapping = new ViewportWidgetButton(string.Empty, window.Editor.Icons.ScaleSnap32, null, true) { Checked = TransformGizmo.ScaleSnapEnabled, TooltipText = "Enable scale snapping", Parent = scaleSnappingWidget }; enableScaleSnapping.Toggled += OnScaleSnappingToggle; var scaleSnappingCM = new ContextMenu(); _scaleSnapping = new ViewportWidgetButton(TransformGizmo.ScaleSnapValue.ToString(), SpriteHandle.Invalid, scaleSnappingCM) { TooltipText = "Scale snapping values" }; for (int i = 0; i < EditorViewportScaleSnapValues.Length; i++) { var v = EditorViewportScaleSnapValues[i]; var button = scaleSnappingCM.AddButton(v.ToString()); button.Tag = v; } scaleSnappingCM.ButtonClicked += OnWidgetScaleSnapClick; scaleSnappingCM.VisibleChanged += OnWidgetScaleSnapShowHide; _scaleSnapping.Parent = scaleSnappingWidget; scaleSnappingWidget.Parent = this; // Rotation snapping widget var rotateSnappingWidget = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight); var enableRotateSnapping = new ViewportWidgetButton(string.Empty, window.Editor.Icons.RotateSnap32, null, true) { Checked = TransformGizmo.RotationSnapEnabled, TooltipText = "Enable rotation snapping", Parent = rotateSnappingWidget }; enableRotateSnapping.Toggled += OnRotateSnappingToggle; var rotateSnappingCM = new ContextMenu(); _rotateSnapping = new ViewportWidgetButton(TransformGizmo.RotationSnapValue.ToString(), SpriteHandle.Invalid, rotateSnappingCM) { TooltipText = "Rotation snapping values" }; for (int i = 0; i < EditorViewportRotateSnapValues.Length; i++) { var v = EditorViewportRotateSnapValues[i]; var button = rotateSnappingCM.AddButton(v.ToString()); button.Tag = v; } rotateSnappingCM.ButtonClicked += OnWidgetRotateSnapClick; rotateSnappingCM.VisibleChanged += OnWidgetRotateSnapShowHide; _rotateSnapping.Parent = rotateSnappingWidget; rotateSnappingWidget.Parent = this; // Translation snapping widget var translateSnappingWidget = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight); var enableTranslateSnapping = new ViewportWidgetButton(string.Empty, window.Editor.Icons.Grid32, null, true) { Checked = TransformGizmo.TranslationSnapEnable, TooltipText = "Enable position snapping", Parent = translateSnappingWidget }; enableTranslateSnapping.Toggled += OnTranslateSnappingToggle; var translateSnappingCM = new ContextMenu(); _translateSnappng = new ViewportWidgetButton(TransformGizmo.TranslationSnapValue.ToString(), SpriteHandle.Invalid, translateSnappingCM) { TooltipText = "Position snapping values" }; for (int i = 0; i < EditorViewportTranslateSnapValues.Length; i++) { var v = EditorViewportTranslateSnapValues[i]; var button = translateSnappingCM.AddButton(v.ToString()); button.Tag = v; } translateSnappingCM.ButtonClicked += OnWidgetTranslateSnapClick; translateSnappingCM.VisibleChanged += OnWidgetTranslateSnapShowHide; _translateSnappng.Parent = translateSnappingWidget; translateSnappingWidget.Parent = this; // Gizmo mode widget var gizmoMode = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight); _gizmoModeTranslate = new ViewportWidgetButton(string.Empty, window.Editor.Icons.Translate32, null, true) { Tag = TransformGizmoBase.Mode.Translate, TooltipText = "Translate gizmo mode", Checked = true, Parent = gizmoMode }; _gizmoModeTranslate.Toggled += OnGizmoModeToggle; _gizmoModeRotate = new ViewportWidgetButton(string.Empty, window.Editor.Icons.Rotate32, null, true) { Tag = TransformGizmoBase.Mode.Rotate, TooltipText = "Rotate gizmo mode", Parent = gizmoMode }; _gizmoModeRotate.Toggled += OnGizmoModeToggle; _gizmoModeScale = new ViewportWidgetButton(string.Empty, window.Editor.Icons.Scale32, null, true) { Tag = TransformGizmoBase.Mode.Scale, TooltipText = "Scale gizmo mode", Parent = gizmoMode }; _gizmoModeScale.Toggled += OnGizmoModeToggle; gizmoMode.Parent = this; _dragHandlers.Add(_dragActorType); _dragHandlers.Add(_dragAssets); // Setup input actions InputActions.Add(options => options.TranslateMode, () => TransformGizmo.ActiveMode = TransformGizmoBase.Mode.Translate); InputActions.Add(options => options.RotateMode, () => TransformGizmo.ActiveMode = TransformGizmoBase.Mode.Rotate); InputActions.Add(options => options.ScaleMode, () => TransformGizmo.ActiveMode = TransformGizmoBase.Mode.Scale); InputActions.Add(options => options.FocusSelection, ShowSelectedActors); SetUpdate(ref _update, OnUpdate); }