示例#1
0
 protected new void OnMouseDown(MouseDownEvent e)
 {
     if (this.m_Active)
     {
         e.StopImmediatePropagation();
     }
     else if (base.CanStartManipulation(e))
     {
         this.m_GraphView = (base.target as GraphView);
         if (this.m_GraphView != null)
         {
             this.selectedElement = null;
             this.clickedElement  = (e.target as GraphElement);
             if (this.clickedElement == null)
             {
                 VisualElement visualElement = e.target as VisualElement;
                 this.clickedElement = visualElement.GetFirstAncestorOfType <GraphElement>();
                 if (this.clickedElement == null)
                 {
                     return;
                 }
             }
             if (this.clickedElement.IsMovable() && this.m_GraphView.selection.Contains(this.clickedElement) && this.clickedElement.HitTest(this.clickedElement.WorldToLocal(e.mousePosition)))
             {
                 this.selectedElement = this.clickedElement;
                 this.m_OriginalPos   = new Dictionary <GraphElement, Rect>();
                 foreach (ISelectable current in this.m_GraphView.selection)
                 {
                     GraphElement graphElement = current as GraphElement;
                     if (graphElement != null && graphElement.IsMovable())
                     {
                         this.m_OriginalPos[graphElement] = graphElement.GetPosition();
                     }
                 }
                 this.m_originalMouse = e.mousePosition;
                 this.m_ItemPanDiff   = Vector3.zero;
                 if (this.m_PanSchedule == null)
                 {
                     this.m_PanSchedule = this.m_GraphView.schedule.Execute(new Action <TimerState>(this.Pan)).Every(10L).StartingIn(10L);
                     this.m_PanSchedule.Pause();
                 }
                 this.m_Active = true;
                 base.target.TakeMouseCapture();
                 e.StopPropagation();
             }
         }
     }
 }
示例#2
0
        void OnMouseDownEvent(MouseDownEvent e)
        {
            if (e.button != (int)MouseButton.LeftMouse)
                return;

            if (e.clickCount == 1 && (variableInfoTooltip == null || variableInfoTooltip.currentHandler != this) && !m_PopupTemporarilyDisabled && !isVariableFieldVisible)
            {
                m_ScheduledShowPopup = labelElement.schedule.Execute(() => ShowPopup(this)).StartingIn(BuilderConstants.DoubleClickDelay);
            }
            else if (e.clickCount == 2 && !m_EditingTemporarilyDisabled)
            {
                m_ScheduledShowPopup?.Pause();
                m_ScheduledShowPopup = null;
                ShowVariableField();
            }
        }
        void OnColorChanged(Color color)
        {
            SetValue(color);

            if (m_EyeDropperScheduler != null)
            {
                m_EyeDropperScheduler.Pause();
                m_EyeDropperScheduler = null;
                m_EyeDropper.RegisterCallback <MouseDownEvent>(OnEyeDropperStart);
            }

            if (OnValueChanged != null)
            {
                OnValueChanged();
            }
        }
        void DeactivateCameraMode()
        {
            if (!m_CameraModeEnabled)
            {
                return;
            }

            m_InGamePreviewScheduledItem.Pause();
            m_InGamePreviewScheduledItem = null;

            m_InGamePreviewRenderTexture = null;
            m_InGamePreviewTexture2D     = null;

            m_CameraModeEnabled = false;

            customBackgroundElement.style.backgroundImage = StyleKeyword.Null;
        }
        public RefreshScheduler(IVisualElementScheduler scheduler)
        {
            m_Scheduler = scheduler.Execute(InvokeRefresh).Every(100);
            m_Scheduler.Pause();

            EditorApplication.playModeStateChanged += (state) =>
            {
                if (state == PlayModeStateChange.EnteredPlayMode)
                {
                    m_Scheduler.Resume();
                }
                else if (state == PlayModeStateChange.ExitingPlayMode)
                {
                    m_Scheduler.Pause();
                    InvokeExitPlayMode();
                }
            };
        }
示例#6
0
        private void PollTouchScreenKeyboard()
        {
            bool flag = TouchScreenKeyboard.isSupported && !TouchScreenKeyboard.isInPlaceEditingAllowed;

            if (flag)
            {
                bool flag2 = this.m_TouchKeyboardPoller == null;
                if (flag2)
                {
                    VisualElement expr_32 = base.textInputField as VisualElement;
                    this.m_TouchKeyboardPoller = ((expr_32 != null) ? expr_32.schedule.Execute(new Action(this.DoPollTouchScreenKeyboard)).Every(100L) : null);
                }
                else
                {
                    this.m_TouchKeyboardPoller.Resume();
                }
            }
        }
        /// <summary>
        /// Creates LoadingSpinner control
        /// </summary>
        public LoadingSpinner()
        {
            AddToClassList(UssClassName);
            UIToolkitEditorUtility.ApplyStyleForInternalControl(this, nameof(LoadingSpinner));
            m_IsActive = false;

            // add child elements to set up centered spinner rotation
            var innerElement = new VisualElement();

            innerElement.AddToClassList("image");
            Add(innerElement);

            m_ScheduledUpdate = schedule.Execute(UpdateProgress).Every(k_RotationUpdateInterval);
            m_ScheduledUpdate.Pause();

            RegisterCallback <AttachToPanelEvent>(OnAttachToPanelEventHandler, TrickleDown.TrickleDown);
            RegisterCallback <DetachFromPanelEvent>(OnDetachFromPanelEventHandler, TrickleDown.TrickleDown);
        }
        public BuilderResizer()
        {
            var builderTemplate = BuilderPackageUtilities.LoadAssetAtPath <VisualTreeAsset>(
                BuilderConstants.UIBuilderPackagePath + "/Manipulators/BuilderResizer.uxml");

            builderTemplate.CloneTree(this);

            AddToClassList(s_UssClassName);

            m_HandleElements = new Dictionary <string, VisualElement>();

            m_HandleElements.Add("top-handle", this.Q("top-handle"));
            m_HandleElements.Add("left-handle", this.Q("left-handle"));
            m_HandleElements.Add("bottom-handle", this.Q("bottom-handle"));
            m_HandleElements.Add("right-handle", this.Q("right-handle"));

            m_HandleElements.Add("top-left-handle", this.Q("top-left-handle"));
            m_HandleElements.Add("top-right-handle", this.Q("top-right-handle"));

            m_HandleElements.Add("bottom-left-handle", this.Q("bottom-left-handle"));
            m_HandleElements.Add("bottom-right-handle", this.Q("bottom-right-handle"));

            m_HandleElements["top-handle"].AddManipulator(new Manipulator(OnStartDrag, OnEndDrag, OnDragTop));
            m_HandleElements["left-handle"].AddManipulator(new Manipulator(OnStartDrag, OnEndDrag, OnDragLeft));
            m_HandleElements["bottom-handle"].AddManipulator(new Manipulator(OnStartDrag, OnEndDrag, OnDragBottom));
            m_HandleElements["right-handle"].AddManipulator(new Manipulator(OnStartDrag, OnEndDrag, OnDragRight));

            m_HandleElements["top-left-handle"].AddManipulator(new Manipulator(OnStartDrag, OnEndDrag, OnDragTopLeft));
            m_HandleElements["top-right-handle"].AddManipulator(new Manipulator(OnStartDrag, OnEndDrag, OnDragTopRight));

            m_HandleElements["bottom-left-handle"].AddManipulator(new Manipulator(OnStartDrag, OnEndDrag, OnDragBottomLeft));
            m_HandleElements["bottom-right-handle"].AddManipulator(new Manipulator(OnStartDrag, OnEndDrag, OnDragBottomRight));

            base.m_AbsoluteOnlyHandleElements.Add(m_HandleElements["top-handle"]);
            base.m_AbsoluteOnlyHandleElements.Add(m_HandleElements["left-handle"]);
            base.m_AbsoluteOnlyHandleElements.Add(m_HandleElements["top-left-handle"]);
            base.m_AbsoluteOnlyHandleElements.Add(m_HandleElements["top-right-handle"]);
            base.m_AbsoluteOnlyHandleElements.Add(m_HandleElements["bottom-left-handle"]);

            m_UndoWidthHighlightScheduledItem = this.schedule.Execute(UndoWidthHighlight);
            m_UndoWidthHighlightScheduledItem.Pause();
            m_UndoHeightHighlightScheduledItem = this.schedule.Execute(UndoHeightHighlight);
            m_UndoHeightHighlightScheduledItem.Pause();
        }
示例#9
0
        /// <summary>
        /// Creates LoadingSpinner control
        /// </summary>
        public LoadingSpinner()
        {
            styleSheets.Add(Resources.Load <StyleSheet>("LoadingSpinner"));
            AddToClassList(UssClassName);

            m_IsActive = false;

            // add child elements to set up centered spinner rotation
            var innerElement = new VisualElement();

            innerElement.AddToClassList("image");
            Add(innerElement);

            m_ScheduledUpdate = schedule.Execute(UpdateProgress).Every(k_RotationUpdateInterval);
            m_ScheduledUpdate.Pause();

            RegisterCallback <AttachToPanelEvent>(OnAttachToPanelEventHandler, TrickleDown.TrickleDown);
            RegisterCallback <DetachFromPanelEvent>(OnDetachFromPanelEventHandler, TrickleDown.TrickleDown);
        }
示例#10
0
        private void OnPointerDown(PointerDownEvent evt)
        {
            bool flag = evt.pointerType != PointerType.mouse && evt.isPrimary && this.m_ScrollingPointerId == PointerId.invalidPointerId;

            if (flag)
            {
                IVisualElementScheduledItem expr_39 = this.m_PostPointerUpAnimation;
                if (expr_39 != null)
                {
                    expr_39.Pause();
                }
                this.m_ScrollingPointerId   = evt.pointerId;
                this.m_PointerStartPosition = evt.position;
                this.m_StartPosition        = this.scrollOffset;
                this.m_Velocity             = Vector2.zero;
                this.m_SpringBackVelocity   = Vector2.zero;
                this.m_LowBounds            = new Vector2(Mathf.Min(this.horizontalScroller.lowValue, this.horizontalScroller.highValue), Mathf.Min(this.verticalScroller.lowValue, this.verticalScroller.highValue));
                this.m_HighBounds           = new Vector2(Mathf.Max(this.horizontalScroller.lowValue, this.horizontalScroller.highValue), Mathf.Max(this.verticalScroller.lowValue, this.verticalScroller.highValue));
                evt.StopPropagation();
            }
        }
示例#11
0
        public void OnEnable()
        {
            var root = m_PaneWindow.rootVisualElement;

            root.focusable = true; // We want commands to work anywhere in the builder.

            foreach (var pane in m_Panes)
            {
                pane.primaryFocusable.RegisterCallback <ValidateCommandEvent>(OnCommandValidate);
                pane.primaryFocusable.RegisterCallback <ExecuteCommandEvent>(OnCommandExecute);

                // Make sure Delete key works on Mac keyboards.
                pane.primaryFocusable.RegisterCallback <KeyDownEvent>(OnDelete);
            }

            // Ctrl+S to save.
            m_PaneWindow.rootVisualElement.RegisterCallback <KeyUpEvent>(OnSaveDocument);
            m_ControlUnpressScheduleItem = m_PaneWindow.rootVisualElement.schedule.Execute(UnsetControlFlag);

            // Undo/Redo
            Undo.undoRedoPerformed += OnUndoRedo;
        }
        public ChoseShapeDataField(ShapeDataFactory shapeDataFactory, CanDependOnShapeBlueprint dependent,
                                   string fieldName, Func <TShapeData> getShapeDataFunc, Action <TShapeData> setShapeDataFunc)
        {
            m_DataFactory      = shapeDataFactory;
            m_Dependent        = dependent;
            m_FieldName        = fieldName;
            m_GetShapeDataFunc = getShapeDataFunc;
            m_SetShapeDataFunc = setShapeDataFunc;

            VisualElement firstRow = new VisualElement {
                style = { flexDirection = FlexDirection.Row }
            };

            firstRow.Add(m_Label = new Label());

            m_ToolbarMenu = new ToolbarMenu {
                text = "Change", style = { flexDirection = FlexDirection.Row }
            };
            m_ToolbarMenu.RemoveFromClassList("unity-toolbar-menu");
            m_ToolbarMenu.AddToClassList("unity-button");

            firstRow.Add(m_ToolbarMenu);

            Add(firstRow);

            IValidator pointNotEmptyValidator =
                new DataNotEmptyValidator <TShapeData>(getShapeDataFunc, action => m_UpdateValidatorAction = action);
            VisualElement validatorField = new ValidatorField(pointNotEmptyValidator);

            Add(validatorField);

            m_DataFactory.BecameDirty.Subscribe(BecameDirty);
            m_AutoSaveScheduler = schedule.Execute(Update);
            m_AutoSaveScheduler.Every(200);

            UpdateList();
            UpdateName();
            m_UpdateValidatorAction?.Invoke();
        }
示例#13
0
        protected void OnMouseDown(MouseDownEvent evt)
        {
            if (CanStartManipulation(evt))
            {
                m_Active = true;
                target.TakeMouseCapture();
                lastMousePosition = evt.localMousePosition;

                if (IsRepeatable())
                {
                    // Repeatable button clicks are performed on the MouseDown and at timer events
                    if (target.ContainsPoint(evt.localMousePosition))
                    {
                        if (clicked != null)
                        {
                            clicked();
                        }
                        else if (clickedWithEventInfo != null)
                        {
                            clickedWithEventInfo(evt);
                        }
                    }

                    if (m_Repeater == null)
                    {
                        m_Repeater = target.schedule.Execute(OnTimer).Every(m_Interval).StartingIn(m_Delay);
                    }
                    else
                    {
                        m_Repeater.ExecuteLater(m_Delay);
                    }
                }

                target.pseudoStates |= PseudoStates.Active;

                evt.StopImmediatePropagation();
            }
        }
示例#14
0
        public override void Resize(Vector2 size, int layoutPass)
        {
            var contentHeight = GetContentHeight();

            m_ScrollView.contentContainer.style.height = contentHeight;

            // Recalculate offset
            var firstItemPadding = GetContentHeightForIndex(m_FirstVisibleIndex - 1);

            var previousOffset  = m_CollectionView.m_ScrollOffset.y;
            var previousPadding = m_StoredPadding;
            var deltaOffset     = previousOffset - previousPadding;
            var offset          = firstItemPadding + deltaOffset;

            // Restore scroll offset and preemptively update the highValue
            // in case this is the initial restore from persistent data and
            // the ScrollView's OnGeometryChanged() didn't update the low
            // and highValues.
            var scrollableHeight = Mathf.Max(0, contentHeight - m_ScrollView.contentViewport.layout.height);
            var scrollOffset     = Mathf.Min(offset, scrollableHeight);

            m_ScrollView.verticalScroller.slider.SetHighValueWithoutNotify(scrollableHeight);
            m_ScrollView.verticalScroller.value            = scrollOffset;
            m_CollectionView.m_ScrollOffset.y              = m_ScrollView.verticalScroller.value;
            m_ScrollView.contentContainer.style.paddingTop = firstItemPadding;
            m_StoredPadding = firstItemPadding;

            if (layoutPass == 0)
            {
                Fill();
                OnScroll(new Vector2(0, scrollOffset));
            }
            else if (m_ScheduledItem == null)
            {
                m_ScheduledItem = m_CollectionView.schedule.Execute(m_FillCallback);
            }
        }
        /// <summary>
        /// Automatically set the value of a Toggle after N milliseconds of the cursor leaving the bounds of (this) target object
        /// </summary>
        /// <param name="element">The target element in which the bounds are used to activate the toggle countdown</param>
        /// <param name="toggleTarget">The target toggle in which to set its value within N milliseconds of the mouse leaving this  elements bounds  </param>
        /// <param name="autoToggleValue">The value in which to set the Toggle after toggleTimer completes</param>
        /// <param name="toggleTimer">The amount of time in which to wait before the toggles value is changed.
        /// Default: 1000ms</param>
        /// <param name="interruptible">Whether the automatic toggle should be interrupted if the cursor is placed back into the bounds of the target element</param>
        /// <typeparam name="T">VisualElement</typeparam>
        public static T AutoToggleAfter <T>(this T element, Toggle toggleTarget, long toggleTimer = 1000, bool interruptible = false, bool autoToggleValue = false)
            where T : VisualElement
        {
            bool interrupter = false;
            IVisualElementScheduledItem menuCloser = element.schedule.Execute(() =>
            {
                if (interrupter == false && toggleTarget.value)
                {
                    toggleTarget.value = autoToggleValue;
                }
            });

            element.RegisterCallback <MouseOverEvent>(evt =>
            {
                if (!interruptible)
                {
                    return;
                }

                interrupter = true;
                menuCloser?.Pause();
                evt.StopPropagation();
            });
            element.RegisterCallback <MouseLeaveEvent>(evt =>
            {
                interrupter = false;

                if (toggleTarget.value)
                {
                    menuCloser.ExecuteLater(toggleTimer);
                }
                evt.StopPropagation();
            });

            return(element);
        }
示例#16
0
        void OnPointerUp(PointerUpEvent evt)
        {
            if (evt.pointerId == m_ScrollingPointerId)
            {
                evt.currentTarget.ReleasePointer(evt.pointerId);
                evt.StopPropagation();

                if (touchScrollBehavior == TouchScrollBehavior.Elastic || hasInertia)
                {
                    ComputeInitialSpringBackVelocity();

                    if (m_PostPointerUpAnimation == null)
                    {
                        m_PostPointerUpAnimation = schedule.Execute(PostPointerUpAnimation).Every(30);
                    }
                    else
                    {
                        m_PostPointerUpAnimation.Resume();
                    }
                }

                m_ScrollingPointerId = PointerId.invalidPointerId;
            }
        }
        public override VisualElement CreateInspectorGUI()
        {
            root = new VisualElement();

            controllerWarning = new IMGUIContainer(() =>
            {
                EditorGUILayout.HelpBox("The Character Controller Y center must be half of the height. Set your Y center to " + characterController.height / 2 + "!", MessageType.Warning);
            });
            controllerWarningFix = new Button(() =>
            {
                if (characterController != null)
                {
                    Undo.RecordObject(characterController, "Fixed player center");
                    characterController.center = new Vector3(characterController.center.x, characterController.height / 2, characterController.center.z);
                }
            })
            {
                text = "Fix"
            };

            if (characterController != null)
            {
                bool show = characterController.center.y != characterController.height / 2;
                controllerWarning.style.display    = show ? DisplayStyle.Flex : DisplayStyle.None;
                controllerWarningFix.style.display = show ? DisplayStyle.Flex : DisplayStyle.None;
            }
            else
            {
                controllerWarning.style.display    = DisplayStyle.None;
                controllerWarningFix.style.display = DisplayStyle.None;
            }

            root.Add(controllerWarning);
            root.Add(controllerWarningFix);

            IVisualElementScheduledItem controllerCheck = root.schedule.Execute(() =>
            {
                if (characterController != null)
                {
                    bool show = characterController.center.y != characterController.height / 2;
                    controllerWarning.style.display    = show ? DisplayStyle.Flex : DisplayStyle.None;
                    controllerWarningFix.style.display = show ? DisplayStyle.Flex : DisplayStyle.None;
                }
            });

            controllerCheck.Every(100);

            IMGUIContainer toolbarContainer = new IMGUIContainer(() =>
            {
                int newTab = GUILayout.Toolbar(currentTab, tabs);
                if (newTab != currentTab)
                {
                    currentTab = newTab;
                    EditorPrefs.SetInt(SELECTED_TAB_PREFS, currentTab);
                    RebuildTab(currentTab);
                }
            });

            root.Add(toolbarContainer);
            root.Add(GetSpace(3));

            inputElements = new VisualElement();

            CreateCameraGUI();
            CreateMovementGUI();
            CreateHeadBobGUI();
            CreateAudioGUI();

            root.Add(cameraElements);
            root.Add(movementElements);
            root.Add(headBobElements);
            root.Add(audioElements);
            root.Add(inputElements);

            RebuildTab(currentTab);

            return(root);
        }
示例#18
0
 public DelayedTask(VisualElement visualElement, Action action)
 {
     m_ScheduledTask = visualElement.schedule.Execute(action);
     m_ScheduledTask.Pause();
 }
示例#19
0
 private void DelayPersistentDataSave()
 {
     m_OnTimerTicker = null;
     SavePersistentData();
 }
        public static void HoverBorderPulseUnregister(
            this VisualElement target, Color pulseStartColor, Color pulseEndColor, Color original = default, bool addBorder = false,
            Vector2 borderStartEndWidth = default,
            int colorDuration           = 1000,
            bool includeChildren        = true,
            bool stopPropagation        = true,
            TrickleDown useTrickleDown  = TrickleDown.NoTrickleDown)
        {
            if (borderStartEndWidth == default)
            {
                borderStartEndWidth = new Vector2(1, 0);
            }

            var pulseIn  = new ValueAnimation <StyleValues>();
            var pulseOut = new ValueAnimation <StyleValues>();
            IVisualElementScheduledItem repeatedAnim = null;
            var doHover = false;

            target.UnregisterCallback <MouseOverEvent>(evt =>
            {
                repeatedAnim = null;
                doHover      = true;
                if (addBorder)
                {
                    target.style.borderBottomWidth = borderStartEndWidth.x;
                    target.style.borderLeftWidth   = borderStartEndWidth.x;
                    target.style.borderRightWidth  = borderStartEndWidth.x;
                    target.style.borderTopWidth    = borderStartEndWidth.x;
                }

                // -- Pulse color will fade original => desired color   --
                // -- via the AnimateTo local function. Once completed  --
                // -- the AnimateFrom function is called animating back --
                // -- to the original color. This is then repeated for  --
                // -- as long as the mouse is hovered over the target   --
                void PulseIn(in ValueAnimation <StyleValues> pulse)
                {
                    if (pulse.isRunning)
                    {
                        pulse.Stop();
                    }
                    pulseIn = target.AnimateBorderColor(pulseStartColor, pulseEndColor, colorDuration, () => PulseOut(pulseIn));
                }

                void PulseOut(in ValueAnimation <StyleValues> pulse)
                {
                    if (pulse.isRunning)
                    {
                        pulse.Stop();
                    }
                    pulseOut = target.AnimateBorderColor(pulseEndColor, pulseStartColor, colorDuration);
                }

                if (pulseIn.isRunning)
                {
                    pulseIn.Stop();
                }
                if (pulseOut.isRunning)
                {
                    pulseOut.Stop();
                }
                repeatedAnim = target.schedule.Execute(() => PulseIn(pulseOut)).StartingIn(0).Every(colorDuration * 2 + 20).Until(() => !doHover);

                if (stopPropagation)
                {
                    evt.StopPropagation();
                }
            }, includeChildren);
            target.UnregisterCallback <MouseOutEvent>(evt =>
            {
                doHover = false;
                if (pulseIn.isRunning)
                {
                    pulseIn?.Stop();
                }
                if (pulseOut.isRunning)
                {
                    pulseOut?.Stop();
                }
                if (repeatedAnim.isActive)
                {
                    repeatedAnim.Pause();
                }

                if (addBorder)
                {
                    target.style.borderBottomWidth = borderStartEndWidth.y;
                    target.style.borderLeftWidth   = borderStartEndWidth.y;
                    target.style.borderRightWidth  = borderStartEndWidth.y;
                    target.style.borderTopWidth    = borderStartEndWidth.y;
                }

                if (pulseIn.isRunning)
                {
                    pulseIn.Stop();
                }
                if (pulseOut.isRunning)
                {
                    pulseOut.Stop();
                }


                target.style.borderBottomColor = original;
                target.style.borderLeftColor   = original;
                target.style.borderRightColor  = original;
                target.style.borderTopColor    = original;

                if (stopPropagation)
                {
                    evt.StopPropagation();
                }
            }, includeChildren);
        }
示例#21
0
        // -------------------------------------------------- @HoverBorder
        // ---------------------------------------------------------------
        /// <summary>
        /// Pulse the  border of an element  between two colors
        ///
        /// ** To help combat your element shifting position slightly when a border is applied on hover,
        /// it is a good idea to add a border to your element before hand and just set color to 'initial'
        /// so that it is transparent, then keep 'addBorder' parameter as false.
        /// </summary>
        /// <param name="element">The element in which this function will be applied</param>
        /// <param name="color1">Color 1 in which to pulse between</param>
        /// <param name="color2">Color 2 in which to pulse between</param>
        /// <param name="original">The original color of the element being changed. Can be obtained and passed via 'visualElement.style.backgroundColor.value'</param>
        /// <param name="color1DurationMs">The amount of time it takes in milliseconds to complete the first color animation</param>
        /// <param name="color2DurationMs">The amount of time it takes in milliseconds to complete the second color animation</param>
        /// <param name="addBorder">Adds a border if the element does not have one already</param>
        /// <param name="borderStartEndWidth">The width in which the borders should be when displaying</param>
        /// <param name="callback">Function that can be called when the animation is completed</param>
        /// <param name="borderSelection">The parameters of the Vector4(1-4) represent which borders should have their colors changed: 1(x) = left, 2(y) = top, 3(z) = right, 4(w) = bottom.
        /// If only the top and bottom borders are desired to pulse, you would pass new Vector4(0, 1, 0, 1)</param>
        public static IVisualElementScheduledItem AnimBorderPulse(this VisualElement element, Color color1, Color color2, Color original = default,
                                                                  int color1DurationMs        = 1000,
                                                                  int color2DurationMs        = 1000,
                                                                  bool addBorder              = false,
                                                                  Vector2 borderStartEndWidth = default,
                                                                  Action callback             = null,
                                                                  Vector4 borderSelection     = default,
                                                                  IVisualElementScheduledItem repeatedAnim = default
                                                                  )
        {
            if (borderStartEndWidth == default)
            {
                borderStartEndWidth = new Vector2(1, 0);
            }

            bool doBorderPulse;
            var  pulseIn  = new ValueAnimation <StyleValues>();
            var  pulseOut = new ValueAnimation <StyleValues>();

            pulseIn.autoRecycle  = true;
            pulseOut.autoRecycle = true;
            pulseIn.KeepAlive();
            pulseOut.KeepAlive();

            doBorderPulse = true;
            if (addBorder)
            {
                element.SetBorderWidth(borderStartEndWidth.x);
            }

            var borderValues  = new Vector4();
            var paddingValues = new Vector4();

            void SetBorderValues()
            {
                if (borderSelection.x == 0)
                {
                    element.style.paddingLeft     = paddingValues.x + borderValues.x;
                    element.style.borderLeftWidth = 0;
                }

                if (borderSelection.y == 0)
                {
                    element.style.paddingTop     = paddingValues.y + borderValues.y;
                    element.style.borderTopWidth = 0;
                }

                if (borderSelection.z == 0)
                {
                    element.style.paddingRight     = paddingValues.z + borderValues.z;
                    element.style.borderRightWidth = 0;
                }

                if (borderSelection.w == 0)
                {
                    element.style.paddingBottom     = paddingValues.w + borderValues.w;
                    element.style.borderBottomWidth = 0;
                }
            }

            void ReplaceBorderValues()
            {
                if (borderSelection.x == 0)
                {
                    element.style.paddingLeft     = paddingValues.x;
                    element.style.borderLeftWidth = borderValues.x;
                }

                if (borderSelection.y == 0)
                {
                    element.style.paddingTop     = paddingValues.y;
                    element.style.borderTopWidth = borderValues.y;
                }

                if (borderSelection.z == 0)
                {
                    element.style.paddingRight     = paddingValues.z;
                    element.style.borderRightWidth = borderValues.z;
                }

                if (borderSelection.w == 0)
                {
                    element.style.paddingBottom     = paddingValues.w;
                    element.style.borderBottomWidth = borderValues.w;
                }
            }

            if (borderSelection != default)
            {
                borderValues = new Vector4(
                    element.style.borderLeftWidth.value,
                    element.style.borderTopWidth.value,
                    element.style.borderRightWidth.value,
                    element.style.borderBottomWidth.value);

                paddingValues = new Vector4(
                    element.resolvedStyle.paddingLeft,
                    element.resolvedStyle.paddingTop,
                    element.resolvedStyle.paddingRight,
                    element.resolvedStyle.paddingBottom);
                SetBorderValues();
            }

            void DoCleanup()
            {
                if (pulseOut.isRunning)
                {
                    pulseOut.Stop();
                }
                if (pulseIn.isRunning)
                {
                    pulseIn.Stop();
                }

                element.SetBorderColor();
                if (addBorder)
                {
                    element.SetBorderWidth(borderStartEndWidth.y);
                }
                if (borderSelection != default)
                {
                    ReplaceBorderValues();
                }
                callback?.Invoke();
            } // @formatter:off

            // -- Pulse color will fade original => desired color   --
            // -- via the AnimateTo local function. Once completed  --
            // -- the AnimateFrom function is called animating back --
            // -- to the original color. This is then repeated for  --
            // -- as long as the mouse is hovered over the target   --
            void PulseIn(IVisualElementScheduledItem repeated)
            {
                if (!repeated.isActive)
                {
                    DoCleanup(); return;
                }
                if (pulseOut.isRunning)
                {
                    pulseOut.Stop();
                }
                pulseIn = element.AnimateBorderColor(
                    color1,
                    color2,
                    color1DurationMs,
                    () => PulseOut(repeated)).KeepAlive();
            }

            void PulseOut(IVisualElementScheduledItem repeated)
            {
                if (!repeated.isActive)
                {
                    DoCleanup(); return;
                }
                if (pulseIn.isRunning)
                {
                    pulseIn.Stop();
                }
                pulseOut = element.AnimateBorderColor(
                    color2,
                    color1,
                    color2DurationMs, () => { if (!repeated.isActive)
                                              {
                                                  DoCleanup();
                                              }
                    }).KeepAlive();
            } // @formatter:on

            var recurring = color1DurationMs + color2DurationMs + 20;

            repeatedAnim = element.schedule
                           .Execute(() => { PulseIn(repeatedAnim); })
                           .StartingIn(0)
                           .Every(recurring)
                           .Until(() => !doBorderPulse);

            return(repeatedAnim);
        }
        public override bool HandleMouseDown(MouseDownEvent evt)
        {
            Vector2 mousePosition = evt.mousePosition;

            if ((draggedPort == null) || (edgeCandidate == null))
            {
                return(false);
            }

            graphView = draggedPort.GetFirstAncestorOfType <GraphView>();

            if (graphView == null)
            {
                return(false);
            }

            if (edgeCandidate.parent == null)
            {
                graphView.AddElement(edgeCandidate);
            }

            bool startFromOutput = (draggedPort.direction == Direction.Output);

            edgeCandidate.candidatePosition = mousePosition;
            edgeCandidate.SetEnabled(false);

            if (startFromOutput)
            {
                edgeCandidate.output = draggedPort;
                edgeCandidate.input  = null;
            }
            else
            {
                edgeCandidate.output = null;
                edgeCandidate.input  = draggedPort;
            }

            draggedPort.portCapLit = true;

            compatiblePorts.Clear();

            foreach (PortView port in graphView.GetCompatiblePorts(draggedPort, nodeAdapter))
            {
                compatiblePorts.TryGetValue(port.owner, out var portList);
                if (portList == null)
                {
                    portList = compatiblePorts[port.owner] = new List <PortView>();
                }
                portList.Add(port);
            }

            // Sort ports by position in the node
            foreach (var kp in compatiblePorts)
            {
                kp.Value.Sort((e1, e2) => e1.layout.y.CompareTo(e2.layout.y));
            }

            // Only light compatible anchors when dragging an edge.
            graphView.ports.ForEach((p) => {
                p.OnStartEdgeDragging();
            });

            foreach (var kp in compatiblePorts)
            {
                foreach (var port in kp.Value)
                {
                    port.highlight = true;
                }
            }

            edgeCandidate.UpdateEdgeControl();

            if (panSchedule == null)
            {
                panSchedule = graphView.schedule.Execute(Pan).Every(k_PanInterval).StartingIn(k_PanInterval);
                panSchedule.Pause();
            }
            wasPanned = false;

            edgeCandidate.layer = Int32.MaxValue;

            return(true);
        }
示例#23
0
        public bool HandleMouseDown(MouseDownEvent evt)
        {
            Vector2 mousePosition = evt.mousePosition;

            if (draggedPort == null || edgeCandidateModel == null)
            {
                return(false);
            }

            if (m_EdgeCandidate == null)
            {
                return(false);
            }

            if (m_EdgeCandidate.parent == null)
            {
                GraphView.AddElement(m_EdgeCandidate);
            }

            bool startFromOutput = draggedPort.Direction == Direction.Output;

            edgeCandidateModel.EndPoint = mousePosition;
            m_EdgeCandidate.SetEnabled(false);

            if (startFromOutput)
            {
                edgeCandidateModel.FromPort = draggedPort;
                edgeCandidateModel.ToPort   = null;
            }
            else
            {
                edgeCandidateModel.FromPort = null;
                edgeCandidateModel.ToPort   = draggedPort;
            }

            var portUI = draggedPort.GetUI <Port>(GraphView);

            if (portUI != null)
            {
                portUI.WillConnect = true;
            }

            m_CompatiblePorts = GraphView.GetCompatiblePorts(draggedPort, s_nodeAdapter);

            // Only light compatible anchors when dragging an edge.
            GraphView.ports.ForEach((p) =>
            {
                p.SetEnabled(false);
                p.Highlighted = false;
            });

            foreach (Port compatiblePort in m_CompatiblePorts)
            {
                compatiblePort.SetEnabled(true);
                compatiblePort.Highlighted = true;
            }

            m_EdgeCandidate.UpdateFromModel();

            if (m_PanSchedule == null)
            {
                m_PanSchedule = GraphView.schedule.Execute(Pan).Every(k_PanInterval).StartingIn(k_PanInterval);
                m_PanSchedule.Pause();
            }

            m_WasPanned = false;

            m_EdgeCandidate.layer = Int32.MaxValue;

            return(true);
        }
示例#24
0
        void Fill()
        {
            if (!m_CollectionView.HasValidDataAndBindings())
            {
                return;
            }

            var itemsToAdd          = 0;
            var lastItem            = lastVisibleItem;
            var lastItemIndex       = lastItem?.index ?? -1;
            var firstVisiblePadding = m_StoredPadding;
            var padding             = firstVisiblePadding;

            if (m_CollectionView.dragger is ListViewDraggerAnimated dragger && dragger.draggedItem != null)
            {
                padding -= dragger.draggedItem.rootElement.style.height.value.value;
            }

            for (var i = m_FirstVisibleIndex; i < itemsCount; i++)
            {
                if (padding - m_CollectionView.m_ScrollOffset.y > m_ScrollView.contentViewport.layout.height)
                {
                    break;
                }

                padding += GetItemHeight(i);

                if (i > lastItemIndex)
                {
                    itemsToAdd++;
                }
            }

            // Grow down
            var initialVisibleCount = visibleItemCount;

            for (var i = 0; i < itemsToAdd; i++)
            {
                var index        = i + m_FirstVisibleIndex + initialVisibleCount;
                var recycledItem = GetOrMakeItem();
                m_ActiveItems.Add(recycledItem);
                m_ScrollView.Add(recycledItem.rootElement);
                m_WaitingCache.Add(index);

                Setup(recycledItem, index);
            }

            // Grow upwards
            while (firstVisiblePadding > m_CollectionView.m_ScrollOffset.y)
            {
                var index = m_FirstVisibleIndex - 1;

                if (index < 0)
                {
                    break;
                }

                var recycledItem = GetOrMakeItem();
                m_ActiveItems.Insert(0, recycledItem);
                m_ScrollView.Insert(0, recycledItem.rootElement);
                m_WaitingCache.Add(index);

                Setup(recycledItem, index);

                firstVisiblePadding -= GetItemHeight(index);
                m_FirstVisibleIndex  = index;
            }

            m_ScrollView.contentContainer.style.paddingTop = firstVisiblePadding;
            m_StoredPadding = firstVisiblePadding;
            m_ScheduledItem = null;
        }
示例#25
0
    private IEnumerable <Object> X_BindPanel()
    {
        // Root cachen
        var root = _UIRenderer.visualTree;

        #region Placement & Edit

        // Animation Setup
        var animation = root.Q("placement-animation");
        _animationScheduler = animation?.schedule.Execute(() =>
        {
            if (_animationFrames.Count == 0)
            {
                return;
            }
            // Frame update
            _currentFrame = (_currentFrame + 1) % _animationFrames.Count;
            var frame     = _animationFrames[_currentFrame];
            animation.style.backgroundImage = frame;
            // 100ms Schritte bis Flag gesetzt wird
        }).Every(100).Until(() => { return(_stopAnimation); });
        // Zunaechst pausieren
        _animationScheduler.Pause();

        // Placement Mode Free Button binden
        root.Q <Button>("placement-select-free").clickable.clicked += () =>
        {
            root.Q("placement-mode-select").style.display = DisplayStyle.None;
            root.Q("placement-free-info").style.display   = DisplayStyle.Flex;
#if UNITY_IOS
            if (_session.subsystem is ARKitSessionSubsystem sessionSubsystem)
            {
                sessionSubsystem.coachingGoal = ARCoachingGoal.HorizontalPlane;
                sessionSubsystem.SetCoachingActive(true, ARCoachingOverlayTransition.Animated);
            }
#else
            // Animation ausfuehren
            root.Q("animation-area").style.display = DisplayStyle.Flex;
            _animationScheduler.Resume();
#endif
            GameManager.Instance.SetPlacementMode(GameManager.PlacementMode.Free);
        };

        // Placement Mode QR Code Button binden
        root.Q <Button>("placement-select-qr").clickable.clicked += () =>
        {
            root.Q("placement-mode-select").style.display = DisplayStyle.None;
            root.Q("placement-qr-info").style.display     = DisplayStyle.Flex;
            GameManager.Instance.SetPlacementMode(GameManager.PlacementMode.QR);
        };

        // Placement Accept Button binden
        root.Q <Button>("placement-accept").clickable.clicked += () =>
        {
            // Modus wechseln (Placement -> Interaction)
            GameManager.Instance.SwitchMenu(GameManager.MenuMode.Interaction);
        };

        // Placement Edit Button binden
        root.Q <Button>("placement-edit").clickable.clicked += () =>
        {
            root.Q("placement-panel").style.display      = DisplayStyle.None;
            root.Q("placement-edit-panel").style.display = DisplayStyle.Flex;
        };

        // Edit Accept Button binden
        root.Q <Button>("placement-edit-accept").clickable.clicked += () =>
        {
            root.Q("placement-edit-panel").style.display = DisplayStyle.None;
            root.Q("placement-panel").style.display      = DisplayStyle.Flex;
        };

        // Scale Edit Button binden
        root.Q <Button>("scale-obj").clickable.clicked += () =>
        {
            root.Q("placement-edit-panel").style.display       = DisplayStyle.None;
            root.Q("placement-edit-scale-panel").style.display = DisplayStyle.Flex;
            // Scale Slider Callback speichern
            root.Q <Slider>("scale-edit-slider").RegisterCallback(_floatChange, GameManager.Instance.ChangeScaling);
        };

        // Scale Accept Button binden
        root.Q <Button>("scaling-accept").clickable.clicked += () =>
        {
            root.Q("placement-edit-panel").style.display       = DisplayStyle.Flex;
            root.Q("placement-edit-scale-panel").style.display = DisplayStyle.None;
        };

        // Rotation Edit Button binden
        root.Q <Button>("rotate-obj").clickable.clicked += () =>
        {
            root.Q("placement-edit-panel").style.display        = DisplayStyle.None;
            root.Q("placement-edit-rotate-panel").style.display = DisplayStyle.Flex;
            // Rotation Slider Callback
            root.Q <Slider>("rotate-edit-slider").RegisterCallback(_floatChange, GameManager.Instance.ChangeRotation);
        };

        // Rotation Accept Button binden
        root.Q <Button>("rotation-accept").clickable.clicked += () =>
        {
            root.Q("placement-edit-panel").style.display        = DisplayStyle.Flex;
            root.Q("placement-edit-rotate-panel").style.display = DisplayStyle.None;
        };

        // Move Edit Button binden
        root.Q <Button>("move-obj").clickable.clicked += () =>
        {
            root.Q("placement-edit-panel").style.display          = DisplayStyle.None;
            root.Q("placement-edit-position-panel").style.display = DisplayStyle.Flex;
        };

        // Move Accept Button binden
        root.Q <Button>("move-accept").clickable.clicked += () =>
        {
            root.Q("placement-edit-panel").style.display          = DisplayStyle.Flex;
            root.Q("placement-edit-position-panel").style.display = DisplayStyle.None;
        };

        // Move Up Callbacks
        root.Q <Button>("move-up").RegisterCallback(_moveStart, Vector2.up);
        root.Q <Button>("move-up").RegisterCallback(_moveStop, Vector2.up);

        // Move Down Callbacks
        root.Q <Button>("move-down").RegisterCallback(_moveStart, Vector2.down);
        root.Q <Button>("move-down").RegisterCallback(_moveStop, Vector2.down);

        // Move Right Callbacks
        root.Q <Button>("move-right").RegisterCallback(_moveStart, Vector2.right);
        root.Q <Button>("move-right").RegisterCallback(_moveStop, Vector2.right);

        // Move Left Callbacks
        root.Q <Button>("move-left").RegisterCallback(_moveStart, Vector2.left);
        root.Q <Button>("move-left").RegisterCallback(_moveStop, Vector2.left);

        #endregion

        #region Options

        // Optionen Button binden
        root.Q <Button>("interaction-options").clickable.clicked += () =>
        {
            GameManager.Instance.SwitchMenu(GameManager.MenuMode.Options);
            root.Q("interaction-panel").style.display = DisplayStyle.None;
            root.Q("options-panel").style.display     = DisplayStyle.Flex;
        };

        // Options Exit Button binden
        root.Q <Button>("options-exit").clickable.clicked += () =>
        {
            GameManager.Instance.SwitchMenu(GameManager.MenuMode.Interaction);
            root.Q("desc-area").style.display            = DisplayStyle.None;
            root.Q("hideSections-area").style.display    = DisplayStyle.None;
            root.Q("options-panel").style.display        = DisplayStyle.None;
            root.Q("create-section-panel").style.display = DisplayStyle.None;
            root.Q("switch-daytime-panel").style.display = DisplayStyle.None;
            root.Q("interaction-panel").style.display    = DisplayStyle.Flex;
            root.Q <Button>("options-storeys-edit").RemoveFromClassList("clicked-button");
        };

        // Ghost Mode Button binden
        root.Q <Button>("options-switch-ghosted").clickable.clicked += () =>
        {
            // Ghosted umschalten
            var newVis = GameManager.Instance.CameraController.GetVisualization() == CameraController.Visualization.Normal ?
                         CameraController.Visualization.Ghosted : CameraController.Visualization.Normal;

            if (newVis == CameraController.Visualization.Ghosted)
            {
                root.Q <Button>("options-switch-ghosted").AddToClassList("clicked-button");
            }
            else
            {
                root.Q <Button>("options-switch-ghosted").RemoveFromClassList("clicked-button");
            }

            GameManager.Instance.CameraController.SetVisualization(newVis);
        };

        // Storey Button binden
        root.Q <Button>("options-storeys-edit").clickable.clicked += () =>
        {
            var area = root.Q("hideSections-area");
            area.style.display = area.style.display == DisplayStyle.Flex ?
                                 DisplayStyle.None : DisplayStyle.Flex;

            if (area.style.display == DisplayStyle.Flex)
            {
                root.Q <Button>("options-storeys-edit").AddToClassList("clicked-button");
            }
            else
            {
                root.Q <Button>("options-storeys-edit").RemoveFromClassList("clicked-button");
            }
        };

        // Description Box erstellen
        var listView = root.Q <ListView>("desc-box");
        // Werte Anpassen
        listView.selectionType = SelectionType.None;
        listView.makeItem      = X_MakeLine;
        listView.bindItem      = X_BindLine;
        listView.itemsSource   = _currentDesc;

        // Storey Toggles erstellen
        foreach (string storey in _storeyNames)
        {
            // Toggle erstellen
            Toggle storeyToggle = new Toggle(storey);
            // Stylesheets hinzufuegen
            foreach (var sheet in _UIRenderer.stylesheets)
            {
                storeyToggle.styleSheets.Add(sheet);
            }
            // Werte anpassen
            storeyToggle.name  = "toggle-" + storey;
            storeyToggle.value = true;
            // Dem Container hinzufuegen
            root.Q("toggle-area").Add(storeyToggle);
            // Callback speichern
            storeyToggle.RegisterCallback <ChangeEvent <bool> >(evt =>
                                                                TridifyQuery.SetStoreyActive(GameManager.Instance.PlacedIFC.transform, storey, evt.newValue));
        }

        // Reset Button binden
        root.Q <Button>("reset-btn").clickable.clicked += () =>
        {
            foreach (string storey in _storeyNames)
            {
                // Storey aktivieren
                root.Q <Toggle>("toggle-" + storey).value = true;
                TridifyQuery.SetStoreyActive(GameManager.Instance.PlacedIFC.transform, storey, true);
            }
        };

        // Section Edit Button binden
        root.Q <Button>("options-sections-create").clickable.clicked += () =>
        {
            root.Q("options-panel").style.display        = DisplayStyle.None;
            root.Q("create-section-panel").style.display = DisplayStyle.Flex;
            // Section Slider Callback speichern
            root.Q <Slider>("move-section-slider").RegisterCallback(_floatChange, GameManager.Instance.CameraController.SetCutPlane);
        };

        // Sections Accept Button binden
        root.Q <Button>("create-section-panel-exit").clickable.clicked += () =>
        {
            GameManager.Instance.CameraController.SetCutPlane(0f);
            root.Q("create-section-panel").style.display = DisplayStyle.None;
            root.Q("options-panel").style.display        = DisplayStyle.Flex;
        };

        // Scale Mode Button binden
        root.Q <Button>("options-scale").clickable.clicked += () =>
        {
            // Size umschalten
            var newSize = GameManager.Instance.CurrentSize == GameManager.SizeMode.Scaled ?
                          GameManager.SizeMode.Normal : GameManager.SizeMode.Scaled;

            if (newSize == GameManager.SizeMode.Scaled)
            {
                root.Q <Button>("options-scale").AddToClassList("clicked-button");
            }
            else
            {
                root.Q <Button>("options-scale").RemoveFromClassList("clicked-button");
            }

            GameManager.Instance.SwitchSize(newSize);
        };

        // TOD Edit Button binden
        root.Q <Button>("options-switch-daytime").clickable.clicked += () =>
        {
            root.Q("options-panel").style.display        = DisplayStyle.None;
            root.Q("switch-daytime-panel").style.display = DisplayStyle.Flex;
            // TOD Slider Callback speichern
            root.Q <Slider>("daytime-slider").RegisterCallback <ChangeEvent <float> >(evt =>
            {
                int hours   = (int)evt.newValue / 60;
                int minutes = (int)evt.newValue % 60;
                _sunCalculator.SetTime(hours, minutes);
            });
        };

        // TOD Accept Button binden
        root.Q <Button>("switch-daytime-exit").clickable.clicked += () =>
        {
            root.Q("switch-daytime-panel").style.display = DisplayStyle.None;
            root.Q("options-panel").style.display        = DisplayStyle.Flex;
        };

        #endregion

        #region Initialisierung

        root.Q("placement-mode-select").style.display         = DisplayStyle.Flex;
        root.Q("placement-free-info").style.display           = DisplayStyle.None;
        root.Q("placement-qr-info").style.display             = DisplayStyle.None;
        root.Q("placement-panel").style.display               = DisplayStyle.None;
        root.Q("options-panel").style.display                 = DisplayStyle.None;
        root.Q("interaction-panel").style.display             = DisplayStyle.None;
        root.Q("animation-area").style.display                = DisplayStyle.None;
        root.Q("desc-area").style.display                     = DisplayStyle.None;
        root.Q("hideSections-area").style.display             = DisplayStyle.None;
        root.Q("placement-edit-panel").style.display          = DisplayStyle.None;
        root.Q("placement-edit-scale-panel").style.display    = DisplayStyle.None;
        root.Q("placement-edit-rotate-panel").style.display   = DisplayStyle.None;
        root.Q("placement-edit-position-panel").style.display = DisplayStyle.None;
        root.Q("create-section-panel").style.display          = DisplayStyle.None;
        root.Q("switch-daytime-panel").style.display          = DisplayStyle.None;

        #endregion

        // Kein return notwendig
        return(null);
    }
        HoverBorderPulse(
            this VisualElement target,
            Color pulseStartColor,
            Color pulseEndColor,
            Color original = default,
            bool addBorder = false,
            Vector2 borderStartEndWidth = default,
            int colorDuration           = 1000,
            bool includeChildren        = true,
            bool stopPropagation        = true,
            TrickleDown useTrickleDown  = TrickleDown.NoTrickleDown,
            AnimatedItems <MouseOverEvent, MouseOutEvent> animatedItems = null,
            params ValueAnimation <StyleValues>[] animRunCheck)
        {
            if (borderStartEndWidth == default)
            {
                borderStartEndWidth = new Vector2(1, 0);
            }

            var doHover  = false;
            var pulseIn  = new ValueAnimation <StyleValues>();
            var pulseOut = new ValueAnimation <StyleValues>();
            IVisualElementScheduledItem repeatedAnim = null;

            if (animatedItems == null)
            {
                animatedItems = new AnimatedItems <MouseOverEvent, MouseOutEvent>(target);
            }

            EventCallback <MouseOverEvent> mouseOverEvent = evt =>
            {
                if (animRunCheck.Length > 0)
                {
                    if (animRunCheck.Any(t => t.isRunning))
                    {
                        return;
                    }
                }

                if (!animatedItems.AllowRun)
                {
                    return;
                }

                repeatedAnim = null;
                doHover      = true;
                if (addBorder)
                {
                    target.style.borderBottomWidth = borderStartEndWidth.x;
                    target.style.borderLeftWidth   = borderStartEndWidth.x;
                    target.style.borderRightWidth  = borderStartEndWidth.x;
                    target.style.borderTopWidth    = borderStartEndWidth.x;
                }

                // -- Pulse color will fade original => desired color   --
                // -- via the AnimateTo local function. Once completed  --
                // -- the AnimateFrom function is called animating back --
                // -- to the original color. This is then repeated for  --
                // -- as long as the mouse is hovered over the target   --
                void PulseIn(in ValueAnimation <StyleValues> pulse)
                {
                    if (pulse.isRunning)
                    {
                        pulse.Stop();
                    }
                    pulseIn = target.AnimateBorderColor(pulseStartColor, pulseEndColor, colorDuration, () => PulseOut(pulseIn));
                }

                void PulseOut(in ValueAnimation <StyleValues> pulse)
                {
                    if (pulse.isRunning)
                    {
                        pulse.Stop();
                    }
                    pulseOut = target.AnimateBorderColor(pulseEndColor, pulseStartColor, colorDuration);
                }

                if (pulseIn.isRunning)
                {
                    pulseIn.Stop();
                }
                if (pulseOut.isRunning)
                {
                    pulseOut.Stop();
                }
                repeatedAnim = target.schedule.Execute(() => PulseIn(pulseOut)).StartingIn(0).Every(colorDuration * 2 + 20).Until(() => !doHover);

                if (stopPropagation)
                {
                    evt.StopPropagation();
                }
            };

            EventCallback <MouseOutEvent> mouseOutEvent = evt =>
            {
                if (!animatedItems.AllowRun)
                {
                    return;
                }
                doHover = false;
                if (pulseIn.isRunning)
                {
                    pulseIn?.Stop();
                }
                if (pulseOut.isRunning)
                {
                    pulseOut?.Stop();
                }
                if (repeatedAnim != null && repeatedAnim.isActive)
                {
                    repeatedAnim.Pause();
                }

                if (addBorder)
                {
                    target.style.borderBottomWidth = borderStartEndWidth.y;
                    target.style.borderLeftWidth   = borderStartEndWidth.y;
                    target.style.borderRightWidth  = borderStartEndWidth.y;
                    target.style.borderTopWidth    = borderStartEndWidth.y;
                }

                if (pulseIn.isRunning)
                {
                    pulseIn.Stop();
                }
                if (pulseOut.isRunning)
                {
                    pulseOut.Stop();
                }

                target.style.borderBottomColor = original;
                target.style.borderLeftColor   = original;
                target.style.borderRightColor  = original;
                target.style.borderTopColor    = original;
                if (stopPropagation)
                {
                    evt.StopPropagation();
                }
            };

            target.RegisterCallback(mouseOverEvent, includeChildren, useTrickleDown);
            target.RegisterCallback(mouseOutEvent, includeChildren, useTrickleDown);

            animatedItems.AnimatedItemList = new List <ValueAnimation <StyleValues> > {
                pulseIn, pulseOut
            };
            animatedItems.EventCallbacks = (mouseOverEvent, mouseOutEvent);
            return(animatedItems);
        }
示例#27
0
        // -------------------------------------------------- @HoverBorder
        // ---------------------------------------------------------------
        /// <summary>
        /// Pulse the  border of an element  between two colors
        ///
        /// ** To help combat your element shifting position slightly when a border is applied on hover,
        /// it is a good idea to add a border to your element before hand and just set color to 'initial'
        /// so that it is transparent, then keep 'addBorder' parameter as false.
        /// </summary>
        /// <param name="target">The element in which this function will be applied</param>
        /// <param name="pulseStartColor">Color 1 of 2 in which to pulse between</param>
        /// <param name="pulseEndColor">Color 2 of 2 in which to pulse between</param>
        /// <param name="original">The original color of the element being changed. Can be obtained and passed via 'visualElement.style.backgroundColor.value'</param>
        /// <param name="startColorDurationMs">The amount of time it takes in milliseconds to complete the first color animation</param>
        /// <param name="endColorDurationMs">The amount of time it takes in milliseconds to complete the second color animation</param>
        /// <param name="addBorder">Adds a border if the element does not have one already</param>
        /// <param name="borderStartEndWidth">The width in which the borders should be when displaying</param>
        public static IVisualElementScheduledItem AnimBorderPulse(this VisualElement target, Color pulseStartColor, Color pulseEndColor, Color original = default,
                                                                  int startColorDurationMs    = 1000,
                                                                  int endColorDurationMs      = 1000,
                                                                  bool addBorder              = false,
                                                                  Vector2 borderStartEndWidth = default, Action callback = null)
        {
            if (borderStartEndWidth == default)
            {
                borderStartEndWidth = new Vector2(1, 0);
            }

            var pulseIn  = new ValueAnimation <StyleValues>();
            var pulseOut = new ValueAnimation <StyleValues>();
            IVisualElementScheduledItem repeatedAnim = null;

            doBorderPulse = true;
            if (addBorder)
            {
                target.SetBorderWidth(borderStartEndWidth.x);
            }

            void DoCleanup()
            {
                if (pulseOut.isRunning)
                {
                    pulseOut.Stop();
                }
                if (pulseIn.isRunning)
                {
                    pulseIn.Stop();
                }
                target.SetBorderColor();
                callback?.Invoke();
            }

            // -- Pulse color will fade original => desired color   --
            // -- via the AnimateTo local function. Once completed  --
            // -- the AnimateFrom function is called animating back --
            // -- to the original color. This is then repeated for  --
            // -- as long as the mouse is hovered over the target   --
            void PulseIn(IVisualElementScheduledItem repeated)
            {
                if (!repeated.isActive)
                {
                    DoCleanup(); return;
                }
                if (pulseOut.isRunning)
                {
                    pulseOut.Stop();
                }
                callback?.Invoke();
                pulseIn = target.AnimateBorderColor(pulseStartColor, pulseEndColor, startColorDurationMs, () => PulseOut(repeated));
            }

            void PulseOut(IVisualElementScheduledItem repeated)
            {
                if (!repeated.isActive)
                {
                    DoCleanup(); return;
                }
                if (pulseIn.isRunning)
                {
                    pulseIn.Stop();
                }
                callback?.Invoke();
                pulseOut = target.AnimateBorderColor(pulseEndColor, pulseStartColor, endColorDurationMs);
            }

            var recurring = startColorDurationMs + endColorDurationMs + 20;

            repeatedAnim = target.schedule.Execute(() => PulseIn(repeatedAnim)).StartingIn(0).Every(recurring).Until(() => !doBorderPulse);
            return(repeatedAnim);
        }
示例#28
0
        public VisualElementUpdateInInvoker()
        {
            IVisualElementScheduledItem updateScheduler = schedule.Execute(EditorUpdateInvokerBridge.OnUpdate);

            updateScheduler.Every(25);
        }
 void OnEyeDropperStart(MouseDownEvent e)
 {
     EyeDropper.Start(OnGammaColorChanged);
     m_EyeDropperScheduler = this.schedule.Execute(OnEyeDropperMove).Every(10).StartingIn(10);
     m_EyeDropper.UnregisterCallback <MouseDownEvent>(OnEyeDropperStart);
 }