Skip to content

Commit

Permalink
Avoid errors on non Mac platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
keijiro committed Nov 25, 2023
1 parent dc5305d commit 17103db
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Legacy/ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
m_EditorVersion: 2022.3.13f1
m_EditorVersionWithRevision: 2022.3.13f1 (5f90a5ebde0f)
m_EditorVersion: 2022.3.14f1
m_EditorVersionWithRevision: 2022.3.14f1 (eff2de9070d8)
14 changes: 14 additions & 0 deletions jp.keijiro.klak.syphon/Runtime/Interop/PluginClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public Texture2D CreateTexture()

#region Unmanaged interface

#if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX

[DllImport("KlakSyphon", EntryPoint = "Plugin_CreateClient")]
static extern PluginClient _Create(string name, string appName);

Expand All @@ -84,6 +86,18 @@ public Texture2D CreateTexture()
[DllImport("KlakSyphon", EntryPoint = "Plugin_UpdateClient")]
static extern void _Update(PluginClient instance);

#else

static PluginClient _Create(string name, string appName) => null;
static void _Destroy(IntPtr instance) {}
static bool _IsValid(PluginClient instance) => false;
static IntPtr _GetTexture(PluginClient instance) => IntPtr.Zero;
static int _GetTextureWidth(PluginClient instance) => 0;
static int _GetTextureHeight(PluginClient instance) => 0;
static void _Update(PluginClient instance) {}

#endif

#endregion
}

Expand Down
9 changes: 9 additions & 0 deletions jp.keijiro.klak.syphon/Runtime/Interop/PluginCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@ namespace Klak.Syphon.Interop {

public static class PluginCommon
{
#if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX

[DllImport("KlakSyphon", EntryPoint = "Plugin_EnableColorSpaceConversion")]
public static extern void EnableColorSpaceConversion();

[DllImport("KlakSyphon", EntryPoint = "Plugin_DisableColorSpaceConversion")]
public static extern void DisableColorSpaceConversion();

#else

public static void EnableColorSpaceConversion() {}
public static void DisableColorSpaceConversion() {}

#endif
}

} // namespace Klak.Sypho.Interopn
12 changes: 12 additions & 0 deletions jp.keijiro.klak.syphon/Runtime/Interop/PluginServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static (PluginServer, Texture2D)
CreateWithBackedTexture(string name, int width, int height)
{
var instance = Create(name, width, height);
if (instance == null) return (null, null);
var texture = Texture2D.CreateExternalTexture
(width, height, TextureFormat.RGBA32,
false, false, instance.TexturePointer);
Expand All @@ -49,6 +50,8 @@ public static (PluginServer, Texture2D)

#region Unmanaged interface

#if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX

[DllImport("KlakSyphon", EntryPoint = "Plugin_CreateServer")]
static extern PluginServer _Create(string name, int width, int height);

Expand All @@ -61,6 +64,15 @@ public static (PluginServer, Texture2D)
[DllImport("KlakSyphon", EntryPoint = "Plugin_PublishServerTexture")]
static extern void _PublishTexture(PluginServer instance);

#else

static PluginServer _Create(string name, int width, int height) => null;
static void _Destroy(IntPtr instance) {}
static IntPtr _GetTexture(PluginServer instance) => IntPtr.Zero;
static void _PublishTexture(PluginServer instance) {}

#endif

#endregion
}

Expand Down
12 changes: 12 additions & 0 deletions jp.keijiro.klak.syphon/Runtime/Interop/ServerList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ protected override bool ReleaseHandle()
string ToString(IntPtr ptr)
=> ptr != IntPtr.Zero ? Marshal.PtrToStringAnsi(ptr) : null;

#if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX

[DllImport("KlakSyphon", EntryPoint = "Plugin_CreateServerList")]
static extern ServerList _Create();

Expand All @@ -52,6 +54,16 @@ string ToString(IntPtr ptr)
[DllImport("KlakSyphon", EntryPoint = "Plugin_GetAppNameFromServerList")]
static extern IntPtr _GetAppName(ServerList list, int index);

#else

static ServerList _Create() => null;
static void _Destroy(IntPtr list) {}
static int _GetCount(ServerList list) => 0;
static IntPtr _GetName(ServerList list, int index) => IntPtr.Zero;
static IntPtr _GetAppName(ServerList list, int index) => IntPtr.Zero;

#endif

#endregion
}

Expand Down
2 changes: 1 addition & 1 deletion jp.keijiro.klak.syphon/Runtime/SyphonServerDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static IEnumerable<string> EnumerateServerNames()
{
using var plugin = Interop.ServerList.Create();
var list = new List<string>();
for (var i = 0; i < plugin.Count; i++)
for (var i = 0; i < (plugin?.Count ?? 0); i++)
{
var (app, name) = (plugin.GetAppName(i), plugin.GetName(i));
list.Add(string.IsNullOrEmpty(name) ? app : $"{app}/{name}");
Expand Down

0 comments on commit 17103db

Please sign in to comment.