Hi I need a level editor inside my game and I decided it would be cleaner to use IMGUI instead of the new gui system(Don’t like it so much).
How would I keep the GUI elements size constant unlike how I have it now.
Hi I need a level editor inside my game and I decided it would be cleaner to use IMGUI instead of the new gui system(Don’t like it so much).
How would I keep the GUI elements size constant unlike how I have it now.
I don’t understand what you mean. The size is whatever you set them to. (in pixels)
You are right about that but if you look at the game running in Unity vs in a desktop build in that screenshot the desktop builds UI is much smaller. Its a DPI problem I think.
Post code - otherwise it’s impossible to tell what you’re doing. It’d also be helpful to see what it looks like in the editor versus what it looks like in a build.
I uploaded two files, one in editor and the other running in a desktop build. You can see the desktop build is much smaller. Is there a way to keep a constant size?
Main Editor Code
public class EditorGUI : MonoBehaviour
{
public EditorGUIToolBar editorGUIToolBar;
public EditorGUIPane editorGUIPane;
public Texture2D pixelTexture;
public GUIStyle buttonGUIStyle;
public bool isPlaying;
public Texture2D CreateTexture(int width, int height, Color color)
{
Texture2D texture = new Texture2D(width, height);
for (int x = 0; x < width; ++x)
for (int y = 0; y < width; ++y)
texture.SetPixel(x, y, color);
texture.Apply();
return texture;
}
public void DrawRect(Rect rect, Color color)
{
GUI.color = color;
GUI.DrawTexture(rect, pixelTexture);
GUI.color = Color.white;
}
public void Start()
{
editorGUIToolBar = new EditorGUIToolBar(this);
editorGUIPane = new EditorGUIPane(this);
pixelTexture = CreateTexture(1, 1, Color.white);
buttonGUIStyle = new GUIStyle();
buttonGUIStyle.font = Resources.Load<Font>("Graphics/Fonts/segmdl2");
buttonGUIStyle.normal.textColor = new Color(0.5f, 0.5f, 0.5f);
buttonGUIStyle.alignment = TextAnchor.MiddleCenter;
buttonGUIStyle.hover.textColor = buttonGUIStyle.normal.textColor;
buttonGUIStyle.hover.background = CreateTexture(1,1,new Color(0.16f, 0.16f, 0.16f));
buttonGUIStyle.active.textColor = buttonGUIStyle.normal.textColor;
buttonGUIStyle.active.background = CreateTexture(1, 1, new Color(0.08f, 0.08f, 0.08f));
}
public void Update()
{
editorGUIPane.Update();
editorGUIToolBar.Update();
}
public void OnGUI()
{
editorGUIPane.OnGUI();
editorGUIToolBar.OnGUI();
}
}
ToolBar Code
public class EditorGUIToolBar
{
EditorGUI editorGUI;
public int height = 32;
public EditorGUIToolBar(EditorGUI editorGUI)
{
this.editorGUI = editorGUI;
}
public void Update()
{
}
public void OnGUI()
{
//BackgroundAndBorder
editorGUI.DrawRect(new Rect(0, 0, Screen.width, height), new Color(0.12f, 0.12f, 0.12f));
editorGUI.DrawRect(new Rect(0, height, Screen.width, 1), Color.black);
GUI.Button(new Rect(0, 0, height, height), "", editorGUI.buttonGUIStyle);
GUI.Button(new Rect(height, 0, height, height), "", editorGUI.buttonGUIStyle);
//Seperator
editorGUI.DrawRect(new Rect(74, 8, 1,height - 16), editorGUI.buttonGUIStyle.normal.textColor);
//Play Button
GUI.contentColor = Color.green;
if (GUI.Button(new Rect(85, 0, height, height),"", editorGUI.buttonGUIStyle))
editorGUI.isPlaying = !editorGUI.isPlaying;
GUI.contentColor = Color.white;
if (editorGUI.isPlaying)
editorGUI.DrawRect((new Rect(85,height - 1, height, 1)),editorGUI.buttonGUIStyle.active.textColor);
}
}