Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions Editor/Inspector/DisabledParentObjectHelpBox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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 UnityEngine;
using UnityEngine.UIElements;

namespace VisualPinball.Engine.Mpf.Unity.Editor
{
public class DisabledParentObjectHelpBox : VisualElement
{
private readonly HelpBox _box;
private readonly UnityEditor.Editor _editor;

public DisabledParentObjectHelpBox(UnityEditor.Editor editor)
{
_editor = editor;
_box = new HelpBox(
"The game object this component is attached to or one of its parents is disabled. This component" +
" cannot initialize until its parent object becomes active in the hierarchy. It is possible that" +
" events from MPF will be missed.",
HelpBoxMessageType.Warning);
Add(_box);

RegisterCallback<AttachToPanelEvent>(evt =>
{
UpdateHelpBoxVisibility();
EditorApplication.hierarchyChanged += OnHierarchyChanged;
});

RegisterCallback<DetachFromPanelEvent>(evt =>
{
EditorApplication.hierarchyChanged -= OnHierarchyChanged;
});
}

private void OnHierarchyChanged() => UpdateHelpBoxVisibility();

private void UpdateHelpBoxVisibility()
{
_box.style.display = _editor.targets.ToList().Any(IsParentObjectDisabled)
? DisplayStyle.Flex
: DisplayStyle.None;
}

private static bool IsParentObjectDisabled(UnityEngine.Object target) =>
!((Component)target).gameObject.activeInHierarchy;
}
}
3 changes: 3 additions & 0 deletions Editor/Inspector/DisabledParentObjectHelpBox.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions Editor/Inspector/EnableDuringModeInspector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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 UnityEditor;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
using VisualPinball.Engine.Mpf.Unity.MediaController.ObjectToggle;

namespace VisualPinball.Engine.Mpf.Unity.Editor
{
[CustomEditor(typeof(EnableDuringMode)), CanEditMultipleObjects]
public class EnableDuringModeInspector : UnityEditor.Editor
{
public override VisualElement CreateInspectorGUI()
{
var root = new VisualElement();
root.Add(new MissingGleHelpBoxes(this));
root.Add(new DisabledParentObjectHelpBox(this));
InspectorElement.FillDefaultInspector(root, serializedObject, this);
return root;
}
}
}
3 changes: 3 additions & 0 deletions Editor/Inspector/EnableDuringModeInspector.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

namespace VisualPinball.Engine.Mpf.Unity.Editor
{
[CustomEditor(typeof(MpfEventSound)), CanEditMultipleObjects]
public class MpfEventSoundInspector : SoundComponentInspector
[CustomEditor(typeof(EventSound)), CanEditMultipleObjects]
public class EventSoundInspector : SoundComponentInspector
{
[SerializeField]
private VisualTreeAsset mpfEventSoundInspectorXml;
Expand Down
71 changes: 71 additions & 0 deletions Editor/Inspector/MissingGleHelpBoxes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;

namespace VisualPinball.Engine.Mpf.Unity.Editor
{
public class MissingGleHelpBoxes : VisualElement
{
private readonly HelpBox _missingGleHelpBox;
private readonly HelpBox _misconfiguredGleHelpBox;
private readonly UnityEditor.Editor _editor;

public MissingGleHelpBoxes(UnityEditor.Editor editor)
{
_editor = editor;
_missingGleHelpBox = new HelpBox(
"This component must be on a game object that is underneath an "
+ "'MPF Game Logic' component in the scene hierarchy.",
HelpBoxMessageType.Error
);
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
);
Add(_misconfiguredGleHelpBox);

RegisterCallback<AttachToPanelEvent>(evt =>
{
UpdateHelpBoxVisibility();
EditorApplication.hierarchyChanged += OnHierarchyChanged;
});

RegisterCallback<DetachFromPanelEvent>(evt =>
{
EditorApplication.hierarchyChanged -= OnHierarchyChanged;
});
}

private void OnHierarchyChanged() => UpdateHelpBoxVisibility();

private void UpdateHelpBoxVisibility()
{
if (_editor.targets.ToList().Any(IsGleMissing))
_missingGleHelpBox.style.display = DisplayStyle.Flex;
else
_missingGleHelpBox.style.display = DisplayStyle.None;
if (_editor.targets.ToList().Any(IsGleMisconfigured))
_misconfiguredGleHelpBox.style.display = DisplayStyle.Flex;
else
_misconfiguredGleHelpBox.style.display = DisplayStyle.None;
}

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;
}
}
}
3 changes: 3 additions & 0 deletions Editor/Inspector/MissingGleHelpBoxes.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

namespace VisualPinball.Engine.Mpf.Unity.Editor
{
[CustomEditor(typeof(MpfModeSound)), CanEditMultipleObjects]
public class MpfModeSoundInspector : BinaryEventSoundInspector
[CustomEditor(typeof(ModeSound)), CanEditMultipleObjects]
public class ModeSoundInspector : BinaryEventSoundInspector
{
[SerializeField]
private VisualTreeAsset mpfModeSoundInspectorXml;
Expand Down
33 changes: 33 additions & 0 deletions Editor/Inspector/MonitoredVariableTextInspector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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 UnityEditor;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
using VisualPinball.Engine.Mpf.Unity.MediaController.Text;

namespace VisualPinball.Engine.Mpf.Unity.Editor
{
[
CustomEditor(typeof(MonitoredVariableTextBase), editorForChildClasses: true),
CanEditMultipleObjects
]
public class MonitoredVariableTextInspector : UnityEditor.Editor
{
public override VisualElement CreateInspectorGUI()
{
var root = new VisualElement();
root.Add(new MissingGleHelpBoxes(this));
InspectorElement.FillDefaultInspector(root, serializedObject, this);
return root;
}
}
}
89 changes: 0 additions & 89 deletions Editor/Inspector/MpfMonitorInspector.cs

This file was deleted.

31 changes: 31 additions & 0 deletions Editor/Inspector/ToggleOnEventInspector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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 UnityEditor;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
using VisualPinball.Engine.Mpf.Unity.MediaController.ObjectToggle;

namespace VisualPinball.Engine.Mpf.Unity.Editor
{
[CustomEditor(typeof(ToggleOnEvent)), CanEditMultipleObjects]
public class ToggleOnEventIInspector : UnityEditor.Editor
{
public override VisualElement CreateInspectorGUI()
{
var root = new VisualElement();
root.Add(new MissingGleHelpBoxes(this));
root.Add(new DisabledParentObjectHelpBox(this));
InspectorElement.FillDefaultInspector(root, serializedObject, this);
return root;
}
}
}
3 changes: 3 additions & 0 deletions Editor/Inspector/ToggleOnEventInspector.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading