I am having this issue too at the moment. It shows the first time the UI is created, then second time I call it, the button text isn't there anymore. Was this bypassed by giving the UI elements random names?
Community entity UI
Discussion in 'Rust Development' started by ShadowEvil, Jun 5, 2015.
-
p.s Seems they're not even interested in this problem. Almost a month.
Bug report: https://github.com/Facepunch/rust-community/issues/3 -
https://github.com/Facepunch/rust-community/pull/4
[edit] Also a month ago -
Do anyone have an example on how to do the random name in the json constant? I looked at what AlexALX_[rus-ua] wrote, but I think I am doing something wrong. I don't know how to change the string inside a json. This is what I have:
Code:using Oxide.Core.Plugins; using System; using System.Collections.Generic; using System.Text; using Oxide.Core; using System.Reflection; using System.Data; using UnityEngine; using Rust;namespace Oxide.Plugins { [Info("GUI", "Carbonade", "0.0.1")] class GUI : RustPlugin { public string RndName = ((int)Math.Round(UnityEngine.Random.Range(0f, 10000000f))).ToString(); #region JSON const string json = @"[ { ""name"": ""UIBackground{RndName}"", ""parent"": ""Overlay"", ""components"": [ { ""type"":""UnityEngine.UI.Image"", ""color"":""0.1 0.1 0.1 0.7"", }, { ""type"":""RectTransform"", ""anchormin"": ""0.05 0.05"", ""anchormax"": ""0.95 0.95"" }, { ""type"":""NeedsCursor"" } ] }, { ""name"": ""UITopBar{RndName}"", ""parent"": ""UIBackground{RndName}"", ""components"": [ { ""type"":""UnityEngine.UI.Image"", ""color"":""0.1 0.1 0.5 0.0"", }, { ""type"":""RectTransform"", ""anchormin"": ""0.0 0.9"", ""anchormax"": ""1.00 1.00"" }, ] }, { ""name"": ""UIBottomBar{RndName}"", ""parent"": ""UIBackground{RndName}"", ""components"": [ { ""type"":""UnityEngine.UI.Image"", ""color"":""0.1 0.1 0.5 0.0"", }, { ""type"":""RectTransform"", ""anchormin"": ""0.0 0.0"", ""anchormax"": ""1.0 0.1"" }, ] }, { ""name"": ""TextExitHelp{RndName}"", ""parent"": ""UITopBar{RndName}"", ""components"": [ { ""type"":""UnityEngine.UI.Text"", ""text"":""Press to exit window ->"", ""fontSize"":12, ""align"": ""UpperRight"", }, { ""type"":""RectTransform"", ""anchormin"": ""0.75 0.95"", ""anchormax"": ""0.95 1.00"" } ] }, { ""name"": ""UITitle{RndName}"", ""parent"": ""UITopBar{RndName}"", ""components"": [ { ""type"":""UnityEngine.UI.Text"", ""text"":""Title: Carbonades Test GUI"", ""fontSize"":16, ""align"": ""UpperLeft"", }, { ""type"":""RectTransform"", ""anchormin"": ""0.05 0.95"", ""anchormax"": ""0.15 1.00"" } ] }, { ""name"": ""ExitButton1{RndName}"", ""parent"": ""UITopBar{RndName}"", ""components"": [ { ""type"":""UnityEngine.UI.Button"", ""close"":""UIBackground{RndName}"", ""command"":""uir"", ""color"": ""0.5 0.5 0.8 1.0"", ""imagetype"": ""Tiled"" }, { ""type"":""RectTransform"", ""anchormin"": ""0.95 0.95"", ""anchormax"": ""1.0 1.0"" } ] }, { ""name"": ""Text2{RndName}"", ""parent"": ""ExitButton1{RndName}"", ""components"": [ { ""type"":""UnityEngine.UI.Text"", ""text"":""X"", ""fontSize"":18, ""align"": ""MiddleCenter"", }, { ""type"":""RectTransform"", ""anchormin"": ""0.05 0.05"", ""anchormax"": ""0.95 0.95"" } ] } ] "; #endregion [ChatCommand("ui")] private void UIChatLoadCMD(BasePlayer player, string command, string[] args) { if (!player.IsAdmin()) return; CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = player.net.connection }, null, "AddUI", json); PrintToChat(player, "Showing GUI. Random number: " + RndName); } [ConsoleCommand("uir")] private void UIChatUnloadCMD(ConsoleSystem.Arg arg) { CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = arg.Player().net.connection }, null, "DestroyUI", "UIBackground{RndName}"); RndName = ((int)Math.Round(UnityEngine.Random.Range(0f, 10000000f))).ToString(); PrintToChat(arg.Player(), "Removing the GUI. Random number: " + RndName); } } }
-
Try something like this
Code:""name"": ""Text2" + UnityEngine.Random.Range(1, 1000) + @""", ""parent"": ""ExitButton1" + UnityEngine.Random.Range(1, 1000) + @""",
Code:var RndName = UnityEngine.Random.Range(1, 1000) ;""name"": ""Text2" + RndName + @""", ""parent"": ""ExitButton1" + RndName + @""",
-
i love it already so easy to work with, i wish i knew about this before 5 hours ago lol
well i had some fun
Last edited by a moderator: Jul 13, 2015 -
-
its pretty easy and you don't need to name everything random names just name the top part then parent the rest under it
and if anyone needs a hint on setting the data i basically just did .Replace("{level}", ""+mylevel) on the json string just as its put through the ClientRPCEx, ive released some working gui's (ones waiting to verified a announcement system) -
Can someone take a look at this JSON and figure out why the text doesn't display? Been looking at it for a while now and can't find out what's wrong:
Code:[ { ""name"": ""Background"", ""parent"": ""Overlay"", ""components"": [ { ""type"": ""UnityEngine.UI.RawImage"", ""imagetype"": ""Tiled"", ""sprite"": ""Assets/Content/UI/UI.Background.Transparent.Radial.psd"", ""color"": ""0.1 0.1 0.1 0"" }, { ""type"": ""RectTransform"", ""anchormin"": ""0 0"", ""anchormax"": ""1 1"" } ] }, { ""name"": ""testButton"", ""parent"": ""Background"", ""components"": [ { ""type"": ""UnityEngine.UI.Button"", ""command"": ""status"", ""sprite"": ""Assets/Content/UI/UI.Background.Transparent.Linear.psd"", ""color"": ""0.4 0.4 0.4 1.0"", ""imagetype"": ""Tiled"" }, { ""type"": ""RectTransform"", ""anchormin"": ""0.671 0.795"", ""anchormax"": ""0.966 0.859"" } ] }, { ""name"": ""testText"", ""parent"": ""testButton"", ""components"": [ { ""type"": ""UnityEngine.UI.Text"", ""text"": ""HELLO"", ""fontSize"": ""20"", ""align"": ""MiddleCenter"", ""color"": ""1 1 1 1 "" } ] } ]
Thanks in advance! -
Does the background + button show up but not the text?
I could be that the text size is too big then if it's only the text. Does it show up the first time you display it or not at all? -
-
-
Does this all actually work with LUA? If yes how?
-
Wulf Community Admin
-
-
Code:[ConsoleCommand("buttonClick:")] private void SaveCommand(ConsoleSystem.Arg arg) { }
Because I really hate being redundant and making a different ConsoleCommand handler for every button :\. I'd much rather make one handler with a switch to handle all the buttons.
Thanks in advance,
DroneFW
[DOUBLEPOST=1437175617,1437043063][/DOUBLEPOST]Bump ^^ -
It may not be of great help, but here is an example of how to use it in javascript
Code:var GUI = { Title : "GUI - JavaScript", Description : "Test GUI JavaScript", Author : "LEO318x", Version : V(0, 0, 1), Init : function () { this.GUI; Network = importNamespace("Network"); global = importNamespace(""); command.AddChatCommand("gui", this.Plugin, "GUI"); }, GUI : function(player){ var JS = "[{\"parent\":\"Overlay\",\"components\":[{\"type\":\"UnityEngine.UI.Text\",\"text\":\"Is it from plugin?\",\"fontSize\":32,\"align\":\"MiddleCenter\"},{\"type\":\"RectTransform\",\"anchormin\":\"0 0.5\",\"anchormax\":\"1 0.9\"}]},{\"name\":\"Button88\",\"parent\":\"Overlay\",\"components\":[{\"type\":\"UnityEngine.UI.Button\",\"close\":\"TestPanel7766\",\"command\":\"status\",\"color\":\"0.9 0.8 0.3 0.8\",\"imagetype\":\"Tiled\"},{\"type\":\"RectTransform\",\"anchormin\":\"0.3 0.15\",\"anchormax\":\"0.7 0.2\"}]},{\"parent\":\"Button88\",\"components\":[{\"type\":\"UnityEngine.UI.Text\",\"text\":\"YES!!!!\",\"fontSize\":20,\"align\":\"MiddleCenter\"}]}]"; var Netw = new Network.SendInfo(conection = player.net.connection); global.CommunityEntity.ServerInstance.ClientRPCEx(Netw, null, "AddUI", JS); } };
You can use this webpage to minify the JSON string
Code:http://codebeautify.org/jsonviewer
-
-
So i'm back to previous problem with "buttons and text makes button unclickable", after some tests i'm understand that button should not have parent, or it will glitch, but this makes writing ui much harder, because its more simplier to use RectTransform with aligment on parent, that globally. So is there possible to write "fix" for this or this is unity limitation? Or i'm doing something wrong?
-