-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMpfMonitorInspector.cs
More file actions
89 lines (75 loc) · 3.26 KB
/
MpfMonitorInspector.cs
File metadata and controls
89 lines (75 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Visual Pinball Engine
// Copyright (C) 2025 freezy and VPE Team
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System.Linq;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
using VisualPinball.Engine.Mpf.Unity.MediaController.Text;
namespace VisualPinball.Engine.Mpf.Unity.Editor
{
[
CustomEditor(typeof(MonitoredVariableTextBase), editorForChildClasses: true),
CanEditMultipleObjects
]
public class MpfMonitorInspector : UnityEditor.Editor
{
private HelpBox _missingGleHelpBox;
private HelpBox _misconfiguredGleHelpBox;
public override VisualElement CreateInspectorGUI()
{
var root = new VisualElement();
_missingGleHelpBox = new HelpBox(
"This component must be on a game object that is underneath an "
+ $"'{nameof(MpfGamelogicEngine)}' component in the scene hierarchy.",
HelpBoxMessageType.Error
);
root.Add(_missingGleHelpBox);
_misconfiguredGleHelpBox = new HelpBox(
"The MPF game logic engine is not configured to use the included media "
+ $"controller. Set 'Media Controller' to '{MpfMediaController.Included}' "
+ "in the game logic engine inspector.",
HelpBoxMessageType.Error
);
root.Add(_misconfiguredGleHelpBox);
UpdateErrorBoxVisibility();
EditorApplication.hierarchyChanged += OnHierarchyChanged;
InspectorElement.FillDefaultInspector(root, serializedObject, this);
return root;
}
private void OnHierarchyChanged() => UpdateErrorBoxVisibility();
private void UpdateErrorBoxVisibility()
{
if (targets.ToList().Any(IsGleMissing))
_missingGleHelpBox.style.display = DisplayStyle.Flex;
else
_missingGleHelpBox.style.display = DisplayStyle.None;
if (targets.ToList().Any(IsGleMisconfigured))
_misconfiguredGleHelpBox.style.display = DisplayStyle.Flex;
else
_misconfiguredGleHelpBox.style.display = DisplayStyle.None;
}
private void OnDisable()
{
EditorApplication.hierarchyChanged -= OnHierarchyChanged;
}
private MpfGamelogicEngine GetParentGle(UnityEngine.Object target)
{
return ((Component)target).GetComponentInParent<MpfGamelogicEngine>();
}
private bool IsGleMissing(UnityEngine.Object target) => GetParentGle(target) == null;
private bool IsGleMisconfigured(UnityEngine.Object target)
{
return !IsGleMissing(target)
&& GetParentGle(target).MediaControllerSetting != MpfMediaController.Included;
}
}
}