Esempio n. 1
0
        private void OnGUI()
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            InternalStartMouseAction(Input.mousePosition, MouseButton.None, false, true);

            var commandBuffer = new CommandBuffer();

            commandBuffer.SetRenderTarget(_renderTexture);
            commandBuffer.ClearRenderTarget(false, true, Core.Utils.GraphicsUtility.TransparentColor);

            var zoom = new Vector2(Screen.width / (float)_renderTexture.width, Screen.height / (float)_renderTexture.height);

            commandBuffer.SetViewMatrix(Matrix4x4.TRS(Vector3.zero, Quaternion.identity, zoom) *
                                        OpenTibiaUnity.GameManager.MainCamera.worldToCameraMatrix);

            for (int i = 0; i < (int)ClothSlots.Hip; i++)
            {
                var @object = OpenTibiaUnity.ContainerStorage.BodyContainerView.Objects[i];
                if (@object)
                {
                    @object.SetClamping(true);
                    @object.Animate(OpenTibiaUnity.TicksMillis);
                    @object.Draw(commandBuffer, new Vector2Int(Constants.FieldSize * i, 0), 0, 0, 0);
                }
            }

            Graphics.ExecuteCommandBuffer(commandBuffer);
            commandBuffer.Dispose();
        }
Esempio n. 2
0
        protected void OnGUI()
        {
            if (Event.current.type != EventType.Repaint || _minimized)
            {
                return;
            }

            InternalStartMouseAction(Input.mousePosition, MouseButton.None, false, true);

            if (!_slotsRenderTexture)
            {
                return;
            }

            var commandBuffer = new CommandBuffer();

            commandBuffer.SetRenderTarget(_slotsRenderTexture);
            commandBuffer.ClearRenderTarget(false, true, Core.Utils.GraphicsUtility.TransparentColor);

            var zoom = new Vector2(Screen.width / (float)_slotsRenderTexture.width, Screen.height / (float)_slotsRenderTexture.height);

            commandBuffer.SetViewMatrix(Matrix4x4.TRS(Vector3.zero, Quaternion.identity, zoom) *
                                        OpenTibiaUnity.GameManager.MainCamera.worldToCameraMatrix);

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < _rows; j++)
                {
                    int index = j * 4 + i;
                    if (index < _containerView.NumberOfTotalObjects)
                    {
                        var @object = _containerView.GetObject(index + _containerView.IndexOfFirstObject);
                        if (@object)
                        {
                            if ([email protected])
                            {
                                @object.ClampeToFieldSize = true;
                            }
                            @object.Animate(OpenTibiaUnity.TicksMillis);
                            @object.Draw(commandBuffer, new Vector2Int(Constants.FieldSize * i, Constants.FieldSize * j), 0, 0, 0);
                        }
                    }
                }
            }

            int iconColumn = _numberOfSlots % 4;
            int iconRow    = _numberOfSlots / 4;

            if (!_containerView.Icon.ClampeToFieldSize)
            {
                _containerView.Icon.ClampeToFieldSize = true;
            }
            _containerView.Icon.Draw(commandBuffer, new Vector2Int(Constants.FieldSize * iconColumn, Constants.FieldSize * iconRow), 0, 0, 0);

            Graphics.ExecuteCommandBuffer(commandBuffer);
            commandBuffer.Dispose();
        }
Esempio n. 3
0
        protected void OnGUI()
        {
            var e = Event.current;

            if (e.type != EventType.Repaint || !Visible)
            {
                return;
            }

            if (!_activeActionPanel)
            {
                if (_objectImage.enabled)
                {
                    _objectImage.enabled = false;
                }
                return;
            }

            var objectAction = GetHotkeyActionForPanel <HotkeyObjectAction>(_activeActionPanel);

            if (objectAction == null || !objectAction.AppearanceType)
            {
                if (_objectImage.enabled)
                {
                    _objectImage.enabled = false;
                }
                return;
            }

            if (s_renderTexture == null)
            {
                s_renderTexture            = new RenderTexture(Constants.FieldSize, Constants.FieldSize, 0, RenderTextureFormat.ARGB32);
                s_renderTexture.filterMode = FilterMode.Bilinear;
                s_renderTexture.Create();
                _objectImage.texture = s_renderTexture;
            }

            var commandBuffer = new CommandBuffer();

            commandBuffer.SetRenderTarget(s_renderTexture);
            commandBuffer.ClearRenderTarget(false, true, Core.Utils.GraphicsUtility.TransparentColor);

            var zoom = new Vector2(Screen.width / (float)s_renderTexture.width, Screen.height / (float)s_renderTexture.height);

            commandBuffer.SetViewMatrix(Matrix4x4.TRS(Vector3.zero, Quaternion.identity, zoom) *
                                        OpenTibiaUnity.GameManager.MainCamera.worldToCameraMatrix);

            _objectInstance.Draw(commandBuffer, new Vector2Int(0, 0), 0, 0, 0);
            Graphics.ExecuteCommandBuffer(commandBuffer);
            commandBuffer.Dispose();

            if (!_objectImage.enabled)
            {
                _objectImage.enabled = true;
            }
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        void EnsureHookedLightSource(Light light)
        {
            if (!light)
            {
                return;
            }

            if (light.commandBufferCount == 2)
            {
                return;
            }

            //Debug.Log("Hooking scattering command buffers on light source: " + light.name);

            // NOTE: This doesn't really play nicely with other users of light events.
            //       Currently not an issue since this code was written pre-5.1 (and light events
            //       are a new feature in 5.1), but might need a proper solution in the future.
            light.RemoveAllCommandBuffers();

            if (m_occlusionCmdAfterShadows != null)
            {
                m_occlusionCmdAfterShadows.Dispose();
            }
            if (m_occlusionCmdBeforeScreen != null)
            {
                m_occlusionCmdBeforeScreen.Dispose();
            }

            m_occlusionCmdAfterShadows      = new UnityEngine.Rendering.CommandBuffer();
            m_occlusionCmdAfterShadows.name = "Scatter Occlusion Pass 1";
            m_occlusionCmdAfterShadows.SetGlobalTexture("u_SMCascadedShadowMap", new UnityEngine.Rendering.RenderTargetIdentifier(UnityEngine.Rendering.BuiltinRenderTextureType.CurrentActive));
            m_occlusionCmdBeforeScreen      = new UnityEngine.Rendering.CommandBuffer();
            m_occlusionCmdBeforeScreen.name = "Scatter Occlusion Pass 2";

            light.AddCommandBuffer(UnityEngine.Rendering.LightEvent.AfterShadowMap, m_occlusionCmdAfterShadows);
            light.AddCommandBuffer(UnityEngine.Rendering.LightEvent.BeforeScreenspaceMask, m_occlusionCmdBeforeScreen);
        }
Esempio n. 6
0
        protected void OnGUI()
        {
            if (Event.current.type != EventType.Repaint || !Visible)
            {
                return;
            }

            if (!_currentOutfit && !_currentMount)
            {
                return;
            }

            if (_renderTexture == null)
            {
                _renderTexture            = new RenderTexture(Constants.FieldSize * 2 * 2, Constants.FieldSize * 2, 0, RenderTextureFormat.ARGB32);
                _renderTexture.filterMode = FilterMode.Bilinear;
                _renderTexture.Create();

                _rawImageOutfit.texture = _renderTexture;
                _rawImageMount.texture  = _renderTexture;
            }

            var commandBuffer = new CommandBuffer();

            commandBuffer.SetRenderTarget(_renderTexture);
            commandBuffer.ClearRenderTarget(false, true, Core.Utils.GraphicsUtility.TransparentColor);

            var zoom = new Vector2(Screen.width / (float)_renderTexture.width, Screen.height / (float)_renderTexture.height);

            commandBuffer.SetViewMatrix(Matrix4x4.TRS(Vector3.zero, Quaternion.identity, zoom) *
                                        OpenTibiaUnity.GameManager.MainCamera.worldToCameraMatrix);

            if (!!_currentOutfit)
            {
                var screenPosition = new Vector2Int(Constants.FieldSize, Constants.FieldSize);
                if (!OpenTibiaUnity.GameManager.GetFeature(GameFeature.GamePlayerMounts))
                {
                    screenPosition.x = (int)(screenPosition.x * _spacingFactor);
                    screenPosition.y = (int)(screenPosition.x * _spacingFactor);
                }

                if (_currentOutfit is OutfitInstance)
                {
                    _currentOutfit.Draw(commandBuffer, screenPosition, (int)_currentDirection, 0, 0);
                }
                else
                {
                    _currentOutfit.Draw(commandBuffer, screenPosition, 0, 0, 0);
                }

                if (!_rawImageOutfit.enabled)
                {
                    _rawImageOutfit.enabled = true;
                }
            }

            if (!!_currentMount)
            {
                float pos            = Constants.FieldSize * _spacingFactor;
                var   screenPosition = new Vector2Int((int)pos + 2 * Constants.FieldSize, (int)pos);

                if (_currentMount is OutfitInstance)
                {
                    _currentMount.Draw(commandBuffer, screenPosition, (int)_currentDirection, 0, 0);
                }
                else
                {
                    _currentMount.Draw(commandBuffer, screenPosition, 0, 0, 0);
                }

                if (!_rawImageMount.enabled)
                {
                    _rawImageMount.enabled = true;
                }
            }

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