示例#1
0
        /// <summary>
        /// Processes the value changes and emits the appropriate events.
        /// </summary>
        public virtual void Process()
        {
            if (!isActiveAndEnabled)
            {
                return;
            }

            if (!Value.ApproxEquals(previousValue))
            {
                previousValue = Value;
                EmitValueChanged();
                EmitNormalizedValueChanged();
            }

            if (!StepValue.ApproxEquals(previousStepValue))
            {
                previousStepValue = StepValue;
                EmitStepValueChanged();
            }

            float targetValue        = GetTargetValue();
            bool  targetValueReached = NormalizedValue.ApproxEquals(targetValue, targetValueReachedThreshold);
            bool  shouldEmitEvent    = !previousTargetValueReached && targetValueReached;

            previousTargetValueReached = targetValueReached;

            if (CanMoveToTargetValue() && shouldEmitEvent)
            {
                EmitTargetValueReached();
            }
        }
示例#2
0
        /// <summary>
        /// Checks if the target value has been reached.
        /// </summary>
        protected virtual void CheckTargetValueReached()
        {
            float targetValue        = GetTargetValue();
            bool  targetValueReached = NormalizedValue.ApproxEquals(targetValue, TargetValueReachedThreshold);
            bool  shouldEmitEvent    = !previousTargetValueReached && targetValueReached;

            previousTargetValueReached = targetValueReached;

            if (CanMoveToTargetValue() && shouldEmitEvent)
            {
                EmitTargetValueReached();
            }
        }
示例#3
0
        /// <summary>
        /// Emits the NormalizedValueChanged event.
        /// </summary>
        protected virtual void EmitNormalizedValueChanged()
        {
            if (isMovingToInitialTargetValue && NormalizedValue.ApproxEquals(Facade.InitialTargetValue, TargetValueReachedThreshold))
            {
                ResetToCacheAfterReachedInitialTargetValue();
                return;
            }

            if (!EmitEvents)
            {
                return;
            }

            Facade.NormalizedValueChanged?.Invoke(NormalizedValue);
        }
示例#4
0
        public virtual void Process()
        {
            if (wasDisabled || !Value.ApproxEquals(previousValue))
            {
                if (!isMoving && previousValue < float.MaxValue)
                {
                    EmitStartedMoving();
                    isMoving = true;
                }
                previousValue = Value;
                EmitValueChanged();
                EmitNormalizedValueChanged();
            }
            else
            {
                if (isMoving)
                {
                    EmitStoppedMoving();
                    isMoving = false;
                }
            }

            if (!StepValue.ApproxEquals(previousStepValue))
            {
                previousStepValue = StepValue;
                EmitStepValueChanged();
            }

            float targetValue        = GetTargetValue();
            bool  targetValueReached = NormalizedValue.ApproxEquals(targetValue, TargetValueReachedThreshold);
            bool  shouldEmitEvent    = !previousTargetValueReached && targetValueReached;

            previousTargetValueReached = targetValueReached;

            if (CanMoveToTargetValue() && shouldEmitEvent)
            {
                EmitTargetValueReached();
            }

            wasDisabled = false;
        }