コード例 #1
0
        /// <summary>
        /// Updates map position
        /// </summary>
        private void UpdateMap()
        {
            // Store last position of GameObject
            lastPosition = target.transform.position;

            // Size of map in scene
            Vector2 size = control.sizeInScene;

            // Calculate offset (in tile position)
            Vector3 offset = map.transform.rotation * (lastPosition - map.transform.position - control.center);

            offset.x = offset.x / OnlineMapsUtils.tileSize / size.x * map.width * map.zoomCoof;
            offset.z = offset.z / OnlineMapsUtils.tileSize / size.y * map.height * map.zoomCoof;

            // Calculate current tile position of the center of the map
            tx -= offset.x;
            ty += offset.z;

            // Set position of the map center
            map.SetTilePosition(tx, ty);

            // Update map GameObject position
            map.transform.position = lastPosition - control.center;
        }
コード例 #2
0
        private void FixedUpdate()
        {
            if (isInteract && control.GetTouchCount() == 0)
            {
                isInteract = false;
            }

            // If there is interaction with the map.
            if (isInteract)
            {
                // Calculates speeds.
                double tx, ty;
                map.GetTilePosition(out tx, out ty, 20);

                double cSpeedX = tx - ptx;
                double cSpeedY = ty - pty;
                float  cSpeedZ = map.floatZoom - pz;

                int halfMax = 1 << 19;
                int max     = 1 << 20;
                if (cSpeedX > halfMax)
                {
                    cSpeedX -= max;
                }
                else if (cSpeedX < -halfMax)
                {
                    cSpeedX += max;
                }

                while (speedX.Count >= maxSamples)
                {
                    speedX.RemoveAt(0);
                }
                while (speedY.Count >= maxSamples)
                {
                    speedY.RemoveAt(0);
                }
                while (speedZ.Count >= maxSamples)
                {
                    speedZ.RemoveAt(0);
                }

                speedX.Add(cSpeedX);
                speedY.Add(cSpeedY);
                speedZ.Add(cSpeedZ);

                ptx = tx;
                pty = ty;
                pz  = map.floatZoom;
            }
            // If no interaction with the map.
            else if (rsX * rsX + rsY * rsY > 0.001 || rsZ > 0.001)
            {
                // Continue to move the map with the current speed.
                double tx, ty;
                map.GetTilePosition(out tx, out ty, 20);

                tx += rsX;
                ty += rsY;

                int max = 1 << 20;
                if (tx >= max)
                {
                    tx -= max;
                }
                else if (tx < 0)
                {
                    tx += max;
                }

                map.SetTilePosition(tx, ty, 20);
                //control.ZoomOnPoint(rsZ, lastScreenPoint);
                map.floatZoom += rsZ;

                // Reduces the current speed.
                rsX *= friction;
                rsY *= friction;
                rsZ *= friction;
            }
        }
コード例 #3
0
        private void FixedUpdate()
        {
            if (isSmoothZoomProceed || waitZeroTouches)
            {
                return;
            }

            // If there is interaction with the map.
            if (isInteract)
            {
                // Calculates speeds.
                double tx, ty;
                map.GetTilePosition(out tx, out ty);
                double cSpeedX = tx - ptx;
                double cSpeedY = ty - pty;

                int halfMax = 1 << (map.zoom - 1);
                int max     = 1 << map.zoom;
                if (cSpeedX > halfMax)
                {
                    cSpeedX -= max;
                }
                else if (cSpeedX < -halfMax)
                {
                    cSpeedX += max;
                }

                while (speedX.Count >= maxSamples)
                {
                    speedX.RemoveAt(0);
                }
                while (speedY.Count >= maxSamples)
                {
                    speedY.RemoveAt(0);
                }

                speedX.Add(cSpeedX);
                speedY.Add(cSpeedY);

                ptx = tx;
                pty = ty;
            }
            // If no interaction with the map.
            else if (rsX * rsX + rsY * rsY > 0.001)
            {
                // Continue to move the map with the current speed.
                double tx, ty;
                map.GetTilePosition(out tx, out ty);
                tx += rsX;
                ty += rsY;

                int max = 1 << map.zoom;
                if (tx >= max)
                {
                    tx -= max;
                }
                else if (tx < 0)
                {
                    tx += max;
                }

                map.SetTilePosition(tx, ty);

                // Reduces the current speed.
                rsX *= friction;
                rsY *= friction;
            }
        }