我正在尝试制作一个Unity应用程序,firebase在其中向android和iOS发送通知。但我想在有人点击通知时打开一个特定的场景。我不知道该怎么做。
我想你正在寻找类似动态链接的东西——这里有另一个名为动态链接的firebase服务——https://firebase.google.com/docs/dynamic-links/unity/receive或者这里团结的深层联系https://docs.unity3d.com/Manual/enabling-deep-linking.html
var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
var currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
var intent = currentActivity.Call<AndroidJavaObject>("getIntent");
var extras = GetExtras(intent);
var sceneToLoad = GetProperty(extras, "<key to load in string>");
var currentScene = SceneManager.GetActiveScene();
GetExtras((函数
private static AndroidJavaObject GetExtras(AndroidJavaObject intent)
{
AndroidJavaObject extras = null;
try
{
extras = intent.Call<AndroidJavaObject>("getExtras");
}
catch (Exception e)
{
Debug.LogError("firebaseScript.GetExtras()->" + e.Message);
}
return extras;
}
GetProperty函数
private static string GetProperty(AndroidJavaObject extras, string name)
{
var s = string.Empty;
try
{
s = extras.Call<string>("getString", name);
}
catch (Exception e)
{
Debug.LogError("firebaseScript.GetProperty() throws ->" + e.Message);
}
return s;
}