I have my UI pretty much completed for my plugin but I am coming across the above error when adding text to a CuiElement. The code I am using for adding the text is:Code:[Oxide] 16:21 [Error] LythixProfessions.cs(110,27): error CS0103: The name `TextAnchor' does not exist in the current context
When I take the Align property out, it compiles without errors and my UI renders accordingly.Code:var stext = new CuiElement { Name = uiStrings[s.Key].Name, Parent = uiFrameName, Components = { new CuiTextComponent { Color = uiStrings[s.Key].Color, Text = uiStrings[s.Key].Text, FontSize = uiStrings[s.Key].FontSize, Align = TextAnchor.MiddleCenter }, new CuiRectTransformComponent { AnchorMin = uiStrings[s.Key].AnchorMin, AnchorMax = uiStrings[s.Key].AnchorMax } } }; uiFrame.Add(stext);
Solved CUI TextAnchor does not exist
Discussion in 'Rust Development' started by IŊŦΣCҴ¤Ŋ, May 12, 2016.
-
Wulf Community Admin
Where is TextAnchor being set? I'm not aware of that existing in the RustCUI.
-
Hi Wulf,
The Align property is set after the CuiElementContainer is created within the CuiPanel (see code below):
Code:private void uiFrame_Create(BasePlayer uiFrameOwner, string uiFrameName, string uiFrameParent, string uiFrameColor, string uiFrameAnchorMin, string uiFrameAnchorMax) { uiFrame_Destroy(uiFrameOwner, uiFrameName); var uiFrame = new CuiElementContainer(); var uiPanel = uiFrame.Add(new CuiPanel { Image = { Color = uiFrameColor }, RectTransform = { AnchorMin = uiFrameAnchorMin, AnchorMax = uiFrameAnchorMax } }, uiFrameParent, uiFrameName); /** check if there is any images to add to this frame */ foreach (var i in uiImages) { if (uiImages[i.Key].Parent == uiFrameName) { var image = new CuiElement { Name = uiImages[i.Key].Name, Parent = uiFrameName, Components = { new CuiRawImageComponent { Url = uiImages[i.Key].Url, Color = uiImages[i.Key].Color, Sprite = "assets/content/textures/generic/fulltransparent.tga" }, new CuiRectTransformComponent { AnchorMin = uiImages[i.Key].AnchorMin, AnchorMax = uiImages[i.Key].AnchorMax } } }; uiFrame.Add(image); } /** check if there is any strings to add to this frame */ foreach (var s in uiStrings) { if (uiStrings[s.Key].Parent == uiFrameName) { var stext = new CuiElement { Name = uiStrings[s.Key].Name, Parent = uiFrameName, Components = { new CuiTextComponent { Color = uiStrings[s.Key].Color, Text = uiStrings[s.Key].Text, FontSize = uiStrings[s.Key].FontSize, Align = TextAnchor.MiddleCenter }, new CuiRectTransformComponent { AnchorMin = uiStrings[s.Key].AnchorMin, AnchorMax = uiStrings[s.Key].AnchorMax } } }; uiFrame.Add(stext); } } } CuiHelper.AddUi(uiFrameOwner, uiFrame); }
-
missing import? "using UnityEngine;"
-
Much appreciated.