Example of platform specified dependencies. No more need for #if statements across all your code!
diff --git a/SuiceExample/Assets/SuiceExample/Scripts/Injector/SuiceExampleInjector.cs b/SuiceExample/Assets/SuiceExample/Scripts/Injector/SuiceExampleInjector.cs
index 5b3399e..592860a 100644
--- a/SuiceExample/Assets/SuiceExample/Scripts/Injector/SuiceExampleInjector.cs
+++ b/SuiceExample/Assets/SuiceExample/Scripts/Injector/SuiceExampleInjector.cs
@@ -1,4 +1,5 @@
-using UnitySuiceCommons.Injector;
+using SuiceExample.Platform;
+using UnitySuiceCommons.Injector;
/// <summary>
/// @author DisTurBinG
@@ -7,6 +8,7 @@
protected override void RegisterModules()
{
-
+ // Registers platform example module here - which is used to manually bind dependencies based on platform type
+ Injector.RegisterModule(new PlatformExampleModule());
}
}
diff --git a/SuiceExample/Assets/SuiceExample/Scripts/Platform.meta b/SuiceExample/Assets/SuiceExample/Scripts/Platform.meta
new file mode 100644
index 0000000..c6524d1
--- /dev/null
+++ b/SuiceExample/Assets/SuiceExample/Scripts/Platform.meta
@@ -0,0 +1,5 @@
+fileFormatVersion: 2
+guid: 49f04ed17fa51274ea8bca06af438645
+folderAsset: yes
+DefaultImporter:
+ userData:
diff --git a/SuiceExample/Assets/SuiceExample/Scripts/Platform/AndroidPlatformExample.cs b/SuiceExample/Assets/SuiceExample/Scripts/Platform/AndroidPlatformExample.cs
new file mode 100644
index 0000000..5f84a09
--- /dev/null
+++ b/SuiceExample/Assets/SuiceExample/Scripts/Platform/AndroidPlatformExample.cs
@@ -0,0 +1,19 @@
+using UnityEngine;
+
+namespace SuiceExample.Platform
+{
+#if UNITY_ANDROID
+ /// <summary>
+ /// Android platform example implementation
+ ///
+ /// @author DisTurBinG
+ /// </summary>
+ public class AndroidPlatformExample : IPlatformExample
+ {
+ public void RunPlatformTask()
+ {
+ Debug.Log("Running platform specific task for Android!");
+ }
+ }
+#endif
+}
diff --git a/SuiceExample/Assets/SuiceExample/Scripts/Platform/AndroidPlatformExample.cs.meta b/SuiceExample/Assets/SuiceExample/Scripts/Platform/AndroidPlatformExample.cs.meta
new file mode 100644
index 0000000..29731a5
--- /dev/null
+++ b/SuiceExample/Assets/SuiceExample/Scripts/Platform/AndroidPlatformExample.cs.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: b6cf0b4513fe9d441a632f8af23797da
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
diff --git a/SuiceExample/Assets/SuiceExample/Scripts/Platform/DefaultPlatformExample.cs b/SuiceExample/Assets/SuiceExample/Scripts/Platform/DefaultPlatformExample.cs
new file mode 100644
index 0000000..a66b703
--- /dev/null
+++ b/SuiceExample/Assets/SuiceExample/Scripts/Platform/DefaultPlatformExample.cs
@@ -0,0 +1,17 @@
+using UnityEngine;
+
+namespace SuiceExample.Platform
+{
+ /// <summary>
+ /// DefaultPlatform example implementation
+ ///
+ /// @author DisTurBinG
+ /// </summary>
+ public class DefaultPlatformExample : IPlatformExample
+ {
+ public void RunPlatformTask()
+ {
+ Debug.Log("Running platform specific task for DefaultPlatformExample!");
+ }
+ }
+}
diff --git a/SuiceExample/Assets/SuiceExample/Scripts/Platform/DefaultPlatformExample.cs.meta b/SuiceExample/Assets/SuiceExample/Scripts/Platform/DefaultPlatformExample.cs.meta
new file mode 100644
index 0000000..4c6de2b
--- /dev/null
+++ b/SuiceExample/Assets/SuiceExample/Scripts/Platform/DefaultPlatformExample.cs.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 5aa9fdfb9acb58c4885ffd87196411c1
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
diff --git a/SuiceExample/Assets/SuiceExample/Scripts/Platform/IPlatformExample.cs b/SuiceExample/Assets/SuiceExample/Scripts/Platform/IPlatformExample.cs
new file mode 100644
index 0000000..7a7c64a
--- /dev/null
+++ b/SuiceExample/Assets/SuiceExample/Scripts/Platform/IPlatformExample.cs
@@ -0,0 +1,13 @@
+namespace SuiceExample.Platform
+{
+ /// <summary>
+ /// An example of using suice for platform specific implementations.
+ /// Be sure to checkout the PlatformModule class on how it works!
+ ///
+ /// @author DisTurBinG
+ /// </summary>
+ public interface IPlatformExample
+ {
+ void RunPlatformTask();
+ }
+}
diff --git a/SuiceExample/Assets/SuiceExample/Scripts/Platform/IPlatformExample.cs.meta b/SuiceExample/Assets/SuiceExample/Scripts/Platform/IPlatformExample.cs.meta
new file mode 100644
index 0000000..faceb96
--- /dev/null
+++ b/SuiceExample/Assets/SuiceExample/Scripts/Platform/IPlatformExample.cs.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 6e25ea2f88af0ac47b5d9ea6d6f03e75
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
diff --git a/SuiceExample/Assets/SuiceExample/Scripts/Platform/PlatformExampleModule.cs b/SuiceExample/Assets/SuiceExample/Scripts/Platform/PlatformExampleModule.cs
new file mode 100644
index 0000000..353694d
--- /dev/null
+++ b/SuiceExample/Assets/SuiceExample/Scripts/Platform/PlatformExampleModule.cs
@@ -0,0 +1,20 @@
+using DTools.Suice;
+
+namespace SuiceExample.Platform
+{
+ public class PlatformExampleModule : AbstractModule
+ {
+ public override void Configure()
+ {
+#if UNITY_IOS
+ Bind<IPlatformExample>().To<iOSPlatformExample>().In(Scope.SINGLETON);
+
+#elif UNITY_ANDROID
+ Bind<IPlatformExample>().To<AndroidPlatformExample>().In(Scope.SINGLETON);
+
+#else
+ Bind<IPlatformExample>().To<DefaultPlatformExample>().In(Scope.SINGLETON);
+#endif
+ }
+ }
+}
diff --git a/SuiceExample/Assets/SuiceExample/Scripts/Platform/PlatformExampleModule.cs.meta b/SuiceExample/Assets/SuiceExample/Scripts/Platform/PlatformExampleModule.cs.meta
new file mode 100644
index 0000000..2b15fb0
--- /dev/null
+++ b/SuiceExample/Assets/SuiceExample/Scripts/Platform/PlatformExampleModule.cs.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: d72f4b18e7bfb66448311b17ae0de698
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
diff --git a/SuiceExample/Assets/SuiceExample/Scripts/Platform/PlatformTaskServiceExample.cs b/SuiceExample/Assets/SuiceExample/Scripts/Platform/PlatformTaskServiceExample.cs
new file mode 100644
index 0000000..0f1211b
--- /dev/null
+++ b/SuiceExample/Assets/SuiceExample/Scripts/Platform/PlatformTaskServiceExample.cs
@@ -0,0 +1,33 @@
+using DTools.Suice;
+using UnitySuiceCommons.EventDispatcher;
+using UnitySuiceCommons.EventDispatcher.Unity.UnityEvent;
+
+namespace SuiceExample.Platform
+{
+ /// <summary>
+ /// Example of what it would be like injecting a platform specific dependency.
+ ///
+ /// This example would better be used for in app purchases across multiple games, or even communication with native level DLLs.
+ ///
+ /// But for the same of time, we will just inject and call a simple debug statement.
+ ///
+ /// @author DisTurBinG
+ /// </summary>
+ [Singleton]
+ public class PlatformTaskServiceExample
+ {
+ private readonly IPlatformExample platformExample;
+
+ [Inject]
+ public PlatformTaskServiceExample(IPlatformExample platformExample)
+ {
+ this.platformExample = platformExample;
+ }
+
+ [EventListener]
+ public void OnStart(UnityStartEvent startEvent)
+ {
+ platformExample.RunPlatformTask();
+ }
+ }
+}
diff --git a/SuiceExample/Assets/SuiceExample/Scripts/Platform/PlatformTaskServiceExample.cs.meta b/SuiceExample/Assets/SuiceExample/Scripts/Platform/PlatformTaskServiceExample.cs.meta
new file mode 100644
index 0000000..a2c4127
--- /dev/null
+++ b/SuiceExample/Assets/SuiceExample/Scripts/Platform/PlatformTaskServiceExample.cs.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 55f0c99153f8c99449fcf96bddcd4be3
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
diff --git a/SuiceExample/Assets/SuiceExample/Scripts/Platform/iOSPlatformExample.cs b/SuiceExample/Assets/SuiceExample/Scripts/Platform/iOSPlatformExample.cs
new file mode 100644
index 0000000..8c3fb0c
--- /dev/null
+++ b/SuiceExample/Assets/SuiceExample/Scripts/Platform/iOSPlatformExample.cs
@@ -0,0 +1,19 @@
+using UnityEngine;
+
+namespace SuiceExample.Platform
+{
+#if UNITY_IOS
+ /// <summary>
+ /// iOS platform example implementation
+ ///
+ /// @author DisTurBinG
+ /// </summary>
+ public class iOSPlatformExample : IPlatformExample
+ {
+ public void RunPlatformTask()
+ {
+ Debug.Log("Running platform specific task for DefaultPlatformExample!");
+ }
+ }
+#endif
+}
diff --git a/SuiceExample/Assets/SuiceExample/Scripts/Platform/iOSPlatformExample.cs.meta b/SuiceExample/Assets/SuiceExample/Scripts/Platform/iOSPlatformExample.cs.meta
new file mode 100644
index 0000000..4d4c73f
--- /dev/null
+++ b/SuiceExample/Assets/SuiceExample/Scripts/Platform/iOSPlatformExample.cs.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 878a937ba86af484ea8be97ad923f41a
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData: