Created
June 20, 2017 23:33
-
-
Save JavadocMD/e4a29b9043e71fdf55e7c29a29a961be to your computer and use it in GitHub Desktop.
Use of a partial class to implement platform-specific logic in Unity.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.