- Home /
Converting from EditorWindow to runnable window
Hi, i had built an EditorWindow but then i noticed that it will not be whit the actual game after build, so i started making the same window but using GUI elements, for it to be inside the game.
So far ive almost converted most of stuff but there are still some elements that i havent been able to convert:
EditorGUILayout.Popup
EditorGUILayout.IntField
EditorGUILayout.HelpBox
What is their GUIlayout equivalent, or if it doesn't exist, how can i replicate them?
Answer by numberkruncher · Aug 07, 2013 at 12:07 AM
As you suspected these are not available within the runtime API.
`EditorGUILayout.Popup`
You could use a button and then simulate the popup area using either `GUI.BeginScrollView` or `GUILayout.BeginArea`.
`EditorGUILayout.IntField`
You could simulate this with something like the following (not tested, but you should see the basic idea):
using UnityEngine;
using System;
using System.Text.RegularExpressions;
public static class YourGUI {
public static int IntField(int value) {
// Format integer into string for text input.
string textInput = GUILayout.TextField(value.ToString());
// Extract valid characters from input.
Match m = Regex.Match(textInput, "[+-]?[0-9]+");
textInput = m.Success ? m.Value : "0";
// Convert from string to integer.
return Convert.ToInt32(textInput);
}
}
// Usage:
yourInt = YourGUI.IntField(yourInt);
`EditorGUILayout.HelpBox`
This is essentially a glorified label. You could achieve this with a custom style (perhaps based upon GUI.skin.box) with three custom icon textures. Here is a pseudo-example (again not tested):
public enum YourMessageType {
None,
Info,
Warning,
Error
}
private static GUIContent _tempContent = new GUIContent();
public static void HelpBox(string message, YourMessageType type = YourMessageType.Info) {
_tempContent.text = message;
switch (type) {
default:
case YourMessageType.None:
_tempContent.image = null;
break;
case YourMessageType.Info:
_tempContent.image = yourInfoIcon;
break;
case YourMessageType.Warning:
_tempContent.image = yourWarningIcon;
break;
case YourMessageType.Error:
_tempContent.image = yourErrorIcon;
break;
}
GUILayout.Label(_tempContent, yourHelpBoxStyle);
}
I hope that this will be of help to you :)
Thank you alot for your answer, helped alot.
Still, Unity.GUIlayout.Sucks.RageQuitForToday(). (I'm sure i'm doing something wrong, but damn i'm full of this for today)
Finally everything is working fine, except my pseudo-popup box, basically I just make a new small window on the place of the mouse with a button for each option, i just have 3 issues i cant figure out on my own. 1)this new window should return a value. 2)clicking anywhere outside this $$anonymous$$i window should make it close. 3)resizing the box rect so it can adjust to the text size of the options
Have any ideas?
Not perfect but: http://webx.ubi.pt/~a23002/SpellCustomizer/build.html