예제 #1
0
 // Update is called once per frame
 void Update()
 {
     if (transform.hasChanged)
     {
         _position = IsometricGrid.IsoTo2D(transform.position.x, transform.position.y);
         _point0   = _position + _point;
         SetPoint1();
         SnapToGrid();
         Position = _position;
         SetWorldPosition();
     }
     else if (Size != _size)
     {
         _size = Size;
         SetPoint1();
     }
     else if (Position != _position)
     {
         _position = Position;
         _point0   = _position + _point;
         SetPoint1();
         SetWorldPosition();
     }
     else if (Point != _point)
     {
         _point  = Point;
         _point0 = _position + _point;
         SetPoint1();
     }
 }
예제 #2
0
        private void OnDrawGizmos()
        {
            bool selected      = Selection.Contains(gameObject);
            var  isometricGrid = FindObjectOfType <IsometricGrid>();

            if (isometricGrid != null && !isometricGrid.ShowSpritesLines && !selected)
            {
                return;
            }

            var oldColor = Gizmos.color;

            var p0 = IsometricGrid.TwoDToIso(_point0.x, _point0.y);
            var p1 = IsometricGrid.TwoDToIso(_point1.x, _point0.y);
            var p2 = IsometricGrid.TwoDToIso(_point1.x, _point1.y);
            var p3 = IsometricGrid.TwoDToIso(_point0.x, _point1.y);

            Gizmos.color = selected ? Color.cyan : Color.blue;

            Gizmos.DrawLine(new Vector3(p0.x, p0.y, 0.0f), new Vector3(p1.x, p1.y, 0.0f));
            Gizmos.DrawLine(new Vector3(p1.x, p1.y, 0.0f), new Vector3(p2.x, p2.y, 0.0f));
            Gizmos.DrawLine(new Vector3(p2.x, p2.y, 0.0f), new Vector3(p3.x, p3.y, 0.0f));
            Gizmos.DrawLine(new Vector3(p3.x, p3.y, 0.0f), new Vector3(p0.x, p0.y, 0.0f));

            Gizmos.color = oldColor;
        }
예제 #3
0
        void SetWorldPosition()
        {
            Vector3 position = IsometricGrid.TwoDToIso(_position.x, _position.y);

            position.z           = transform.position.z;
            transform.position   = position;
            transform.hasChanged = false;
        }
예제 #4
0
        // Update is called once per frame
        void Update()
        {
            bool needSort = false;

            if (transform.hasChanged)
            {
                var point = IsometricGrid.IsoTo2D(transform.position.x, transform.position.y - _position.z);
                _position.x = point.x;
                _position.y = point.y;
                _point0     = _position + _point;
                SetPoint1();
                SnapToGrid();
                Position = _position;
                SetWorldPosition();
                needSort = true;
            }
            else if (Size != _size)
            {
                _size = Size;
                SetPoint1();
                needSort = true;
            }
            else if (Position != _position)
            {
                _position = Position;
                _point0   = _position + _point;
                SetPoint1();
                SetWorldPosition();
                needSort = true;
            }
            else if (Point != _point)
            {
                _point  = Point;
                _point0 = _position + _point;
                SetPoint1();
                needSort = true;
            }

            if (needSort)
            {
                Topological(this);
            }
        }