Exemple #1
0
#pragma warning restore 649

        public void Invoke()
        {
            if (DividedFloat != null)
            {
                if (divisorValue.Value == 0)
                {
                    DividedFloat?.Invoke(float.MaxValue);
                }
                else
                {
                    DividedFloat?.Invoke((float)dividendValue.Value / divisorValue.Value);
                }
            }

            if (DividedInt != null)
            {
                if (divisorValue.Value == 0)
                {
                    DividedInt.Invoke(int.MaxValue);
                }
                else
                {
                    DividedInt.Invoke(dividendValue.Value / divisorValue.Value);
                }
            }
        }
    private IEnumerator PauseAnimatorRoutine(float pauseDurationSeconds)
    {
        var oldSpeed = animator.speed;

        animator.speed = 0;

        isPaused = true;
        onPauseStarts?.Invoke();

        var timer = 0f;

        onPauseProgress?.Invoke(0);

        while (timer < pauseDurationSeconds && isPaused)
        {
            yield return(null);

            timer += Time.deltaTime;

            onPauseProgress?.Invoke(timer / pauseDurationSeconds);
        }

        onPauseProgress?.Invoke(1);

        onPauseEnds?.Invoke();

        animator.speed = oldSpeed;
        isPaused       = false;
    }
 public void ResendEvents()
 {
     musicMutedEvent?.Invoke(!musicEnabled);
     musicVolumeEvent?.Invoke(save.musicVolume);
     fxVolumeEvent?.Invoke(save.fxVolume);
     fxMutedEvent?.Invoke(!fxEnabled);
 }
Exemple #4
0
#pragma warning restore 649

        public void Invoke()
        {
            if (ProductFloat != null)
            {
                ProductFloat?.Invoke((float)firstFactor.Value * secondFactor.Value);
            }

            if (ProductInt != null)
            {
                ProductInt.Invoke(firstFactor.Value * secondFactor.Value);
            }
        }
Exemple #5
0
#pragma warning restore 649

        public void Invoke()
        {
            if (SumFloat != null)
            {
                SumFloat?.Invoke((float)firstIngredient.Value + secondIngredient.Value);
            }

            if (SumInt != null)
            {
                SumInt.Invoke(firstIngredient.Value + secondIngredient.Value);
            }
        }
    private IEnumerator invoke(float time)
    {
        float timer = 0;

        while (timer < 1)
        {
            yield return(0);

            output?.Invoke(curve.Evaluate(timer));
            timer += Time.deltaTime / time;
        }
        output?.Invoke(curve.Evaluate(1));
    }
 public void Input(float input)
 {
     if (debug)
     {
         print("input:" + input);
     }
     if (clamp)
     {
         output?.Invoke(Mathf.Clamp(remapCurve.Evaluate(input), outputRange.x, outputRange.y));
     }
     else
     {
         output?.Invoke(remapCurve.Evaluate(input));
     }
 }
Exemple #8
0
        public virtual void DealDamage(float damageAmount, Vector3?hitPosition = null, Vector3?hitNormal = null, bool reactToHit = true, GameObject sender = null, GameObject receiver = null)
        {
            if (destroyed)
            {
                return;
            }

            Health -= damageAmount;

            onDamaged?.Invoke(damageAmount);

            // Invector Integration
#if INVECTOR_BASIC || INVECTOR_AI_TEMPLATE
            if (SendDamageToInvector)
            {
                var d = new Invector.vDamage();
                d.hitReaction = reactToHit;
                d.hitPosition = (Vector3)hitPosition;
                d.receiver    = receiver == null ? this.gameObject.transform : null;
                d.damageValue = (int)damageAmount;

                this.gameObject.ApplyDamage(new Invector.vDamage(d));
            }
#endif

            if (Health <= 0)
            {
                DestroyThis();
            }
        }
Exemple #9
0
    IEnumerator SpeedOffsets()
    {
        while (true)
        {
            float min = float.MaxValue, max = float.MinValue;
            for (int i = 1; i < samples.Length; i++)
            {
                samples[i - 1] = samples[i];
            }

            samples[samples.Length - 1] = speedOffset;

            foreach (var sample in samples)
            {
                if (min > sample)
                {
                    min = sample;
                }
                if (max < sample)
                {
                    max = sample;
                }
            }

            maxDelta = Mathf.Abs(max - min);
            onVaribilityChange?.Invoke(maxDelta);

            yield return(new WaitForSecondsRealtime(.25f));
        }
    }
Exemple #10
0
 IEnumerator BarValueUpdateRoutine()
 {
     while (true)
     {
         onBarValueChange?.Invoke(Mathf.InverseLerp(startTime, endTime, Time.timeSinceLevelLoad));
         yield return(new WaitForSecondsRealtime(0.1f));
     }
 }
Exemple #11
0
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            _spaceCount++;
            FloatEvent?.Invoke(_spaceCount);

            ActionEvent?.Invoke(true, 56);
        }
    }
Exemple #12
0
 public void OnTextChanged(string text)
 {
     if (enabled)
     {
         float value;
         if (float.TryParse(text, out value))
         {
             onValueChanged?.Invoke(value);
         }
     }
 }
Exemple #13
0
    private IEnumerator moveToInTimeRelativeLocallyAndOutput(Vector3 targetPosition, float time)
    {
        float   timer     = 0;
        Vector3 oPos      = transform.localPosition;
        Vector3 tPosition = oPos + targetPosition;
        float   distance  = Vector3.Distance(oPos, tPosition);
        float   currentD  = 0;

        while (timer < 1)
        {
            yield return(0);

            float t = moveCurve.Evaluate(timer) * distance;
            movementOutput?.Invoke(t - currentD);
            currentD = t;
            transform.localPosition = Vector3.LerpUnclamped(oPos, tPosition, moveCurve.Evaluate(timer));
            timer += Time.deltaTime / time;
        }
        movementOutput?.Invoke(distance - currentD);
        transform.localPosition = tPosition;
    }
Exemple #14
0
    IEnumerator PeriodicSampler()
    {
        while (true)
        {
            onValueSpeed?.Invoke((float)controller.speed);
            onValueDeviation?.Invoke((float)controller.maxDelta);
            onValueDistance?.Invoke((float)controller.safeDistance);

            onSamplingFinished?.Invoke();

            yield return(new WaitForSecondsRealtime(1));
        }
    }
    IEnumerator CycleAI()
    {
        while (true)
        {
            speed    = myRigidbody.velocity.magnitude;
            distance = (float)fuzzyEngine.Defuzzify(new { speed = speed, variability = variability });

            //controller.controllers[0].target = distance;
            onValue?.Invoke(distance);

            yield return(new WaitForSecondsRealtime(1));
        }
    }
Exemple #16
0
    /// <summary>
    /// This function increases the amount of the given resource type by the given amount.
    /// </summary>
    /// <param name="resource">Takes in the type of resource that needs to be increased.</param>
    /// <param name="amount">Takes in the amount with which the given resource has to be increased.</param>
    public static void IncreaseResource(ResourceType resource, float amount)
    {
        switch (resource)
        {
        case ResourceType.happiness:
            if ((_currentAmountHappiness + amount) < 100)
            {
                _currentAmountHappiness += amount;
            }
            else
            {
                _currentAmountHappiness = 100;
            }

            OnHappinessChanged?.Invoke(_currentAmountHappiness);
            break;

        case ResourceType.villagers:
            _currentAmountVillagers += (int)amount;
            break;
        }
    }
Exemple #17
0
 private void OnButtonClick(int i)
 {
     if (i == currentID + 1)
     {
         currentID++;
         times.Add(Time.time - startTime);
         if (currentID == 25)
         {
             OnFinishSplits?.Invoke(times);
             restartButton.gameObject.SetActive(true);
         }
     }
 }
Exemple #18
0
            /// <summary>What to trigger when this is invoked.</summary>
            /// <param name="existsEvent">Whether the value exists.</param>
            /// <param name="stringEvent">The event to invoke if this is a string.</param>
            /// <param name="intEvent">The event to invoke if this is an int.</param>
            /// <param name="floatEvent">The event to invoke if this is a float.</param>
            public void Invoke(UnityEvent existsEvent, StringEvent stringEvent, IntEvent intEvent, FloatEvent floatEvent)
            {
                if (this.key.IsNullOrEmpty())
                {
                    return;
                }

                if (PlayerPrefs.HasKey(this.key))
                {
                    existsEvent.Invoke();
                }

                stringEvent?.Invoke(PlayerPrefs.GetString(this.key));
                intEvent?.Invoke(PlayerPrefs.GetInt(this.key));
                floatEvent?.Invoke(PlayerPrefs.GetFloat(this.key));
            }
Exemple #19
0
        private void SetNorm(float norm)
        {
            var changed = _norm != norm;

            _norm = norm;
            foreach (var fill in fills)
            {
                fill.fillAmount = norm;
            }
            if (changed && IsFinished)
            {
//                Debug.Log($"FillBar Finished ({(int)(norm * 100)}%)");
                CurrentAmount = amount;
                onFinished?.Invoke(amount);
            }
        }
Exemple #20
0
    void Update()
    {
        speedOffset = Mathf.Sin(Time.timeSinceLevelLoad * a + c) +
                      Mathf.Sin(Time.timeSinceLevelLoad * b + a) +
                      Mathf.Sin(Time.timeSinceLevelLoad * c + b);

        var targetDistance = Mathf.InverseLerp(minDistance,
                                               maxDistance, distance + speedOffset);

        currentDistance = Mathf.Lerp(currentDistance, targetDistance, 0.1f);

        transform.position = new Vector3(transform.position.x,
                                         Mathf.Lerp(baseDistanceY, maxDistanceY,
                                                    currentDistance), transform.position.z);

        onDistanceChange?.Invoke(distance);
    }
Exemple #21
0
    public IEnumerator _Speak()
    {
        audioSource.Play();
        while (audioSource.isPlaying)
        {
            yield return(0);

            audioSource.GetSpectrumData(data, channel, fTWindow);
            if (debug)
            {
                for (int i = 0; i < 64; i++)
                {
                    Debug.DrawLine(new Vector3(i * 0.1f, 0, 0), new Vector3(i * 0.1f, data[i], 0));
                }
            }
            onSpeak?.Invoke(data[outputFrequencyIndex]);
        }
    }
        private void HandleDragUpdate(InteractionPoint[] interactionPoint, Vector3 position, Quaternion rotation, float scale)
        {
            float percentage = MathUtilities.TraveledPercentage(startPosition.position, endPosition.position, position);

            handle.transform.position = Vector3.Lerp(startPosition.position, endPosition.position, Mathf.Clamp01(percentage));
            _value = Mathf.Lerp(minValue, maxValue, percentage);
            if (wholeNumbers)
            {
                _value = Mathf.Round(_value);
            }
            OnChanged?.Invoke(Value);

            //draw connection line:
            Lines.DrawLine(_lineID, Color.green, Color.green, .0025f, interactionPoint[0].position, handle.transform.position);

            //dragged too far?
            if (Vector3.Distance(interactionPoint[0].position, handle.transform.position) > dragBreakDistance)
            {
                handle.StopGrab();
            }
        }
        public void OnAction(InputAction.CallbackContext context)
        {
            var value = context.ReadValue <float>();

            switch (_targetType)
            {
            case TargetType.Int:
                var iv = (int)Mathf.Lerp(_intValueMin, _intValueMax, value);
                _intEvent?.Invoke(iv);
                break;

            case TargetType.Float:
                var fv = Mathf.Lerp(_floatValueMin, _floatValueMax, value);
                _floatEvent?.Invoke(fv);
                break;

            case TargetType.Vector3:
                var vv = Vector3.Lerp(_vector3ValueMin, _vector3ValueMax, value);
                _vector3Event?.Invoke(vv);
                break;
            }
        }
Exemple #24
0
        private void UpdateFiller(bool sendUpdate)
        {
            if (isIntegerSlider)
            {
                fillerImage.fillAmount = Mathf.Round(value * maxIntegerValue) / maxIntegerValue;
            }
            else
            {
                fillerImage.fillAmount = value;
            }

            if (Application.isPlaying && sendUpdate)
            {
                if (isIntegerSlider)
                {
                    onIntValueSet?.Invoke(Mathf.RoundToInt(value * maxIntegerValue));
                }
                else
                {
                    onValueSet?.Invoke(value);
                }
            }
        }
        //Loops:
        private void Update()
        {
            if (_previousHand != handedness)
            {
                _previousHand = handedness;
                GetControl();
            }

            //no control?
            if (Control == null)
            {
                return;
            }

            //control pose:
            Position    = Control.Position;
            Orientation = Control.Orientation;

            if (followControl)
            {
                transform.position = Position;
                transform.rotation = Orientation;
            }

            //touch down:
            if (!Touch && Control.Touch1Active)
            {
                Touch = true;
                StartCoroutine("TouchHold");

                //resets:
                TouchMoved       = false;
                TouchRadialDelta = 0;

                //current for comparisons:
                Vector4 tempTouch = GetTouch1Info();

                //double - must be close to last touch and quick enough:
                float distanceFromLastTouchDown = Vector2.Distance(tempTouch, TouchValue);
                float durationSinceLastTouch    = Time.realtimeSinceStartup - _lastTouchTime;
                if (distanceFromLastTouchDown <= _maxDoubleTouchDistance && durationSinceLastTouch < _touchDoubleDuration)
                {
                    OnDoubleTap?.Invoke(TouchValue);
                }

                //cache:
                TouchValue       = tempTouch;
                _touchBeganValue = TouchValue;
                _touchBeganTime  = Time.realtimeSinceStartup;
                _lastTouchTime   = Time.realtimeSinceStartup;

                OnTouchDown?.Invoke(TouchValue);
            }

            //touch movement:
            if (Touch)
            {
                //current for comparisons:
                Vector4 tempTouch = GetTouch1Info();

                //touch force delta tracking:
                if (tempTouch.z != TouchValue.z)
                {
                    if (tempTouch.z > TouchValue.z)
                    {
                        //touch is getting stronger:
                        if (!ForceTouch && tempTouch.z >= _forceTouchDownThreshold)
                        {
                            ForceTouch       = true;
                            _wasForceTouched = true;
                            OnForceTouchDown?.Invoke();
                        }
                    }
                    else
                    {
                        //touch is getting weaker:
                        if (ForceTouch && tempTouch.z <= _forceTouchUpThreshold)
                        {
                            ForceTouch = false;
                            OnForceTouchUp?.Invoke();
                        }
                    }
                }

                //since force touch can make values go crazy we ignore everything if it happened:
                if (!_wasForceTouched)
                {
                    //did we have an intentional initial move?
                    if (!TouchMoved)
                    {
                        //did we initially move far enough?
                        float movedFromInitialTouchDistance = Vector2.Distance(tempTouch, _touchBeganValue);

                        if (movedFromInitialTouchDistance > _touchBeganMovingThreshold)
                        {
                            TouchMoved = true;

                            OnTouchBeganMoving?.Invoke();
                        }
                    }

                    //only track subsequent moves if we initially began moving:
                    if (TouchMoved)
                    {
                        //did we have an intentional move?
                        float movedDistance = Vector2.Distance(TouchValue, tempTouch);
                        if (TouchValue != tempTouch && movedDistance > 0 && movedDistance > _minTouchMove)
                        {
                            //moved:
                            OnTouchMove?.Invoke(TouchValue);

                            //radial move:
                            float angleDelta = tempTouch.w - TouchValue.w;
                            if (OnTouchRadialMove != null)
                            {
                                TouchRadialDelta = angleDelta;
                                OnTouchRadialMove?.Invoke(angleDelta);
                            }

                            //cache:
                            TouchValue = tempTouch;
                        }
                    }
                }
            }

            //touch up:
            if (!Control.Touch1Active && Touch)
            {
                //status:
                Touch      = false;
                TouchMoved = false;
                TouchValue = GetTouch1Info();
                StopCoroutine("TouchHold");

                //meta on touch sequence:
                Vector2 start = _touchBeganValue;
                Vector2 end   = TouchValue;
                float   distanceFromTouchStart = Vector2.Distance(start, end);
                float   durationFromTouchStart = Time.realtimeSinceStartup - _touchBeganTime;

                //since force touch can make values go crazy we ignore everything if it happened:
                if (!_wasForceTouched)
                {
                    //swipe determinations:
                    if (distanceFromTouchStart >= _minSwipeDistance)
                    {
                        //swiped - we only calculate if the event is registered:
                        if (OnSwipe != null)
                        {
                            //swipes must be quicker than _maxSwipeDuration:
                            if (durationFromTouchStart < _maxSwipeDuration)
                            {
                                //get angle:
                                Vector2 swipe      = (end - start).normalized;
                                float   swipeAngle = Vector2.Angle(Vector2.up, swipe);

                                //swiped to the left? then we need to continue to 360 degrees:
                                if (end.x < start.x)
                                {
                                    swipeAngle = 360 - swipeAngle;
                                }

                                //determine swipe direction:
                                MLInputControllerTouchpadGestureDirection direction = MLInputControllerTouchpadGestureDirection.Left;
                                if (swipeAngle > 315 || swipeAngle <= 45)
                                {
                                    direction = MLInputControllerTouchpadGestureDirection.Up;
                                }
                                else if (swipeAngle > 45 && swipeAngle <= 135)
                                {
                                    direction = MLInputControllerTouchpadGestureDirection.Right;
                                }
                                else if (swipeAngle > 135 && swipeAngle <= 225)
                                {
                                    direction = MLInputControllerTouchpadGestureDirection.Down;
                                }

                                OnSwipe?.Invoke(direction);
                            }
                        }
                    }
                    else
                    {
                        //tapped - we only calculate if the event is registered:
                        if (OnTapped != null)
                        {
                            //taps must be quicker than _maxTapDuration:
                            if (durationFromTouchStart < _maxTapDuration)
                            {
                                //determine tap location:
                                MLInputControllerTouchpadGestureDirection direction = MLInputControllerTouchpadGestureDirection.Left;
                                if (TouchValue.w > 315 || TouchValue.w <= 45)
                                {
                                    direction = MLInputControllerTouchpadGestureDirection.Up;
                                }
                                else if (TouchValue.w > 45 && TouchValue.w <= 135)
                                {
                                    direction = MLInputControllerTouchpadGestureDirection.Right;
                                }
                                else if (TouchValue.w > 135 && TouchValue.w <= 225)
                                {
                                    direction = MLInputControllerTouchpadGestureDirection.Down;
                                }

                                OnTapped?.Invoke(direction);
                            }
                        }
                    }
                }

                //we ultimately released so fire that event:
                OnTouchUp?.Invoke(TouchValue);

                //reset force touch activity on full release only to avoid any slight swipes at the end of release:
                _wasForceTouched = false;

                //if a user releases rapidly after a force press this will catch the release:
                if (ForceTouch)
                {
                    ForceTouch = false;
                    OnForceTouchUp?.Invoke();
                }
            }

            //trigger:
            if (TriggerValue != Control.TriggerValue)
            {
                //trigger began moving:
                if (TriggerValue == 0)
                {
                    OnTriggerPressBegan?.Invoke();
                }

                //trigger moved:
                OnTriggerMove?.Invoke(Control.TriggerValue - TriggerValue);

                //trigger released:
                if (Control.TriggerValue == 0)
                {
                    OnTriggerPressEnded?.Invoke();
                }

                TriggerValue = Control.TriggerValue;
            }
        }
 protected override bool InvokeParsedValueChange(string input)
 {
     OnValueChanged?.Invoke(float.Parse(input));
     return(OnValueChanged.GetPersistentEventCount() > 0);
 }
Exemple #27
0
 public virtual void OnEventRaised(float argument)
 {
     Response?.Invoke(argument);
 }
Exemple #28
0
 //Input
 public void Invoke(float input)
 {
     output?.Invoke(Random.Range(range.x, range.y));
 }
Exemple #29
0
 private void FPS(NetworkMessage msg)
 {
     OnFPS.Invoke(msg.ReadMessage <FloatMessage>().value);
 }
Exemple #30
0
 void Update()
 {
     _valueEvent.Invoke(_value.Step());
 }