Exemplo n.º 1
0
        void SnapToGrid()
        {
            var isometricGrid = FindObjectOfType <IsometricGrid>();

            if (isometricGrid != null)
            {
                var p0        = _point0;
                var p1        = _point1;
                var p0Ceiling = new Vector2((float)Math.Ceiling(p0.x / isometricGrid.GridStep) * isometricGrid.GridStep, (float)Math.Ceiling(p0.y / isometricGrid.GridStep) * isometricGrid.GridStep);
                var p0Floor   = new Vector2(p0Ceiling.x - isometricGrid.GridStep, p0Ceiling.y - isometricGrid.GridStep);
                p0Ceiling.x -= p0.x;
                p0Ceiling.y -= p0.y;
                p0Floor.x   -= p0.x;
                p0Floor.y   -= p0.y;
                var p1Ceiling = new Vector2((float)Math.Ceiling(p1.x / isometricGrid.GridStep) * isometricGrid.GridStep, (float)Math.Ceiling(p1.y / isometricGrid.GridStep) * isometricGrid.GridStep);
                var p1Floor   = new Vector2(p1Ceiling.x - isometricGrid.GridStep, p1Ceiling.y - isometricGrid.GridStep);
                p1Ceiling.x -= p1.x;
                p1Ceiling.y -= p1.y;
                p1Floor.x   -= p1.x;
                p1Floor.y   -= p1.y;
                var dx = IsometricSprite.FindMinValues(IsometricSprite.FindMinValues(p0Ceiling.x, p0Floor.x), IsometricSprite.FindMinValues(p1Ceiling.x, p1Floor.x));
                var dy = IsometricSprite.FindMinValues(IsometricSprite.FindMinValues(p0Ceiling.y, p0Floor.y), IsometricSprite.FindMinValues(p1Ceiling.y, p1Floor.y));
                _point0.x   += dx;
                _point0.y   += dy;
                _point1.x   += dx;
                _point1.y   += dy;
                _position.x += dx;
                _position.y += dy;
            }
        }
Exemplo n.º 2
0
 private void VisitNode(IsometricSprite sprite)
 {
     sprite._visitedFlag = true;
     if (sprite.SpritesBehind.Count > 0)
     {
         foreach (var value in sprite.SpritesBehind)
         {
             if (!value._visitedFlag)
             {
                 VisitNode(value);
             }
         }
     }
     sprite.SetSortOrder(_sortingOrder++);
 }
Exemplo n.º 3
0
        private void Topological(IsometricSprite sprite)
        {
            foreach (var s in Sprites)
            {
                if (s != sprite)
                {
                    if (s._point1.x > sprite._point0.x && s._point1.y > sprite._point0.y && s._point0.z < sprite._point1.z)
                    {
                        if (!sprite.SpritesBehind.Contains(s))
                        {
                            sprite.SpritesBehind.Add(s);
                        }
                    }
                    else
                    {
                        if (sprite.SpritesBehind.Contains(s))
                        {
                            sprite.SpritesBehind.Remove(s);
                        }
                    }

                    if (sprite._point1.x > s._point0.x && sprite._point1.y > s._point0.y && sprite._point0.z < s._point1.z)
                    {
                        if (!s.SpritesBehind.Contains(sprite))
                        {
                            s.SpritesBehind.Add(sprite);
                        }
                    }
                    else
                    {
                        if (s.SpritesBehind.Contains(sprite))
                        {
                            s.SpritesBehind.Remove(sprite);
                        }
                    }
                }
                s._visitedFlag = false;
            }
            _sortingOrder = 0;
            foreach (var s in Sprites)
            {
                if (!s._visitedFlag)
                {
                    VisitNode(s);
                }
            }
        }
Exemplo n.º 4
0
 private void VisitNode(IsometricSprite sprite)
 {
     sprite._visitedFlag = true;
     if (sprite.SpritesBehind.Count > 0)
     {
         foreach (var value in sprite.SpritesBehind)
             if (!value._visitedFlag)
                 VisitNode(value);
     }
     sprite.SetSortOrder(_sortingOrder++);
 }
Exemplo n.º 5
0
        private void Topological(IsometricSprite sprite)
        {
            foreach (var s in Sprites)
            {
                if (s != sprite)
                {
                    if (s._point1.x > sprite._point0.x && s._point1.y > sprite._point0.y && s._point0.z < sprite._point1.z)
                    {
                        if (!sprite.SpritesBehind.Contains(s))
                            sprite.SpritesBehind.Add(s);
                    }
                    else
                    {
                        if (sprite.SpritesBehind.Contains(s))
                            sprite.SpritesBehind.Remove(s);
                    }

                    if (sprite._point1.x > s._point0.x && sprite._point1.y > s._point0.y && sprite._point0.z < s._point1.z)
                    {
                        if (!s.SpritesBehind.Contains(sprite))
                            s.SpritesBehind.Add(sprite);
                    }
                    else
                    {
                        if (s.SpritesBehind.Contains(sprite))
                            s.SpritesBehind.Remove(sprite);
                    }
                }
                s._visitedFlag = false;
            }
            _sortingOrder = 0;
            foreach (var s in Sprites)
                if (!s._visitedFlag)
                    VisitNode(s);
        }