Exemple #1
0
    private void StartHiding()
    {
        var widget = GetComponentInChildren <UIWidget>();

        StartCoroutine(MathfUtils.LerpWithDuration(1, 0, HidingDuration, (v) =>
        {
            widget.alpha = v;
        }, () => Destroy(gameObject)));
    }
Exemple #2
0
    void UpdateSpeed()
    {
        float dist     = Vector3.Distance(transform.position, _prevPos);
        var   newSpeed = Mathf.Lerp(0, _rvo.maxSpeed, dist / (_rvo.maxSpeed * Time.deltaTime));

        newSpeed = MathfUtils.SmoothChangeValue(_prevSpeed, newSpeed, _changingSpeed, Time.deltaTime, 0, _rvo.maxSpeed);

        _animator.SetFloat("Speed", newSpeed);
        _prevPos   = transform.position;
        _prevSpeed = newSpeed;
    }
Exemple #3
0
        public void TestSmallestAngleDiff()
        {
            const float fromDeg = 350f;
            const float toDeg   = 10f;

            Assert.IsTrue(MathfUtils.SmallestAngleDifferenceDeg(fromDeg, toDeg).IsApproximately(20f));

            const float fromRad = fromDeg * Mathf.Deg2Rad;
            const float toRad   = toDeg * Mathf.Deg2Rad;

            Assert.IsTrue(MathfUtils.SmallestAngleDifferenceRad(fromRad, toRad).IsApproximately(20f * Mathf.Deg2Rad));
        }
Exemple #4
0
    void UpdateSpeed()
    {
        float dist = Vector3.Distance(transform.position, _prevPos);

        _speedInfo = Mathf.Lerp(0, _rvo.maxSpeed, dist / (_rvo.maxSpeed * Time.deltaTime));//currentvalue/maxvalue

        _speedInfo = MathfUtils.SmoothChangeValue(_prevSpeed, _speedInfo, _changingSpeed, Time.deltaTime, 0, _rvo.maxSpeed);
        //_speedInfo = Mathf.SmoothDamp(_prevSpeed, _speedInfo, ref cv, 0.5f, 1, Time.deltaTime);

        _animator.SetFloat("Speed", _speedInfo);
        _prevPos   = transform.position;
        _prevSpeed = _speedInfo;
    }
Exemple #5
0
    void Awake()
    {
        this.collider  = this.GetComponent <Collider>();
        this.rigidbody = this.GetComponent <Rigidbody>();

        this.initialDrag        = this.rigidbody.drag;
        this.initialAngularDrag = this.rigidbody.angularDrag;

        if (this.calculateDensity)
        {
            float objectVolume = MathfUtils.CalculateVolume_Mesh(this.GetComponent <MeshFilter>().mesh, this.transform);
            this.density = this.rigidbody.mass / objectVolume;
        }
    }
Exemple #6
0
 void Start()
 {
     for (int i = 0; i < sampling; i++)
     {
         m = Random.Range(0, 100000);
         n = Random.Range(0, 100000);
         float gcd = MathfUtils.Gcd(m, n);
         if (gcd == 1)
         {
             count++;
         }
     }
     pi = Mathf.Sqrt(6f * sampling / count);
     print(pi);
 }
Exemple #7
0
    private IEnumerator UpdateTimeCoroutine(float frequency) //0.1f
    {
        RemainTime = _startTime;
        SetText(RemainTime < 10 ? "0" + RemainTime.ToString() : RemainTime.ToString(), ":", "0");

        while (RemainTime > 0)
        {
            yield return(new WaitForSeconds(frequency));

            RemainTime -= frequency;
            int remainSec = (int)Mathf.Floor(RemainTime + 0.01f);  //+0.01f для исправления погрешности float
            int remainMs  = MathfUtils.FracDecimalToCeil(RemainTime);
            SetText(remainSec < 10 ? "0" + remainSec.ToString() : remainSec.ToString(), ":", remainMs.ToString());
        }
        if (RemainTime <= 0)
        {
            SetText("00", ":", "0");
        }
    }
Exemple #8
0
    /// <summary>
    /// ブレゼンハムのアルゴリズム(4象限対応)
    /// </summary>
    /// <returns>The line.</returns>
    /// <param name="x0">始点X0.</param>
    /// <param name="y0">始点Y0.</param>
    /// <param name="x1">終点x1</param>
    /// <param name="y1">終点y1</param>
    public static IEnumerable <Vector2> BresenhamsLine(int x0, int y0, int x1, int y1)
    {
        //正=true,負=false
        int  a          = ((y0 * y1) > 0) ? Mathf.Abs(Mathf.Abs(y0) - Mathf.Abs(y1)) : Mathf.Abs(y0) + Mathf.Abs(y1);
        bool incrementA = ((y0 - y1) > 0) ? incrementA = false : incrementA = true;

        int  b          = ((x0 * x1) > 0) ? Mathf.Abs(Mathf.Abs(x0) - Mathf.Abs(x1)) : Mathf.Abs(x0) + Mathf.Abs(x1);
        bool incrementB = ((x0 - x1) > 0) ? incrementB = false : incrementB = true;

        bool changeAB = false;

        if (a > b)
        {
            MathfUtils.Swap(ref a, ref b);
            MathfUtils.Swap(ref x0, ref y0);
            MathfUtils.Swap(ref incrementA, ref incrementB);
            changeAB = true;
        }

        int a2 = a << 2;
        int b2 = b << 2;
        int D  = -b;

        for (int x = 0, y = 0; x <= b; x++)
        {
            if (D > 0)
            {
                y  = y + 1;
                D -= b2;
            }
            D += a2;
            if (changeAB)
            {
                yield return(new Vector2(y0 + (incrementA ? y : -y), x0 + (incrementB ? x : -x)));
            }
            else
            {
                yield return(new Vector2(x0 + (incrementB ? x : -x), y0 + (incrementA ? y : -y)));
            }
        }
    }