Skip to content

Commit 933c5a0

Browse files
committed
Add property drawers for the GLE's switches and coils.
1 parent 8a03a34 commit 933c5a0

10 files changed

+175
-1
lines changed

Editor/DummyEditorDependency.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
internal class DummyEditorDependency : UnityEditor.Editor { }
1+
// see:
2+
// - https://forum.unity.com/threads/cant-get-custom-unitwidget-to-work.1212936/
3+
// - https://forum.unity.com/threads/additional-editor-assemblies-are-not-detected-correctly.1197328/
4+
internal class DummyEditorDependency : UnityEditor.Editor { }

Editor/PropertyDrawers.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Visual Pinball Engine
2+
// Copyright (C) 2021 freezy and VPE Team
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
17+
using UnityEditor;
18+
using VisualPinball.Unity.VisualScripting;
19+
20+
namespace Editor.PropertyDrawers
21+
{
22+
[CustomPropertyDrawer(typeof(VisualScriptingCoil))]
23+
public class VisualScriptingCoilPropertyDrawer : VisualScriptingDeviceItemPropertyDrawer
24+
{
25+
public override string NameName => nameof(VisualScriptingCoil.Name);
26+
public override string DescName => nameof(VisualScriptingCoil.Desc);
27+
}
28+
}

Editor/PropertyDrawers/VisualScriptingCoilPropertyDrawer.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Visual Pinball Engine
2+
// Copyright (C) 2021 freezy and VPE Team
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
17+
using UnityEditor;
18+
using UnityEngine;
19+
using VisualPinball.Unity.VisualScripting;
20+
21+
namespace Editor.PropertyDrawers
22+
{
23+
public abstract class VisualScriptingDeviceItemPropertyDrawer : PropertyDrawer
24+
{
25+
private const float Padding = 2f;
26+
27+
public abstract string NameName { get; }
28+
public abstract string DescName { get; }
29+
30+
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
31+
{
32+
return EditorGUIUtility.singleLineHeight + Padding;
33+
}
34+
35+
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
36+
{
37+
EditorGUI.BeginProperty(position, label, property);
38+
39+
var nameProperty = property.FindPropertyRelative(NameName);
40+
var descProperty = property.FindPropertyRelative(DescName);
41+
42+
position.y += 2f;
43+
position.height = EditorGUIUtility.singleLineHeight;
44+
45+
const float space = 4f;
46+
var leftWidth = position.width / 3f;
47+
var rightWidth = position.width / 3f * 2f;
48+
var labelWidth = 20f;
49+
var halfPos = position;
50+
halfPos.width = leftWidth - labelWidth - space;
51+
var labelPos = halfPos;
52+
halfPos.x += labelWidth;
53+
labelPos.width = labelWidth;
54+
EditorGUI.LabelField(labelPos, "ID:");
55+
EditorGUI.PropertyField(halfPos, nameProperty, GUIContent.none);
56+
57+
labelWidth = 42f;
58+
halfPos = position;
59+
halfPos.width = rightWidth - labelWidth;
60+
labelPos = halfPos;
61+
labelPos.x += leftWidth;
62+
halfPos.x += leftWidth + labelWidth;
63+
labelPos.width = labelWidth;
64+
EditorGUI.LabelField(labelPos, "Descr:");
65+
EditorGUI.PropertyField(halfPos, descProperty, GUIContent.none);
66+
67+
EditorGUI.EndProperty();
68+
}
69+
}
70+
}

Editor/PropertyDrawers/VisualScriptingDeviceItemPropertyDrawer.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Visual Pinball Engine
2+
// Copyright (C) 2021 freezy and VPE Team
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
17+
using UnityEditor;
18+
using VisualPinball.Unity.VisualScripting;
19+
20+
namespace Editor.PropertyDrawers
21+
{
22+
[CustomPropertyDrawer(typeof(VisualScriptingSwitch))]
23+
public class VisualScriptingSwitchPropertyDrawer : VisualScriptingDeviceItemPropertyDrawer
24+
{
25+
public override string NameName => nameof(VisualScriptingSwitch.Name);
26+
public override string DescName => nameof(VisualScriptingSwitch.Desc);
27+
}
28+
}

Editor/PropertyDrawers/VisualScriptingSwitchPropertyDrawer.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Gamelogic/VisualScriptingCoil.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

17+
// ReSharper disable InconsistentNaming
18+
1719
using System;
1820
using VisualPinball.Engine.Game.Engines;
1921

@@ -23,9 +25,12 @@ namespace VisualPinball.Unity.VisualScripting
2325
public class VisualScriptingCoil : GamelogicEngineCoil
2426
{
2527
public string Name;
28+
public string Desc;
2629

2730
public override string Id => Name;
2831

32+
public override string Description => Desc;
33+
2934
public VisualScriptingCoil() : base(string.Empty)
3035
{
3136
}

Runtime/Gamelogic/VisualScriptingSwitch.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

17+
// ReSharper disable InconsistentNaming
18+
1719
using System;
1820
using VisualPinball.Engine.Game.Engines;
1921

@@ -23,8 +25,10 @@ namespace VisualPinball.Unity.VisualScripting
2325
public class VisualScriptingSwitch : GamelogicEngineSwitch
2426
{
2527
public string Name;
28+
public string Desc;
2629

2730
public override string Id => Name;
31+
public override string Description => Desc;
2832

2933
public VisualScriptingSwitch() : base(string.Empty)
3034
{

0 commit comments

Comments
 (0)