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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

## Unreleased

Built with Unity 2021.2.
Built with Unity 2021.3.0

### Added
- Scale support for rubbers.
- Gate Lifter Component ([#418](https://github.com/freezy/VisualPinball.Engine/pull/418), [Documentation](https://docs.visualpinball.org/creators-guide/manual/mechanisms/lifting-gates.html)).
- Asset Browser ([#412](https://github.com/freezy/VisualPinball.Engine/pull/412))
- Trigger meshes can now be easily scaled ([#374](https://github.com/freezy/VisualPinball.Engine/pull/374))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

namespace VisualPinball.Unity.Editor
{
public partial class AssetBrowserX : EditorWindow, IDragHandler
public partial class AssetBrowser : EditorWindow, IDragHandler
{
[SerializeField]
private int _thumbnailSize = 150;
Expand Down Expand Up @@ -62,7 +62,7 @@ private AssetResult LastSelectedAsset {
[MenuItem("Visual Pinball/Asset Browser")]
public static void ShowWindow()
{
var wnd = GetWindow<AssetBrowserX>();
var wnd = GetWindow<AssetBrowser>();
wnd.titleContent = new GUIContent("Asset Browser", Icons.AssetLibrary(IconSize.Small));

// Limit size of the window
Expand Down

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

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

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 @@ -21,7 +21,7 @@

namespace VisualPinball.Unity.Editor
{
public partial class AssetBrowserX
public partial class AssetBrowser
{
private ToolbarButton _refreshButton;
private ToolbarSearchField _queryInput;
Expand Down Expand Up @@ -77,14 +77,14 @@ private string DragError {
public void CreateGUI()
{
// import UXML
var visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Packages/org.visualpinball.engine.unity/VisualPinball.Unity/VisualPinball.Unity.Editor/AssetBrowser/AssetBrowserX.uxml");
var visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Packages/org.visualpinball.engine.unity/VisualPinball.Unity/VisualPinball.Unity.Editor/AssetBrowser/AssetBrowser.uxml");
visualTree.CloneTree(rootVisualElement);
_assetTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Packages/org.visualpinball.engine.unity/VisualPinball.Unity/VisualPinball.Unity.Editor/AssetBrowser/LibraryAssetElement.uxml");

var ui = rootVisualElement;

// import style sheet
var styleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>("Packages/org.visualpinball.engine.unity/VisualPinball.Unity/VisualPinball.Unity.Editor/AssetBrowser/AssetBrowserX.uss");
var styleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>("Packages/org.visualpinball.engine.unity/VisualPinball.Unity/VisualPinball.Unity.Editor/AssetBrowser/AssetBrowser.uss");
ui.styleSheets.Add(styleSheet);

// libraries
Expand Down

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 @@ -188,7 +188,7 @@ public void UpdateDetails()
return;
}

var browser = panel.visualTree.userData as AssetBrowserX;
var browser = panel.visualTree.userData as AssetBrowser;
_object = _asset.Asset.Object;
_titleElement.text = _asset.Asset.Name;
_libraryElement.text = _asset.Library.Name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Unity.Mathematics;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
Expand Down Expand Up @@ -49,7 +50,15 @@ public void Search(string q)
{
// parse attributes
_attributes.Clear();
foreach (var regex in new []{ new Regex(@"(\w+):(\w+)"), new Regex("\"([\\w\\s]+)\":(\\w+)"), new Regex("(\\w+):\"([\\w\\s]+)\""), new Regex("\"([\\w\\s]+)\":\"([\\w\\s]+)\"") }) {
const string quoted = "\"([\\w\\d\\s_-]+)\"";
const string nonQuoted = "([\\w\\d_-]+)";
var regexes = new[] {
new Regex($"{nonQuoted}:{nonQuoted}"),
new Regex($"{quoted}:{nonQuoted}"),
new Regex($"{nonQuoted}:{quoted}"),
new Regex($"{quoted}:{quoted}")
};
foreach (var regex in regexes) {
foreach (Match match in regex.Matches(q)) {
var key = match.Groups[1].Value;
if (!_attributes.ContainsKey(key)) {
Expand Down Expand Up @@ -151,6 +160,13 @@ public AssetResult(AssetLibrary library, LibraryAsset asset, long score)
Score = score;
}

public void AddScore(long score)
{
Score = Score < 0
? math.max(Score, score)
: math.max(Score, Score + score);
}

public void Save()
{
Library.SaveAsset(Asset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class KeyValueElement : VisualElement

private readonly bool _isLink;
private bool _isEditing;
private AssetBrowserX _browser;
private AssetBrowser _browser;

private VisualElement DisplayContainer => _isLink ? _displayLinkElement : _displayElement;
private Label DisplayElement => _isLink ? _linkElement : _nameElement;
Expand Down Expand Up @@ -86,7 +86,7 @@ public KeyValueElement(AssetResult result, LibraryKeyValue keyValue, bool isLink

private void OnAttached(AttachToPanelEvent evt)
{
_browser = panel.visualTree.userData as AssetBrowserX;
_browser = panel.visualTree.userData as AssetBrowser;
_valuesEditElement.RegisterCallback<FocusInEvent>(OnAttributeValueFocus);
Update();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private void OnPointerUp(PointerUpEvent evt)

private void OnDragEnterEvent(DragEnterEvent evt)
{
if (AssetBrowserX.IsDraggingExistingAssets || AssetBrowserX.IsDraggingNewAssets) {
if (AssetBrowser.IsDraggingExistingAssets || AssetBrowser.IsDraggingNewAssets) {
AddToClassList(ClassDrag);
} else {
return;
Expand Down Expand Up @@ -198,7 +198,7 @@ private void OnDragEnterEvent(DragEnterEvent evt)

private static void OnDragUpdatedEvent(DragUpdatedEvent evt)
{
DragAndDrop.visualMode = AssetBrowserX.IsDraggingExistingAssets || AssetBrowserX.IsDraggingNewAssets
DragAndDrop.visualMode = AssetBrowser.IsDraggingExistingAssets || AssetBrowser.IsDraggingNewAssets
? DragAndDropVisualMode.Move
: DragAndDropVisualMode.Rejected;
}
Expand All @@ -208,7 +208,7 @@ private void OnDragPerformEvent(DragPerformEvent evt)
RemoveFromClassList(ClassDrag);
if (_libraryCategoryView.DragError != null) {
_libraryCategoryView.DragError = null;
AssetBrowserX.StopDraggingAssets();
AssetBrowser.StopDraggingAssets();
return;
}

Expand All @@ -221,12 +221,12 @@ private void OnDragPerformEvent(DragPerformEvent evt)
d.Library.SetCategory(d.Asset, category);
}
_libraryCategoryView.Refresh();
AssetBrowserX.StopDraggingAssets();
AssetBrowser.StopDraggingAssets();
return;
}

// drop from outside
if (AssetBrowserX.IsDraggingNewAssets) {
if (AssetBrowser.IsDraggingNewAssets) {
_libraryCategoryView.AddAssets(DragAndDrop.paths, assetLibrary => Categories.FirstOrDefault(i => i.Item1 == assetLibrary).Item2 ??assetLibrary.AddCategory(Name));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public string DragError {

public void AddAssets(IEnumerable<string> paths, Func<AssetLibrary, LibraryCategory> getCategory) => _browser.AddAssets(paths, getCategory);

private AssetBrowserX _browser;
private AssetBrowser _browser;
private AssetLibrary _activeLibrary;

private readonly VisualElement _container;
Expand Down Expand Up @@ -87,7 +87,7 @@ private string OnActiveLibraryChanged(string libraryName)
return libraryName;
}

public void Refresh(AssetBrowserX browser = null)
public void Refresh(AssetBrowser browser = null)
{
if (browser != null) {
_browser = browser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Unity.Mathematics;
using UnityEditor;
using UnityEditor.Search;
using UnityEngine;
Expand All @@ -41,13 +42,16 @@ public IEnumerable<AssetResult> GetAssets(AssetLibrary lib, LibraryQuery query)
results = results
.Select(result => {
FuzzySearch.FuzzyMatch(query.Keywords, result.Asset.Object.name, ref result.Score);
/* todo fix search in tags and attributes.
foreach (var tag in result.Asset.Tags) {
FuzzySearch.FuzzyMatch(query.Keywords, tag, ref result.Score);
var score = 0L;
FuzzySearch.FuzzyMatch(query.Keywords, tag, ref score);
result.AddScore(score);
}
foreach (var value in result.Asset.Attributes.SelectMany(values => values.Value.Split(","))) {
FuzzySearch.FuzzyMatch(query.Keywords, value, ref result.Score);
}*/
var score = 0L;
FuzzySearch.FuzzyMatch(query.Keywords, value, ref score);
result.AddScore(score);
}
return result;
})
.Where(result => result.Score > 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public bool IsActive {
private readonly SearchSuggest _nameEditElement;

private bool _isEditing;
private AssetBrowserX _browser;
private AssetBrowser _browser;

public TagElement(AssetResult result, string value, SerializableHashSet<string> values)
{
Expand Down Expand Up @@ -83,7 +83,7 @@ public TagElement(AssetResult result, string value, SerializableHashSet<string>

private void OnAttached(AttachToPanelEvent evt)
{
_browser = panel.visualTree.userData as AssetBrowserX;
_browser = panel.visualTree.userData as AssetBrowser;
}

private void OnNameClicked(MouseDownEvent evt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,11 @@ public GameObject Convert(bool applyPatch = true, string tableName = null)
ExtractTextures();
ExtractSounds();
SaveData();
SaveLegacyData();

var prefabLookup = InstantiateGameItems();
var componentLookup = UpdateGameItems(prefabLookup);

SaveLegacyData(); // now we freed the binary data, write the remaining game items.
FinalizeGameItems(componentLookup);

FreeTextures();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public class SlingshotInspector : ItemInspector
private SerializedProperty _animationDurationProperty;
private SerializedProperty _animationCurveProperty;
private SerializedProperty _coilArmProperty;
private SerializedProperty _coilArmAngleProperty;
private SerializedProperty _coilArmEndAngleProperty;
private SerializedProperty _coilArmStartAngleProperty;
private SerializedProperty _coilArmRotationAxis;

protected override MonoBehaviour UndoTarget => target as MonoBehaviour;

Expand All @@ -44,7 +46,9 @@ protected override void OnEnable()
_rubberOffProperty = serializedObject.FindProperty(nameof(SlingshotComponent.RubberOff));
_rubberOnProperty = serializedObject.FindProperty(nameof(SlingshotComponent.RubberOn));
_coilArmProperty = serializedObject.FindProperty(nameof(SlingshotComponent.CoilArm));
_coilArmAngleProperty = serializedObject.FindProperty(nameof(SlingshotComponent.CoilArmAngle));
_coilArmStartAngleProperty = serializedObject.FindProperty(nameof(SlingshotComponent.CoilArmStartAngle));
_coilArmEndAngleProperty = serializedObject.FindProperty(nameof(SlingshotComponent.CoilArmEndAngle));
_coilArmRotationAxis = serializedObject.FindProperty(nameof(SlingshotComponent.CoilArmRotationAxis));
_animationDurationProperty = serializedObject.FindProperty(nameof(SlingshotComponent.AnimationDuration));
_animationCurveProperty = serializedObject.FindProperty(nameof(SlingshotComponent.AnimationCurve));
}
Expand All @@ -66,7 +70,9 @@ public override void OnInspectorGUI()

EditorGUILayout.Space(10f);
PropertyField(_coilArmProperty, "Coil Arm");
PropertyField(_coilArmAngleProperty, "Arm Angle");
PropertyField(_coilArmStartAngleProperty, "Start Angle");
PropertyField(_coilArmEndAngleProperty, "End Angle");
PropertyField(_coilArmRotationAxis, "Rotation Axis");

EditorGUILayout.Space(10f);
PropertyField(_animationDurationProperty, "Animation Duration");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ private void HandleMoveTool()
private void HandleScaleTool()
{
var e = Event.current;
if (e.type == EventType.MouseDown || e.type == EventType.MouseUp) {
var startScaling = e.type == EventType.MouseDown;
var endScaling = e.type == EventType.MouseUp;
if (startScaling || endScaling) {
_scaleFactor = _primaryItem.GetEditorScale().x;
}

Expand All @@ -290,6 +292,14 @@ private void HandleScaleTool()
}
var handleRot = _transform.rotation;
var handleScale = HandleUtility.GetHandleSize(handlePos);

if (startScaling) {
_primaryItem.EditorStartScaling();
}
if (endScaling) {
_primaryItem.EditorEndScaling();
}

switch (_primaryItem.EditorScaleType) {

case ItemDataTransformType.OneD: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ private static void SetupLeftSlingshot(GameObject go)
ss.SlingshotSurface = go.GetComponent<SurfaceColliderComponent>();
ss.RubberOff = playfieldGo.transform.Find("Rubbers/LeftSling1").GetComponent<RubberComponent>();
ss.RubberOn = playfieldGo.transform.Find("Rubbers/LeftSling4").GetComponent<RubberComponent>();
ss.CoilArm = playfieldGo.transform.Find("Primitives/Lemk").GetComponent<PrimitiveComponent>();
ss.CoilArmAngle = 22f;
ss.CoilArm = playfieldGo.transform.Find("Primitives/Lemk").gameObject;
ss.CoilArmEndAngle = 22f;

EditorUtility.SetDirty(ssGo);
PrefabUtility.RecordPrefabInstancePropertyModifications(ss);
Expand All @@ -173,8 +173,8 @@ private static void SetupRightSlingshot(GameObject go)
ss.SlingshotSurface = go.GetComponent<SurfaceColliderComponent>();
ss.RubberOff = playfieldGo.transform.Find("Rubbers/RightSling1").GetComponent<RubberComponent>();
ss.RubberOn = playfieldGo.transform.Find("Rubbers/RightSling3").GetComponent<RubberComponent>();
ss.CoilArm = playfieldGo.transform.Find("Primitives/Remk").GetComponent<PrimitiveComponent>();
ss.CoilArmAngle = 22f;
ss.CoilArm = playfieldGo.transform.Find("Primitives/Remk").gameObject;
ss.CoilArmEndAngle = 22f;

EditorUtility.SetDirty(ssGo);
PrefabUtility.RecordPrefabInstancePropertyModifications(ss);
Expand Down
24 changes: 24 additions & 0 deletions VisualPinball.Unity/VisualPinball.Unity/Game/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public class Player : MonoBehaviour

public event EventHandler OnUpdate;

public event EventHandler<BallEvent> OnBallCreated;
public event EventHandler<BallEvent> OnBallDestroyed;

[HideInInspector] [SerializeField] public string debugUiId;
[HideInInspector] [SerializeField] public string physicsEngineId;

Expand Down Expand Up @@ -485,6 +488,15 @@ public void OnEvent(in EventData eventData)
}
}

internal void BallCreated(Entity ballEntity, GameObject ball)
{
OnBallCreated?.Invoke(this, new BallEvent(ballEntity, ball));
}
internal void BallDestroyed(Entity ballEntity, GameObject ball)
{
OnBallDestroyed?.Invoke(this, new BallEvent(ballEntity, ball));
}

#endregion

#region API
Expand Down Expand Up @@ -579,4 +591,16 @@ private static void HandleInput(object obj, InputActionChange change)
}
}
}

public readonly struct BallEvent
{
public readonly Entity BallEntity;
public readonly GameObject Ball;

public BallEvent(Entity ballEntity, GameObject ball)
{
BallEntity = ballEntity;
Ball = ball;
}
}
}
Loading