Skip to content

Commit 4486d48

Browse files
committed
unity: Add package.
1 parent 2b6ea5a commit 4486d48

28 files changed

+4721
-4
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ StyleCopReport.xml
6969
*_p.c
7070
*_h.h
7171
*.ilk
72-
*.meta
7372
*.obj
7473
*.iobj
7574
*.pch

VisualPinball.Engine.Mpf.Unity/Editor.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Visual Pinball Engine
2+
// Copyright (C) 2021 freezy and VPE Team
3+
//
4+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
7+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
8+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
9+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
10+
// SOFTWARE.
11+
12+
using UnityEditor;
13+
using UnityEngine;
14+
15+
namespace VisualPinball.Engine.Mpf.Unity.Editor
16+
{
17+
[CustomEditor(typeof(MpfGamelogicEngine))]
18+
public class MpfGamelogicEngineInspector : UnityEditor.Editor
19+
{
20+
private MpfGamelogicEngine _mpfEngine;
21+
22+
private void OnEnable()
23+
{
24+
_mpfEngine = target as MpfGamelogicEngine;
25+
}
26+
27+
public override void OnInspectorGUI()
28+
{
29+
if (GUILayout.Button("Refresh")) {
30+
_mpfEngine.RefreshFromMpf();
31+
}
32+
}
33+
}
34+
}

VisualPinball.Engine.Mpf.Unity/Editor/MpfGamelogicEngineInspector.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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "VisualPinball.Engine.Mpf.Unity.Editor",
3+
"rootNamespace": "VisualPinball.Engine.Mpf.Unity.Editor",
4+
"references": [
5+
"VisualPinball.Unity",
6+
"VisualPinball.Engine.Mpf.Unity"
7+
],
8+
"includePlatforms": [ "Editor" ],
9+
"excludePlatforms": [],
10+
"allowUnsafeCode": true,
11+
"overrideReferences": false,
12+
"precompiledReferences": [],
13+
"autoReferenced": true,
14+
"defineConstraints": [],
15+
"versionDefines": [],
16+
"noEngineReferences": false
17+
}

VisualPinball.Engine.Mpf.Unity/Editor/VisualPinball.Engine.Mpf.Unity.Editor.asmdef.meta

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

VisualPinball.Engine.Mpf.Unity/Plugins.meta

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

VisualPinball.Engine.Mpf.Unity/Runtime.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Visual Pinball Engine
2+
// Copyright (C) 2021 freezy and VPE Team
3+
//
4+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
7+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
8+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
9+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
10+
// SOFTWARE.
11+
12+
using System;
13+
using System.Collections.Generic;
14+
using System.IO;
15+
using System.Threading.Tasks;
16+
using Mpf.Vpe;
17+
18+
namespace VisualPinball.Engine.Mpf.Unity
19+
{
20+
public class MpfApi : IDisposable
21+
{
22+
private readonly MpfClient _client = new MpfClient();
23+
private readonly MpfSpawner _spawner;
24+
25+
public MpfApi(string machineFolder)
26+
{
27+
_spawner = new MpfSpawner(Path.GetFullPath(machineFolder));
28+
}
29+
30+
/// <summary>
31+
/// Launches MPF in the background and connects to it via gRPC.
32+
/// </summary>
33+
/// <param name="port">gRPC port to use for MPC/VPE communication</param>
34+
/// <returns></returns>
35+
public async Task Launch(int port = 50051)
36+
{
37+
await _spawner.Spawn();
38+
await _client.Connect($"localhost:{port}");
39+
}
40+
41+
/// <summary>
42+
/// Starts MPF, i.e. it will start polling for switches and sending events.
43+
/// </summary>
44+
/// <param name="initialSwitches">Initial switch states of the machine</param>
45+
public void Start(Dictionary<string, bool> initialSwitches = null)
46+
{
47+
_client.Start(initialSwitches ?? new Dictionary<string, bool>());
48+
}
49+
50+
/// <summary>
51+
/// Returns the machine description.
52+
/// </summary>
53+
public async Task<MachineDescription> GetMachineDescription()
54+
{
55+
return await _client.GetMachineDescription();
56+
}
57+
58+
public void Dispose()
59+
{
60+
_client?.Dispose();
61+
}
62+
}
63+
}

VisualPinball.Engine.Mpf.Unity/Runtime/MpfApi.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.

0 commit comments

Comments
 (0)