Skip to content

Instantly share code, notes, and snippets.

@JavadocMD
Created Jun 20, 2017
Embed
What would you like to do?
Use of a partial class to implement platform-specific logic in Unity.
namespace Login {
public static partial class Login {
// Call this from the outside to log in
public static void LogIn() {
DoLogIn();
}
// Implementation delegate
static partial void DoLogIn();
}
#if UNITY_IOS
public static partial class Login {
static partial void DoLogIn() {
// iOS login logic goes here...
}
}
#endif
#if UNITY_ANDROID
public static partial class Login {
static partial void DoLogIn() {
// Android login logic goes here...
}
}
#endif
}
@JavadocMD

This comment has been minimized.

Copy link
Owner Author

@JavadocMD JavadocMD commented Jun 20, 2017

The advantage to using partial classes is that it lets us split the platform-specific definitions into different files so you don't wind up with one unreadable monolith.

Note: the fact that this class is static is not necessary, and only done here for simplicity of demonstration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment