예제 #1
0
 public static float EaseElastic(float x)
 {
     return(x.Approximately(0f)
         ? 0f
         : x.Approximately(1f)
             ? 1f
             : Mathf.Pow(2f, -10f * x) * Mathf.Sin((x * 10f - 0.75f) * ElasticConst) + 1);
 }
예제 #2
0
 // Expo:
 public static float EaseInOutExpo(float x)
 {
     return(x.Approximately(0f)
         ? 0f
         : x.Approximately(1f)
             ? 1f
             : x < 0.5f ? Mathf.Pow(2f, 20f * x - 10f) / 2f
                 : (2f - Mathf.Pow(2f, -20f * x + 10f)) / 2f);
 }
예제 #3
0
    void SetRatio(float ratio)
    {
        if (GaugeType == AnimType.Invalid)
        {
            SetType();
        }

        if ((GaugeType & AnimType.Translate) != 0)
        {
            transform.localPosition = Vector3.LerpUnclamped(PositionMin, PositionMax, ratio);
        }

        if ((GaugeType & AnimType.Scale) != 0)
        {
            transform.localScale = Vector3.LerpUnclamped(ScaleMin, ScaleMax, ratio);
        }

        if ((GaugeType & AnimType.Rotate) != 0)
        {
            transform.localEulerAngles = Vector3.LerpUnclamped(RotationMin, RotationMax, ratio);
        }

        if ((GaugeType & AnimType.Color) != 0)
        {
            foreach (var renderer in Renderers)
            {
                renderer.material.color = Color.LerpUnclamped(ColorMin, ColorMax, ratio);
            }
        }

        if ((GaugeType & AnimType.Enable) != 0)
        {
            gameObject.SetActive(EnableAt == 1f ? ratio.Approximately(1f, 0.003f) : ratio >= EnableAt);
        }

        if ((GaugeType & AnimType.Particles) != 0)
        {
            if (ParticlesAt == 1f ? ratio.Approximately(1f, 0.003f) : ratio >= ParticlesAt)
            {
                foreach (var particle in Particles)
                {
                    particle.Play();
                }
            }
            else
            {
                foreach (var particle in Particles)
                {
                    particle.Stop();
                }
            }
        }
    }
예제 #4
0
 private void Update()
 {
     if (!m_LastValue.Approximately(m_Control.value))
     {
         m_LastValue = m_Variable.Progress = m_Control.value;
     }
 }
        protected override IEnumerator OnComplete()
        {
            yield return(base.OnComplete());

            if (!_duration.Approximately(0))
            {
                yield return(YieldInstructioner.GetWaitForSeconds(_duration));
            }
        }
예제 #6
0
        public void Out(float duration, AnimationCurve curve, Action callback)
        {
            m_Callback = callback ?? (() => { });

            if (duration.Approximately(0))
            {
                Hide();
            }
            else
            {
                To(0, duration, curve);
            }
        }
예제 #7
0
        public IProgress UpdateProgress(long value, long total, string message = null, IProgress innerProgress = null,
                                        bool dontInvoke = false)
        {
            InnerProgress = innerProgress;
            Total         = total == 0 ? 100 : total;
            Value         = value > Total ? Total : value;
            string previousMessage = Message;

            Message = string.IsNullOrEmpty(message) ? Message : message;

            float fTotal = Total;
            float fValue = Value;

            Percentage = fValue / fTotal;
            float delta = (fValue / fTotal - previousValue / fTotal) * 100f;

            bool shouldSignal = Changed ||
                                (innerProgress?.Changed ?? false) ||
                                previousMessage != Message ||
                                fValue.Approximately(0f) || delta > 1f || fValue.Approximately(fTotal) ||
                                (innerProgress?.Percentage.Approximately(1f) ?? false);

            ;

            if (shouldSignal)
            {             // signal progress in 1% increments or if we don't know what the total is
                previousValue = Value;

                var ret = new ProgressData(Task, Percentage, Value, Total, Message, innerProgress);
                if (!dontInvoke)
                {
                    OnProgress?.Invoke(ret);
                }
                return(ret);
            }
            return(this);
        }
예제 #8
0
 private void UpdateFade()
 {
     if (!m_InTransition)
     {
         return;
     }
     if (!FadeComplete)
     {
         Alpha = Mathf.Lerp(m_FadeStart, m_FadeTarget, m_FadeCurve.Evaluate(m_FadeTarget.Approximately(0) ? 1 - FadeProgress : FadeProgress));
     }
     else
     {
         CompleteFade();
     }
 }
예제 #9
0
    protected virtual void Update()
    {
        if (isDragging)
        {
            currentRotation = -velocityMultiplier * (storedPointer.Position.y - prevPointerYPos);
            rotatingObject.Rotate(0f, currentRotation, 0f);

            prevPointerYPos = storedPointer.Position.y;
        }
        else
        {
            if (!currentRotation.Approximately(0f, 0.1f))
            {
                currentRotation -= Mathf.Sign(currentRotation) * velocityDampen * Time.deltaTime;
                rotatingObject.Rotate(0f, currentRotation, 0f);
            }
        }
    }
예제 #10
0
        private static IEnumerator To(float duration, ProgressChanged onProgress)
        {
            if (duration.Approximately(0f))
            {
                onProgress(1f);
                yield break;
            }

            float time = 0f;

            while (time < duration)
            {
                onProgress(time / duration);
                time += Time.deltaTime;
                yield return(null);
            }

            onProgress(1f);
        }
            protected void UpdateDisplayString(float buttonWidth) {
                if (m_LastButtonWidth.Approximately(buttonWidth)) {
                    return;
                }

                m_LastButtonWidth = buttonWidth;
                m_DisplayString = FullName;

                string trimmedString = m_DisplayString;
                float currentWidth = GUI.skin.label.CalcSize(new GUIContent(m_DisplayString)).x;
                int startIndex = 0;
                while (currentWidth > buttonWidth - kDisplayTextBuffer && startIndex < m_DisplayString.Length) {
                    ++startIndex;
                    trimmedString = "..." + m_DisplayString.Substring(startIndex, m_DisplayString.Length - startIndex);
                    currentWidth = GUI.skin.label.CalcSize(new GUIContent(trimmedString)).x;
                }

                m_DisplayString = trimmedString;
            }
예제 #12
0
        private static IEnumerator To(float duration, Action <float> onProgressChanged)
        {
            if (duration.Approximately(0f))
            {
                onProgressChanged(1f);
                yield break;
            }

            float _time = 0f;

            while (_time < duration)
            {
                onProgressChanged(_time / duration);
                _time += Time.deltaTime;
                yield return(null);
            }

            onProgressChanged(1f);
        }
예제 #13
0
        private float GetXVelocity(float startT, float t, out bool finished)
        {
            finished = false;
            if (prevXVelocityCurve == null)
            {
                return(prevVelocity.x);
            }

            if (prevIsDeaccel)
            {
                float v = prevXVelocityCurve.Evaluate(startT + t) * Mathf.Sign(prevVelocity.x);
                finished = v.Approximately(0, 0.1f);
                return(v);
            }
            else
            {
                float v = prevXVelocityCurve.Evaluate(startT + t) * Mathf.Sign(input.Movement.x);
                finished = Mathf.Abs(v) >= prevXVelocityCurve.Evaluate(1000) - 0.2f;
                return(v);
            }
        }
예제 #14
0
        private void Update()
        {
            if (!m_Cam)
            {
                return;
            }

            float currentAspect = (float)Screen.width / Screen.height;

            if (currentAspect.Approximately(m_LastAspect, 0.01f))
            {
                return;
            }

            m_LastAspect = currentAspect;

            if (m_LastAspect.Approximately(WantedAspectRatio, 0.01f))
            {
                m_Cam.rect = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
                return;
            }

            // Pillarbox
            if (m_LastAspect > WantedAspectRatio)
            {
                float inset = 1.0f - WantedAspectRatio / m_LastAspect;
                m_Cam.rect = new Rect(inset / 2, 0.0f, 1.0f - inset, 1.0f);
            }

            // Letterbox
            else
            {
                float inset = 1.0f - m_LastAspect / WantedAspectRatio;
                m_Cam.rect = new Rect(0.0f, inset / 2, 1.0f, 1.0f - inset);
            }
        }
예제 #15
0
 // Token: 0x0600036B RID: 875 RVA: 0x0000C37A File Offset: 0x0000A57A
 public static bool Approximately(this float first, float second)
 {
     return(first.Approximately(second, float.Epsilon));
 }
예제 #16
0
        public bool ConditionMatched(ModuleBlockMover block, bool localInput, float m_Val, float m_Vel)
        {
            bool Invert = m_InputParam < 0;

            switch (m_InputType)
            {
            case InputType.AlwaysOn:
                return(true);

            case InputType.OnPress:
                m_InputParam = Mathf.Sign(m_InputParam);
                return((KeyState(CanInput(block, localInput)) == 1) != Invert);

            case InputType.OnRelease:
                m_InputParam = Mathf.Sign(m_InputParam);
                return((KeyState(CanInput(block, localInput)) == 3) != Invert);

            case InputType.WhileHeld:
                m_InputParam = Mathf.Sign(m_InputParam);
                return((KeyState(CanInput(block, localInput)) != 0) != Invert);

            case InputType.Toggle:
                m_InputParam = Mathf.Sign(m_InputParam - 0.001f);
                if (KeyState(CanInput(block, localInput)) == 1)
                {
                    m_InputParam = -m_InputParam;
                }
                return(m_InputParam > 0);

            case InputType.EnemyTechIsNear:
                Visible target = block.GetTarget();
                if (target == null)
                {
                    return(Invert);
                }
                return(((target.centrePosition - block.block.centreOfMassWorld).sqrMagnitude < m_InputParam * m_InputParam) != Invert);

            case InputType.PlayerTechIsNear:
                if (Singleton.playerTank == null)
                {
                    return(Invert);
                }
                if (Singleton.playerTank == block.block.tank)
                {
                    return(!Invert);
                }
                return(((Singleton.playerTank.visible.centrePosition - block.block.centreOfMassWorld).sqrMagnitude < m_InputParam * m_InputParam) != Invert);

            case InputType.AboveSurfaceElev:
                var comw = block.block.centreOfMassWorld;
                ManWorld.inst.GetTerrainHeight(comw, out float outHeight);
                return((comw.y > outHeight + m_InputParam) != Invert);

            case InputType.AboveVelocity:
                return((block.block.tank.rbody.GetPointVelocity(block.block.centreOfMassWorld).sqrMagnitude > m_InputParam * m_InputParam) != Invert);

            case InputType.IfPosAbove:
                if (block.IsPlanarVALUE)
                {
                    return(((block.PVALUE + 900) % 360) - 180 > m_InputParam);
                }
                m_InputParam = Mathf.Max(m_InputParam, 0f);
                return(block.PVALUE > m_InputParam);

            case InputType.IfPosBelow:
                if (block.IsPlanarVALUE)
                {
                    return(((block.PVALUE + 900) % 360) - 180 < m_InputParam);
                }
                m_InputParam = Mathf.Max(m_InputParam, 0f);
                return(block.PVALUE < m_InputParam);

            case InputType.IfPosEqual:
                if (block.IsPlanarVALUE)
                {
                    return(m_InputParam.Approximately(((block.PVALUE + 900) % 360) - 180));
                }
                m_InputParam = Mathf.Max(m_InputParam, 0f);
                return(block.PVALUE.Approximately(m_InputParam));

            case InputType.IfSpeedAbove:
                return(m_Vel > m_InputParam);

            case InputType.IfSpeedBelow:
                return(m_Vel < m_InputParam);

            case InputType.IfSpeedEqual:
                return(m_Vel.Approximately(m_InputParam));

            default:
                return(false);
            }
        }
예제 #17
0
 public static float RoundToMultipleOf(float value, float multiple)
 => multiple.Approximately(0) ? value : (value / multiple).Round() * multiple;
예제 #18
0
 public static float EaseOutExpo(float x)
 {
     return(x.Approximately(1f) ? 1f : 1 - Mathf.Pow(2f, -10f * x));
 }
예제 #19
0
 public static float EaseInExpo(float x)
 {
     return(x.Approximately(0f) ? 0f : Mathf.Pow(2f, 10f * x - 10f));
 }
예제 #20
0
        // Currently this expects a string of plain text,
        // and will not correctly handle rich text tags etc.
        private IEnumerator FadeTextByWord(string text)
        {
            MatchCollection words         = Regex.Matches(text, @"\S+\s*");
            int             length        = words.Count;
            float           duration      = text.Length / m_TravelSpeed;
            float           wordPerSecond = duration / words.Count;

            // Build a character buffer of our desired text,
            // with a rich text "color" tag around every word.
            StringBuilder builder    = new StringBuilder();
            Color32       color      = m_Text.color;
            string        startColor = string.Format("<color=#{0}{1}{2}{3}{4}{5}00>", s_NibbleToHex[color.r >> 4], s_NibbleToHex[color.r & 0xF], s_NibbleToHex[color.g >> 4], s_NibbleToHex[color.g & 0xF], s_NibbleToHex[color.b >> 4], s_NibbleToHex[color.b & 0xF]);

            Dictionary <int, int> alphaIndexes = new Dictionary <int, int>();

            Debug.Log("String length = " + text.Length + " and word count = " + length);
            for (int i = 0; i < length; i++)
            {
                Match current = words[i];
                builder.Append(startColor);
                alphaIndexes[i] = builder.Length - 3;
                builder.Append(current.Value);
                builder.Append("</color>");
            }

            // Each frame, update the alpha values along the fading frontier.
            float fadingProgress = 0f;
            int   opaqueWords    = -1;

            while (opaqueWords < length - 1)
            {
                yield return(null);

                fadingProgress += Time.deltaTime;
                float leadingEdge = fadingProgress / wordPerSecond;
                int   lastWord    = Mathf.Min(length - 1, Mathf.FloorToInt(leadingEdge));
                int   newOpaque   = opaqueWords;
                for (int i = lastWord; i > opaqueWords; i--)
                {
                    byte fade = (byte)(m_FadeDuration.Approximately(0) ? 255f : (255f * Mathf.Clamp01((leadingEdge - i) / (wordPerSecond * m_FadeDuration))));
                    builder[alphaIndexes[i]]     = s_NibbleToHex[fade >> 4];
                    builder[alphaIndexes[i] + 1] = s_NibbleToHex[fade & 0xF];
                    if (fade == 255)
                    {
                        newOpaque = Mathf.Max(newOpaque, i);
                    }
                }

                opaqueWords = newOpaque;
                // This allocates a new string.
                m_Text.text = builder.ToString();
            }

            // Once all the characters are opaque,
            // ditch the unnecessary markup and end the routine.
            m_Text.text = text;

            // Mark the fade transition as finished.
            // This can also fire an event/message if you want to signal UI.
            m_Fade = null;

            OnComplete.Invoke();
        }
예제 #21
0
 public static bool Approximately(this float f, float f2)
 {
     return(f.Approximately(f2, Mathf.Epsilon));
 }
예제 #22
0
 private static float ElasticOut(float t) => t.Approximately(1f) ? 1f : 1f - ElasticIn(1f - t);