- Home /
Can I use platform-specific UIs
Short version: Is it possible to make separate UIs for each platform natively so that I can show real Windows Phone / iOS / Android UI elements while still using Unity?
Long Version: I started a project a few months ago where I was attempting to use a native UI for each of the mobile platforms and have the platform-specific code talk back and forth with the Unity code. I had this working in a Windows Universal App by modifying the main XAML and XAML.cs files. I mostly used UnityEngine to do the communication.
So now it has been a few months and it is no longer working. I get errors about not being able to call some of the UnityEngine methods on a non-main thread. I used a dispatcher to invoke my code on a UI thread and that still does not seem to be helping.
Is there a way that I can accomplish what I'm explaining? Like I mentioned, I did have this working for a Windows Universal App at some point, but something has changed. I did not do much with iOS or Android yet.
Edit: I am using a very similar method to what is described in the docs for communication between a Windows Phone 8 app and Unity. http://docs.unity3d.com/Manual/wp8-unity-interaction.html
Answer by Diet-Chugg · Jun 08, 2015 at 07:58 PM
You will find this quite handy: http://docs.unity3d.com/ScriptReference/RuntimePlatform.html
Make a script that is called DisableOnPlatformMismatch.cs
public class DisableOnPlatformMismatch : Monobehaviour
{
public RuntimePlatform runtimePlatform;
void OnEnable()
{
if(Application.platform != runtimePlatform)
gameObject.SetActive(false);
}
}
Make a UI for each platform and place this script on them all. Set the runtimeplatform to the corresponding match and you should be good to go.
The downside to this approach is all the versions of your UI will be included in the build which depending on the complexity of your UIs could cause longer load times. On the plus side you don't have to have multiple copies of your project with a different UI on it.
I'm sorry if my question wasn't clear enough, but I don't think that quite helps me accomplish what I am looking for. It seems like this will allow me to create different UIs for each platform in Unity. What I meant by "native" UI is a platform-specific UI built using that platform's tools.
For example, I want to create the UI in Visual Studio or Xcode and have that code talk to Unity. I have followed the example in the link at the bottom of my original post. This method used to work for me, but no longer does in a Windows Universal App. I did not try a similar solution for iOS or Android yet.