/// <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();

            // Prepare rendering task
            Task.ActorsSource = ActorsSources.CustomActors;
            Task.ViewFlags    = ViewFlags.DefaultEditor & ~ViewFlags.EditorSprites;
            Task.PostRender  += OnPostRender;

            // Create post effects
            SelectionOutline = FlaxEngine.Object.New <SelectionOutline>();
            SelectionOutline.SelectionGetter = () => TransformGizmo.SelectedParents;
            Task.CustomPostFx.Add(SelectionOutline);
            EditorPrimitives          = FlaxEngine.Object.New <EditorPrimitives>();
            EditorPrimitives.Viewport = this;
            Task.CustomPostFx.Add(EditorPrimitives);

            // 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.World16, 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.ScaleStep16, 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.RotateStep16, 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.Grid16, 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.Translate16, 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.Rotate16, null, true)
            {
                Tag         = TransformGizmoBase.Mode.Rotate,
                TooltipText = "Rotate gizmo mode",
                Parent      = gizmoMode
            };
            _gizmoModeRotate.Toggled += OnGizmoModeToggle;
            _gizmoModeScale           = new ViewportWidgetButton(string.Empty, window.Editor.Icons.Scale16, 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);
        }
Ejemplo n.º 2
0
 public static void ShowWindow()
 {
     _winInstance = GetWindow <PrefabWindow>(true, "PrefabSpawner");
 }