Пример #1
0
 public void LateUpdate()
 {
     _position           = _transform.position;
     _transform.position = new Vector3(
         DMath.Round(_position.x, Interval.x),
         DMath.Round(_position.y, Interval.y),
         _position.z);
 }
Пример #2
0
        public void Update()
        {
            Time += RevolutionsPerSecond * UnityEngine.Time.deltaTime;
            Time %= 1f;

            transform.position = transform.parent.position +
                                 (Vector3)DMath.AngleToVector(Time * Mathf.PI * 2f) * Radius;
        }
Пример #3
0
        public void MoveTo(Vector3 target)
        {
            float x = target.x, y = target.y;

            x += (target.x - Center.x) * GetRatio(Factor.x);
            y += (target.y - Center.y) * GetRatio(Factor.y);

            if (SnapInterval != default(Vector2))
            {
                x = DMath.Round(x, SnapInterval.x);
                y = DMath.Round(y, SnapInterval.y);
            }

            transform.position = new Vector2(x, y);
        }
Пример #4
0
        /// <summary>
        /// Turns the specified normal angle and returns the closest side. For example,
        /// a surface whose normal is 90 will return the top side.
        /// </summary>
        /// <param name="normal">The specified normal angle, in degrees.</param>
        /// <returns></returns>
        public static ControllerSide NormalToControllerSide(float normal)
        {
            normal = DMath.PositiveAngle_d(normal);
            if (normal >= 315.0f || normal < 45.0f)
            {
                return(ControllerSide.Right);
            }
            else if (normal < 135.0f)
            {
                return(ControllerSide.Top);
            }
            else if (normal < 225.0f)
            {
                return(ControllerSide.Left);
            }

            return(ControllerSide.Bottom);
        }
Пример #5
0
        public TerrainCastHit Initialize(RaycastHit2D hit, ControllerSide fromSide = ControllerSide.All,
                                         HedgehogController controller             = null, Vector2 start = default(Vector2), Vector2 end = default(Vector2))
        {
            Start        = start;
            End          = end;
            Hit          = hit;
            Side         = fromSide;
            Controller   = controller;
            NormalAngle  = DMath.Modp(DMath.Angle(hit.normal), DMath.DoublePi);
            SurfaceAngle = DMath.Modp(NormalAngle - DMath.HalfPi, DMath.DoublePi);

            if (!hit)
            {
                return(this);
            }

            Transform = hit.transform;
            Collider  = hit.collider;

            return(this);
        }
Пример #6
0
        /// <summary>
        /// Sets the palette to the specified index.
        /// </summary>
        /// <param name="index">The specified index.</param>
        public void SetPalette(int index)
        {
            // If the number is out of bounds just mod it
            index = DMath.Modp(index, PaletteCount);

            for (var i = 0; i < ColorsPerPalette; ++i)
            {
                var absolute = i + index * ColorsPerPalette;
                if (!IgnoreTransparent || AllColors[absolute].a != 0.0f)
                {
#if UNITY_EDITOR
                    PaletteMaterial.SetColor(ColorTo + (i + 1), AllColors[absolute]);
#else
                    PaletteMaterial.SetColor(ColorToIDs[i], AllColors[absolute]);
#endif
                }
            }

            CurrentIndex = index;
            OnPaletteChange.Invoke();
        }
Пример #7
0
 public virtual void SetSprite(int index)
 {
     SpriteRenderer.sprite = Sprites[CurrentIndex = DMath.Modp(index, SpriteCount)];
 }