Skip to content

Instantly share code, notes, and snippets.

@JavadocMD
Created June 20, 2017 23:33
Show Gist options
  • Save JavadocMD/e4a29b9043e71fdf55e7c29a29a961be to your computer and use it in GitHub Desktop.
Save JavadocMD/e4a29b9043e71fdf55e7c29a29a961be to your computer and use it in GitHub Desktop.
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
Copy link
Author

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