From 9f307d7632ad92162237f29c4418e1f6b3a90dfb Mon Sep 17 00:00:00 2001 From: excitedneon Date: Thu, 11 May 2017 20:30:15 +0300 Subject: [PATCH] Fix text prop caching and an exception in Server.cs --- Assets/Scripts/Networking/Serverside/Server.cs | 2 +- Assets/Scripts/Util/TextTextureRenderer.cs | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/Networking/Serverside/Server.cs b/Assets/Scripts/Networking/Serverside/Server.cs index 7a1bacc..091c068 100644 --- a/Assets/Scripts/Networking/Serverside/Server.cs +++ b/Assets/Scripts/Networking/Serverside/Server.cs @@ -139,7 +139,7 @@ namespace Cyber.Networking.Serverside { SendToAll(PktType.TextMessage, new TextMessagePkt("Server: " + args[0])); }); - gameObject.AddComponent(); + Syncer = gameObject.AddComponent(); return true; } diff --git a/Assets/Scripts/Util/TextTextureRenderer.cs b/Assets/Scripts/Util/TextTextureRenderer.cs index e8054b4..ed27f8e 100644 --- a/Assets/Scripts/Util/TextTextureRenderer.cs +++ b/Assets/Scripts/Util/TextTextureRenderer.cs @@ -63,10 +63,20 @@ namespace Cyber.Util { /// Whether the texture should be rendered /// again even if it's cached. public static Texture2D GetText(TextTextureProperties text, bool forceRender = false) { - if (forceRender || !Cache.ContainsKey(text.Text)) { - Cache[text.Text] = Singleton.RenderText(text); + string Hash = CreateHash(text); + if (forceRender || !Cache.ContainsKey(Hash)) { + Cache[Hash] = Singleton.RenderText(text); + Term.Println("Created a new texture for:"); + Term.Println(Hash); + Term.Println("===="); } - return Cache[text.Text]; + return Cache[Hash]; + } + + private static string CreateHash(TextTextureProperties text) { + return text.Text + "," + text.Width + "," + text.Height + "," + + text.FontSize + "," + text.Background.r + "," + + text.Background.g + "," + text.Background.b; } } } \ No newline at end of file