From cac960800f3f16118d7145c7f53c6603e1c1bbf1 Mon Sep 17 00:00:00 2001 From: in0finite Date: Wed, 22 Apr 2020 00:28:09 +0200 Subject: [PATCH] working on crosshair --- Assets/Scripts/Behaviours/Loader.cs | 14 ++---- Assets/Scripts/UI/HUD.cs | 77 ++++++++++++++++++++++++++++- 2 files changed, 81 insertions(+), 10 deletions(-) diff --git a/Assets/Scripts/Behaviours/Loader.cs b/Assets/Scripts/Behaviours/Loader.cs index 1315be36..a4c68b22 100644 --- a/Assets/Scripts/Behaviours/Loader.cs +++ b/Assets/Scripts/Behaviours/Loader.cs @@ -69,6 +69,8 @@ namespace SanAndreasUnity.Behaviours private static bool m_showFileBrowser = false; private static FileBrowser m_fileBrowser = null; + public static event System.Action onLoadSpecialTextures = delegate { }; + void Start () @@ -409,18 +411,12 @@ namespace SanAndreasUnity.Behaviours mouseFix.Apply(); Cursor.SetCursor(mouseFix, Vector2.zero, CursorMode.Auto); - // load crosshair texture - Weapon.CrosshairTexture = TextureDictionary.Load("hud").GetDiffuse("siteM16").Texture; - // fist texture Weapon.FistTexture = TextureDictionary.Load("hud").GetDiffuse("fist").Texture; - // arrow textures - var pcbtnsTxd = TextureDictionary.Load("pcbtns"); - UI.HUD.LeftArrowTexture = pcbtnsTxd.GetDiffuse("left").Texture; - UI.HUD.RightArrowTexture = pcbtnsTxd.GetDiffuse("right").Texture; - UI.HUD.UpArrowTexture = pcbtnsTxd.GetDiffuse("up").Texture; - UI.HUD.DownArrowTexture = pcbtnsTxd.GetDiffuse("down").Texture; + + onLoadSpecialTextures(); + } private static void StepLoadGXT() diff --git a/Assets/Scripts/UI/HUD.cs b/Assets/Scripts/UI/HUD.cs index 73f5a908..2011acd1 100644 --- a/Assets/Scripts/UI/HUD.cs +++ b/Assets/Scripts/UI/HUD.cs @@ -3,6 +3,7 @@ using UnityEngine; using SanAndreasUnity.Behaviours; using SanAndreasUnity.Utilities; using UnityEngine.UI; +using SanAndreasUnity.Importing.Conversion; namespace SanAndreasUnity.UI { @@ -38,6 +39,80 @@ namespace SanAndreasUnity.UI { void Awake () { Instance = this; + + Loader.onLoadSpecialTextures += LoadTextures; + } + + void LoadTextures() + { + // load arrow textures + var pcbtnsTxd = TextureDictionary.Load("pcbtns"); + LeftArrowTexture = pcbtnsTxd.GetDiffuse("left").Texture; + RightArrowTexture = pcbtnsTxd.GetDiffuse("right").Texture; + UpArrowTexture = pcbtnsTxd.GetDiffuse("up").Texture; + DownArrowTexture = pcbtnsTxd.GetDiffuse("down").Texture; + + LoadCrosshairTexture(); + + } + + void LoadCrosshairTexture() + { + + Texture2D originalTex = TextureDictionary.Load("hud") + .GetDiffuse("siteM16", new TextureLoadParams { makeNoLongerReadable = false }) + .Texture; + + // construct crosshair texture + + int originalWidth = originalTex.width; + int originalHeight = originalTex.height; + + Texture2D tex = new Texture2D(originalWidth * 2, originalHeight * 2); + + // bottom left + for (int i = 0; i < originalWidth; i++) + { + for (int j = 0; j < originalHeight; j++) + { + tex.SetPixel(i, j, originalTex.GetPixel(i, j)); + } + } + + // bottom right - flip around X axis + for (int i = 0; i < originalWidth; i++) + { + for (int j = 0; j < originalHeight; j++) + { + tex.SetPixel(originalWidth - i + originalWidth, j, originalTex.GetPixel(i, j)); + } + } + + // top left - flip Y axis + for (int i = 0; i < originalWidth; i++) + { + for (int j = 0; j < originalHeight; j++) + { + tex.SetPixel(i, originalHeight - j + originalHeight, originalTex.GetPixel(i, j)); + } + } + + // top right - flip both X and Y axes + for (int i = 0; i < originalWidth; i++) + { + for (int j = 0; j < originalHeight; j++) + { + tex.SetPixel(originalWidth - i + originalWidth, originalHeight - j + originalHeight, originalTex.GetPixel(i, j)); + } + } + + //tex.Apply(false, true); + tex.Apply(); + + Weapon.CrosshairTexture = tex; + this.crosshairImage.enabled = true; + this.crosshairImage.texture = tex; + } void Update() @@ -89,7 +164,7 @@ namespace SanAndreasUnity.UI { // draw crosshair if (ped.IsAiming) { - DrawCrosshair( new Vector2(Screen.width * 0.5f, Screen.height * 0.5f), Vector2.one * this.crosshairSize, this.crosshairScaleMode ); + //DrawCrosshair( new Vector2(Screen.width * 0.5f, Screen.height * 0.5f), Vector2.one * this.crosshairSize, this.crosshairScaleMode ); } // draw hud