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(); }
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(); }
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; } }
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); }
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(); _outfitImage.texture = _renderTexture; _mountImage.texture = _renderTexture; } using (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 (!_outfitImage.enabled) { _outfitImage.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 (!_mountImage.enabled) { _mountImage.enabled = true; } } Graphics.ExecuteCommandBuffer(commandBuffer); } }
private void OnGUI() { Event e = Event.current; if (!_mustRedraw || e.type != EventType.Repaint) { return; } if (_renderTexture == null) { int width = Core.Colors.HSI_H_STEPS * _colorTexture.width + (Core.Colors.HSI_H_STEPS - 1) * margin.x; int height = Core.Colors.HSI_SI_VALUES * _colorTexture.height + (Core.Colors.HSI_SI_VALUES - 1) * margin.y; _renderTexture = new RenderTexture(width, height, 0, RenderTextureFormat.ARGB32); _renderTexture.filterMode = FilterMode.Point; _image.texture = _renderTexture; } int totalColors = Core.Colors.HSI_H_STEPS * Core.Colors.HSI_SI_VALUES; var texturePositions = new Vector2[totalColors]; var colorPositions = new Vector2[totalColors]; var colors = new Vector4[totalColors]; var uvs = new Vector4[totalColors]; int index = 0; for (int j = 0; j < Core.Colors.HSI_SI_VALUES; j++) { for (int i = 0; i < Core.Colors.HSI_H_STEPS; i++) { int colorIndex = j * Core.Colors.HSI_H_STEPS + i; if (colorIndex == _activeColor || colorIndex == _highlightedColor) { totalColors--; continue; } var position = new Vector2 { x = i * (margin.x + _colorTexture.width), y = j * (margin.y + _colorTexture.height) }; texturePositions[index] = position; colorPositions[index] = position + padding; colors[index] = Core.Colors.ColorFromHSI(colorIndex); uvs[index] = new Vector4(1, 1, 0, 0); index++; } } var zoom = new Vector2 { x = (float)Screen.width / _renderTexture.width, y = (float)Screen.height / _renderTexture.height }; using (CommandBuffer commandBuffer = new CommandBuffer()) { commandBuffer.SetRenderTarget(_renderTexture); commandBuffer.ClearRenderTarget(false, true, GraphicsUtility.TransparentColor); commandBuffer.SetViewMatrix( Matrix4x4.TRS(Vector3.zero, Quaternion.identity, zoom) * OpenTibiaUnity.GameManager.MainCamera.worldToCameraMatrix); DrawColorItems(commandBuffer, totalColors, texturePositions, colorPositions, uvs, colors, padding); if (_activeColor != -1) { DrawColorItem(commandBuffer, _activeColor, margin, padding); } if (_highlightedColor != -1) { DrawColorItem(commandBuffer, _highlightedColor, margin, padding); } Graphics.ExecuteCommandBuffer(commandBuffer); } _mustRedraw = false; }