Skip to content

Commit 7d36eb3

Browse files
committed
assets: Add reference to background object.
1 parent 5a0f7c1 commit 7d36eb3

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

VisualPinball.Unity/VisualPinball.Unity.Editor/AssetBrowser/AssetStructure/Asset.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,19 @@ public class Asset : ScriptableObject
6363
[NonReorderable] // see https://answers.unity.com/questions/1828499/nested-class-lists-inspector-overlapping-bug.html
6464
public List<AssetMaterialVariation> MaterialVariations;
6565

66+
[SerializeField]
67+
public string ThumbBackgroundObjectName;
68+
6669
[SerializeReference]
6770
public Preset ThumbCameraPreset;
6871

6972
[SerializeField]
7073
public float ThumbCameraHeight;
7174

72-
[SerializeReference]
75+
[SerializeField]
76+
public bool ThumbTopLight;
77+
78+
[SerializeField]
7379
public bool UnpackPrefab;
7480

7581
[SerializeReference]

VisualPinball.Unity/VisualPinball.Unity.Editor/AssetBrowser/AssetStructure/AssetDetails.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using UnityEditor;
2323
using UnityEditor.UIElements;
2424
using UnityEngine;
25+
using UnityEngine.SceneManagement;
2526
using UnityEngine.UIElements;
2627
using Object = UnityEngine.Object;
2728

@@ -165,6 +166,28 @@ public void Bind(Asset asset)
165166
description.text = asset.Description;
166167
SetVisibility(description, asset.Library.IsLocked && !string.IsNullOrEmpty(asset.Description));
167168

169+
BindBackgroundObjects();
170+
}
171+
172+
private void BindBackgroundObjects()
173+
{
174+
var bgo = _body.Q<ObjectDropdownElement>("background-object-field");
175+
var bgParent = SceneManager.GetActiveScene().GetRootGameObjects()
176+
.FirstOrDefault(go => go.name == "_BackgroundObjects");
177+
178+
if (bgParent == null) {
179+
bgo.visible = false;
180+
return;
181+
}
182+
bgo.visible = true;
183+
bgo.Value = _asset.ThumbBackgroundObjectName != null ? bgParent.transform.Find(_asset.ThumbBackgroundObjectName)?.gameObject : null;
184+
bgo.AddObjectsToDropdown<MeshRenderer>(bgParent, true);
185+
bgo.RegisterValueChangedCallback(OnThumbBackgroundObjectChanged);
186+
}
187+
188+
private void OnThumbBackgroundObjectChanged(Object obj)
189+
{
190+
_asset.ThumbBackgroundObjectName = obj.name;
168191
}
169192

170193
private void BindInfo(Asset asset)

VisualPinball.Unity/VisualPinball.Unity.Editor/AssetBrowser/AssetStructure/AssetDetails_Body.uxml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@
3131
<uie:PropertyField binding-path="Links" label="Links" class="top-space" />
3232

3333
<!-- Geometry -->
34-
<ui:Foldout text="Geometry">
34+
<ui:Foldout text="Thumbnail Settings">
3535
<ui:VisualElement class="left-indent">
36-
<uie:PropertyField binding-path="Scale" label="Scale Transform" />
37-
<uivpe:PresetDropdownElement name="thumb-camera-preset" binding-path="ThumbCameraPreset" label="Thumbnail Camera" preset-path="Packages/org.visualpinball.engine.unity/VisualPinball.Unity/Assets/Presets/Asset Thumbcam" />
38-
<uie:PropertyField binding-path="ThumbCameraHeight" label="Thumb Object Z-Pos" />
36+
<uivpe:ObjectDropdownElement name="background-object-field" label="On Object" />
37+
<uivpe:PresetDropdownElement name="thumb-camera-preset" binding-path="ThumbCameraPreset" label="Camera" preset-path="Packages/org.visualpinball.engine.unity/VisualPinball.Unity/Assets/Presets/Asset Thumbcam" />
38+
<uie:PropertyField binding-path="ThumbCameraHeight" label="Z-Position" />
39+
<uie:PropertyField binding-path="ThumbTopLight" label="Enable Top Light" />
3940
</ui:VisualElement>
4041
</ui:Foldout>
4142

VisualPinball.Unity/VisualPinball.Unity.Editor/AssetBrowser/Elements/ObjectDropdownElement.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ public void RegisterValueChangedCallback(Action<Object> onValueChanged)
8787
_onValueChanged = onValueChanged;
8888
}
8989

90-
public void AddObjectsToDropdown<T>(Object parentObj) where T : Component
90+
public void AddObjectsToDropdown<T>(Object parentObj, bool includeInactive = false) where T : Component
9191
{
9292
if (parentObj is not GameObject parentGo) {
9393
return;
9494
}
9595
_objects.Clear();
96-
_objects.AddRange(parentGo.GetComponentsInChildren<T>().Select(c => c.gameObject));
96+
_objects.AddRange(parentGo.GetComponentsInChildren<T>(includeInactive).Select(c => c.gameObject));
9797
_dropdown.choices = _objects.Select(go => go.name).ToList();
9898
if (_objectPicker.value) {
9999
_dropdown.SetValueWithoutNotify(_objectPicker.value.name);
@@ -102,6 +102,11 @@ public void AddObjectsToDropdown<T>(Object parentObj) where T : Component
102102

103103
public void SetValue(Object obj)
104104
{
105+
if (obj == null) {
106+
_dropdown.SetValueWithoutNotify(null);
107+
_objectPicker.value = null;
108+
return;
109+
}
105110
var selectedGo = _objects.FirstOrDefault(go => go.name == obj.name);
106111
if (selectedGo != null) {
107112
_dropdown.SetValueWithoutNotify(obj.name);

0 commit comments

Comments
 (0)