I created a Main Menu using the new UI in the editor and want to see how this looks in a C# script. In Visual Studio when you design a window you can see all the code by opening FormX.designer.cs. Is there a way to view the code that is created by the Editor?
When editing UI in Unity, it doesn’t create code like in Visual Studio Forms. Instead, it creates data that is serialized and serialized which has all the information about what type of object, it’s position, and the values of its properties.
However, from what I understand of the comments on the question, what you want to do is a procedural UI and all you need to do is write your own code to make it. Just create a new GameObject and use the method AddComponent to add text, sprite, or whatever you want to it.
Here is an example:
var textObject = new GameObject("Text");
textObject.layer = UILayer;
textObject.transform.SetParent(openGroup.transform, false);
var text = textObject.AddComponent<Text>();
text.font = Settings.Font;
text.fontSize = Settings.FontSize;
text.color = Settings.FontColor;
text.text = Settings.OpenText;
text.alignment = TextAnchor.MiddleRight;
text.text = "Hello World";
However, for having done it and regretted it later, I cannot recommend this method at all. It is long, tedious, prone to error, and hard to modify.
Instead, if you want to make dynamic that you can modify and do fun stuff with, I recommend you make some template UI in the Unity Editor and save it to a Prefab. Later, when you want to instantiate it and change it’s content, it is a lot easier to just do a prefab instantiation and just change the one value that is going to be different, like the text for example, rather than do the whole configuration programatically.
What kind of menu did you create?