Skip to content

Commit d35b0bd

Browse files
committed
now control inspector can be used inside of an application, form Show() method.
1 parent 84a1a52 commit d35b0bd

File tree

12 files changed

+157
-81
lines changed

12 files changed

+157
-81
lines changed

System/Drawing/Editor.cs

Lines changed: 80 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66

77
namespace System.Drawing
88
{
9-
#if UNITY_EDITOR
109
public class Editor
1110
{
1211
private static float _width { get; set; }
1312
private static float _nameWidth { get; set; }
1413
private static float _contentWidth { get; set; }
1514

15+
public static bool WinFormsCompatible { get; set; }
16+
1617
public static void BeginGroup(float width)
1718
{
1819
_width = width;
@@ -49,7 +50,7 @@ public static EditorValue<bool> BooleanField(string name, bool value)
4950
{
5051
UnityEngine.GUILayout.BeginHorizontal();
5152
UnityEngine.GUILayout.Label(name + ":", UnityEngine.GUILayout.Width(_nameWidth));
52-
var boolBuffer = UnityEngine.GUILayout.Toolbar(value ? 0 : 1, new string[] { "On", "Off" }, UnityEngine.GUILayout.Width(_contentWidth)) == 0 ? true : false;
53+
var boolBuffer = UnityEngine.GUILayout.Toolbar(value ? 0 : 1, new string[] { "On", "Off" }, UnityEngine.GUILayout.Width(_contentWidth - 48)) == 0 ? true : false;
5354
UnityEngine.GUILayout.EndHorizontal();
5455

5556
return new EditorValue<bool>(boolBuffer, boolBuffer != value);
@@ -71,11 +72,30 @@ public static bool Button(string text, int width)
7172
{
7273
return UnityEngine.GUILayout.Button(text, UnityEngine.GUILayout.Width(width));
7374
}
74-
public static EditorValue<Color> ColorField(string name, Color value)
75+
public static EditorValue<Color> ColorField(string name, Color value, Action<Color> setColor = null)
7576
{
7677
UnityEngine.GUILayout.BeginHorizontal();
7778
UnityEngine.GUILayout.Label(name + ":", UnityEngine.GUILayout.Width(_nameWidth));
78-
var colorBuffer = System.Drawing.Color.FromUColor(UnityEditor.EditorGUILayout.ColorField(value.ToUColor(), UnityEngine.GUILayout.Width(_contentWidth)));
79+
Color colorBuffer = value;
80+
if (WinFormsCompatible)
81+
{
82+
if (Button(value.ToString()))
83+
{
84+
ColorPicker colorPicker = new ColorPicker();
85+
ColorPickerForm colorForm = new ColorPickerForm(colorPicker);
86+
colorForm.Color = value;
87+
colorForm.Show();
88+
colorForm.ColorChanged += (s, a) =>
89+
{
90+
if (setColor != null)
91+
setColor.Invoke(colorForm.Color);
92+
};
93+
}
94+
}
95+
#if UNITY_EDITOR
96+
else
97+
colorBuffer = System.Drawing.Color.FromUColor(UnityEditor.EditorGUILayout.ColorField(value.ToUColor(), UnityEngine.GUILayout.Width(_contentWidth)));
98+
#endif
7999
UnityEngine.GUILayout.EndHorizontal();
80100

81101
return new EditorValue<Color>(colorBuffer, colorBuffer != value);
@@ -84,14 +104,30 @@ public static EditorValue<Enum> EnumField(string name, Enum value)
84104
{
85105
UnityEngine.GUILayout.BeginHorizontal();
86106
UnityEngine.GUILayout.Label(name + ":", UnityEngine.GUILayout.Width(_nameWidth));
87-
var enumBuffer = UnityEditor.EditorGUILayout.EnumPopup(value, UnityEngine.GUILayout.Width(_contentWidth));
107+
var enumBuffer = value;
108+
if (WinFormsCompatible)
109+
{
110+
111+
}
112+
#if UNITY_EDITOR
113+
else
114+
enumBuffer = UnityEditor.EditorGUILayout.EnumPopup(value, UnityEngine.GUILayout.Width(_contentWidth));
115+
#endif
88116
UnityEngine.GUILayout.EndHorizontal();
89117

90118
return new EditorValue<Enum>(enumBuffer, enumBuffer != value);
91119
}
92120
public static bool Foldout(string name, bool value)
93121
{
94-
return UnityEditor.EditorGUILayout.Foldout(value, name);
122+
if (WinFormsCompatible)
123+
{
124+
return Toggle(name, value);
125+
}
126+
#if UNITY_EDITOR
127+
else
128+
return UnityEditor.EditorGUILayout.Foldout(value, name);
129+
#endif
130+
return false;
95131
}
96132
public static void Header(string text)
97133
{
@@ -121,10 +157,18 @@ public static EditorValue<int[]> IntField(string name, params int[] value)
121157
UnityEngine.GUILayout.Label(name + ":", UnityEngine.GUILayout.Width(_nameWidth));
122158

123159
bool changed = false;
124-
int[] intBuffer = new int[value.Length];
160+
int[] intBuffer = value;
125161
for (int i = 0; i < value.Length; i++)
126162
{
127-
intBuffer[i] = UnityEditor.EditorGUILayout.IntField(value[i], UnityEngine.GUILayout.Width(_contentWidth / value.Length));
163+
if (WinFormsCompatible)
164+
{
165+
var valueBuffer = UnityEngine.GUILayout.TextField(value[i].ToString(), UnityEngine.GUILayout.Width(_contentWidth / value.Length));
166+
int.TryParse(valueBuffer, out intBuffer[i]);
167+
}
168+
#if UNITY_EDITOR
169+
else
170+
intBuffer[i] = UnityEditor.EditorGUILayout.IntField(value[i], UnityEngine.GUILayout.Width(_contentWidth / value.Length));
171+
#endif
128172
if (intBuffer[i] != value[i])
129173
changed = true;
130174
}
@@ -141,7 +185,15 @@ public static void NewLine(int cnt)
141185
{
142186
UnityEngine.GUILayout.BeginHorizontal();
143187
UnityEngine.GUILayout.Label(name + ":", UnityEngine.GUILayout.Width(_nameWidth));
144-
var objectBuffer = UnityEditor.EditorGUILayout.ObjectField(value, type, UnityEngine.GUILayout.Width(_contentWidth));
188+
UnityEngine.Object objectBuffer = value;
189+
if (WinFormsCompatible)
190+
{
191+
192+
}
193+
#if UNITY_EDITOR
194+
else
195+
objectBuffer = UnityEditor.EditorGUILayout.ObjectField(value, type, UnityEngine.GUILayout.Width(_contentWidth));
196+
#endif
145197
UnityEngine.GUILayout.EndHorizontal();
146198

147199
return new EditorValue<UnityEngine.Object>(objectBuffer, objectBuffer != value);
@@ -150,7 +202,15 @@ public static EditorValue<int> Popup(string name, int index, string[] values)
150202
{
151203
UnityEngine.GUILayout.BeginHorizontal();
152204
UnityEngine.GUILayout.Label(name + ":", UnityEngine.GUILayout.Width(_nameWidth));
153-
var intBuffer = UnityEditor.EditorGUILayout.Popup(index, values, UnityEngine.GUILayout.Width(_contentWidth - 8));
205+
int intBuffer = 0;
206+
if (WinFormsCompatible)
207+
{
208+
209+
}
210+
#if UNITY_EDITOR
211+
else
212+
intBuffer = UnityEditor.EditorGUILayout.Popup(index, values, UnityEngine.GUILayout.Width(_contentWidth - 8));
213+
#endif
154214
UnityEngine.GUILayout.EndHorizontal();
155215

156216
return new EditorValue<int>(intBuffer, intBuffer != index);
@@ -159,7 +219,16 @@ public static EditorValue<float> Slider(string name, float value, float min, flo
159219
{
160220
UnityEngine.GUILayout.BeginHorizontal();
161221
UnityEngine.GUILayout.Label(name + ":", UnityEngine.GUILayout.Width(_nameWidth));
162-
var floatBuffer = UnityEditor.EditorGUILayout.Slider(value, min, max, UnityEngine.GUILayout.Width(_contentWidth - 8));
222+
float floatBuffer = value;
223+
if (WinFormsCompatible)
224+
{
225+
floatBuffer = UnityEngine.GUILayout.HorizontalSlider(value, min, max, UnityEngine.GUILayout.Width(_contentWidth - 96));
226+
UnityEngine.GUILayout.TextField(floatBuffer.ToString(), UnityEngine.GUILayout.Width(32));
227+
}
228+
#if UNITY_EDITOR
229+
else
230+
floatBuffer = UnityEditor.EditorGUILayout.Slider(value, min, max, UnityEngine.GUILayout.Width(_contentWidth - 8));
231+
#endif
163232
UnityEngine.GUILayout.EndHorizontal();
164233

165234
return new EditorValue<float>(floatBuffer, floatBuffer != value);
@@ -178,7 +247,6 @@ public static bool Toggle(string name, bool value)
178247
return UnityEngine.GUILayout.Toggle(value, name, UnityEngine.GUILayout.Width(_width));
179248
}
180249
}
181-
#endif
182250

183251
public struct EditorValue<T>
184252
{

System/Drawing/Graphics.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,8 @@ public string DrawTextArea(string s, Font font, SolidBrush brush, float x, float
640640
GUI.skin.textArea.fontSize = 12;
641641
}
642642

643+
GUI.skin.textArea.hover.background = null;
644+
643645
if (!_group)
644646
{
645647
var c_position = Control.PointToScreen(Point.Zero);
@@ -707,6 +709,7 @@ public string DrawTextField(string s, Font font, SolidBrush brush, float x, floa
707709
}
708710

709711
GUI.color = brush.Color.ToUColor();
712+
GUI.skin.textField.hover.background = null;
710713

711714
if (!_group)
712715
{

System/Windows/Forms/Application.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static bool IsStandalone
4646

4747
private static bool _ControlVisible(Control control)
4848
{
49-
if (control.Visible == false) return false;
49+
if (control.Visible == false || control.VisibleInternal == false) return false;
5050
if (control.Parent == null)
5151
return control.Visible;
5252
if (control.Parent.Visible)

System/Windows/Forms/ApplicationBehaviour.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private void Update()
6060
}
6161
_lastWidth = UnityEngine.Screen.width;
6262
_lastHeight = UnityEngine.Screen.height;
63-
63+
6464
_controller.Update();
6565
}
6666
private void OnApplicationFocus(bool focusStatus)
@@ -76,7 +76,8 @@ private void OnGUI()
7676
_controller.ProccessKeys();
7777
}
7878

79-
GUI.skin = Skin;
79+
if (Skin != null)
80+
GUI.skin = Skin;
8081
_controller.Draw();
8182
}
8283
}

System/Windows/Forms/Button.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ public class Button : Control
1111
{
1212
internal ColorF currentBackColor;
1313
private Color _normalColor;
14-
15-
#if UNITY_EDITOR
14+
1615
private bool _toggleEditor = true;
17-
#endif
1816

1917
public virtual Color HoverBorderColor { get; set; }
2018
public virtual Color HoverColor { get; set; }
@@ -48,7 +46,7 @@ public Button()
4846

4947
currentBackColor = NormalColor;
5048
}
51-
49+
5250
protected override void OnKeyUp(KeyEventArgs e)
5351
{
5452
base.OnKeyUp(e);
@@ -59,7 +57,7 @@ protected override void OnPaint(PaintEventArgs e)
5957
{
6058
Graphics g = e.Graphics;
6159

62-
if ((!Hovered && !Focused) || !Enabled)
60+
if ((!Hovered) || !Enabled)
6361
{
6462
currentBackColor = MathCustom.ColorLerp(currentBackColor, NormalColor, 5);
6563

@@ -104,8 +102,7 @@ protected override void OnPaint(PaintEventArgs e)
104102
protected override object OnPaintEditor(float width)
105103
{
106104
var control = base.OnPaintEditor(width);
107-
108-
#if UNITY_EDITOR
105+
109106
Editor.BeginVertical();
110107
Editor.NewLine(1);
111108

@@ -143,7 +140,6 @@ protected override object OnPaintEditor(float width)
143140
Editor.EndGroup();
144141
}
145142
Editor.EndVertical();
146-
#endif
147143

148144
return control;
149145
}

System/Windows/Forms/ColorPicker.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ protected override void OnMouseClick(MouseEventArgs e)
3434
{
3535
_currentForm = null;
3636
};
37+
_currentForm.Show();
3738
}
3839
_currentForm.BringToFront();
3940
}

0 commit comments

Comments
 (0)