Exemplo n.º 1
0
        public RenderError Render(RenderTexture renderTarget)
        {
            if (MiniMapStorage == null || !OpenTibiaUnity.GameManager.IsGameRunning || !WorldMapStorage.Valid)
            {
                return(RenderError.MiniMapNotValid);
            }

            var commandBuffer = new CommandBuffer();

            commandBuffer.SetRenderTarget(renderTarget);
            commandBuffer.ClearRenderTarget(false, true, Color.black);

            var zoom = new Vector2()
            {
                x = Screen.width / (float)Constants.MiniMapSideBarViewWidth,
                y = Screen.height / (float)Constants.MiniMapSideBarViewHeight,
            };

            zoom *= _zoomScale;

            var drawnSectors = new List <MiniMapSector>();

            // 4 is the maximum number of sectors to be drawn (pre-calculated)
            // todo; provide a function to calculate it (if someone plans to use minimap differently)
            Vector3Int curPosition = new Vector3Int(0, 0, PositionZ);

            for (int i = 0; i < 4; i++)
            {
                curPosition.x = _positionRect.x + i % 2 * _positionRect.width;
                curPosition.y = _positionRect.y + (i / 2) * _positionRect.height;

                var sector = MiniMapStorage.AcquireSector(curPosition, false);
                if (sector == null || drawnSectors.IndexOf(sector) != -1)
                {
                    continue;
                }

                drawnSectors.Add(sector);

                var sectorRect  = new RectInt(sector.SectorX, sector.SectorY, Constants.MiniMapSectorSize, Constants.MiniMapSectorSize);
                var translation = sectorRect.position - _positionRect.position;

                Matrix4x4 transformation = Matrix4x4.TRS(translation * zoom, Quaternion.Euler(180, 0, 0), Constants.MiniMapSectorSize * zoom);

                var props = new MaterialPropertyBlock();
                props.SetTexture("_MainTex", sector.SafeDrawTexture);
                props.SetVector("_MainTex_UV", new Vector4(1, 1, 0, 0));
                props.SetFloat("_HighlightOpacity", 0);
                Utils.GraphicsUtility.Draw(commandBuffer, transformation, OpenTibiaUnity.GameManager.AppearanceTypeMaterial, props);
            }

            Graphics.ExecuteCommandBuffer(commandBuffer);
            commandBuffer.Dispose();

            return(RenderError.None);
        }
Exemplo n.º 2
0
        public RenderError Render(Material material)
        {
            if (MiniMapStorage == null || !OpenTibiaUnity.GameManager.IsGameRunning || !WorldMapStorage.Valid)
            {
                return(RenderError.MiniMapNotValid);
            }

            GL.Clear(false, true, Color.black);

            if (PositionX < Constants.MapMinX || PositionX > Constants.MapMaxX ||
                PositionY < Constants.MapMinY || PositionY > Constants.MapMaxY ||
                PositionZ < Constants.MapMinZ || PositionZ > Constants.MapMaxZ)
            {
                return(RenderError.PositionNotValid);
            }

            Vector2 screenZoom = new Vector2()
            {
                x = Screen.width * m_ZoomScale / Constants.MiniMapSideBarViewWidth,
                y = Screen.height * m_ZoomScale / Constants.MiniMapSideBarViewHeight,
            };

            Vector2 zoom = new Vector2()
            {
                x = Constants.MiniMapSideBarViewWidth / m_ZoomScale,
                y = Constants.MiniMapSideBarViewHeight / m_ZoomScale
            };

            m_PositionRect.x      = PositionX - zoom.x / 2;
            m_PositionRect.y      = PositionY - zoom.y / 2;
            m_PositionRect.width  = zoom.x;
            m_PositionRect.height = zoom.y;

            var drawnSectors = new List <MiniMapSector>();

            Vector3Int position = Vector3Int.zero;

            var transformationMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(m_ZoomScale, m_ZoomScale, 1));

            for (int i = 0; i < 4; i++)
            {
                position.Set(
                    (int)(m_PositionRect.x + i % 2 * m_PositionRect.width),
                    (int)(m_PositionRect.y + (int)(i / 2) * m_PositionRect.height),
                    PositionZ);

                var sector = MiniMapStorage.AcquireSector(position, false);
                if (drawnSectors.IndexOf(sector) == -1)
                {
                    drawnSectors.Add(sector);

                    var otherRect        = new Rect(sector.SectorX, sector.SectorY, Constants.MiniMapSectorSize, Constants.MiniMapSectorSize);
                    var intersectingRect = Intersection(m_PositionRect, otherRect);

                    Rect screenRect = new Rect()
                    {
                        x      = (intersectingRect.x - m_PositionRect.x) * screenZoom.x,
                        y      = (intersectingRect.y - m_PositionRect.y) * screenZoom.y,
                        width  = intersectingRect.width * screenZoom.x,
                        height = intersectingRect.height * screenZoom.y
                    };

                    sector.ApplyPixelChanges();
                    Graphics.DrawTexture(screenRect, sector.Texture2D, OpenTibiaUnity.GameManager.DefaultMaterial);
                }
            }

            return(RenderError.None);
        }