My project is for iPhone and PC/Web. The iPhoneKeyboard class is not define on PC/Web. Even though I can still run in the editor, it won’t let me build PC/Web version unless I remove iPhoneKeyboard.
What is the best way around this so that I don’t have to switch back and forth between two set of codes?
The second usable method is to use System.Diagnostics.ConditionalAttribute
[System.Diagnostics.Conditional("UNITY_IPHONE")]
public static void DoIPhoneThing()
{
//This only works on IPhone
}
[System.Diagnostics.Conditional("UNITY_EDITOR")]
public static void DoEditorThing()
{
//Only called if Editor exists
}
The Conditional attribute is interesting in that it will remove the Function declaration AND remove each individual call, meaning that if you don’t want the function you don’t actually have to #if define out each individual call to that function.
With Conditional you cannot use !, so I cannot say NOT Unity_Engine.
Overall I prefer it, as it can make sure I handle all platform specific stripping from the function declaration as opposed to scattered about the project in the function calls. But sometimes I have to do some preprocessor stuff at the top of that particular file
#if (!Unity_IPhone || Unity_Engine)
#define UseCalls
#endif
//Namespace and Class Declarations here:
[System.Diagnostics.Conditional("UseCalls")]
public static void DoNonIPhoneThing()
{
//These calls exist on all platforms but on Device on iPhone (iPhone editor will still use this)
}
C# defines within the scripts are per script, but it does mean for more complex conditionals you need an extra define to be able to use Conditional Properly.
But I still prefer it to having #if scattered all willy nilly around the code base, it’s just asking for one place to be forgotten.
This sounds exactly like what I am looking for but one newbie question!
What happens if I wish to run in the editor but use unity remote to control the input i.e. simulate iPhone play but without downloading too the iPhone. I hope that’s clear
How do I use conditionals for that??
i.e. in editor but ‘using’ remote (hence need iPhone input)…
Thanks for that. So what do I #define to get what I need? - I guess that’s what I am asking.
It can’t be #if UNITY_EDITOR and it can’t be #if UNITY_IPHONE (unless I guess the UNITY_EDITOR automatically takes input from remote if present…??
No-one else having these issues with Remote?. i.e. how to compile an ‘editor’ version but use remote as though it’s on a real iPhone.
Is there no way to do a build for this?, or at the very least in a script be able to detect the remote - then of course the script would be able to go into ‘iPhone’ input mode.
Otherwise it’s download to the real device each time which is a pain :-(((
Cheers
EDIT:
I guess the only solution is to #define USING_UNITY_REMOTE and recompile each time depending on where I wish to run in the editor (with no remote) or run in the editor but use remote as though a real iPhone input.
Will try