RPC Calls in Unity 3D / Photon Fusion 2

138 views Asked by At

I am attempting to connect multiple users together in a single Photon Fusion 2 room. Once they are connected, I would like any user to be able to select a button that represents another app to launch. Once they've selected an app though, I want everyone to be redirected to that app. I have the code below and it works perfectly for the one who selects the application, however, it doesn't do anything for anyone else. What am I missing here? I'm not sure I understand how RPC really works for Fusion 2. TIA.

Application uses Unity 3D with C# Operations on Photon Fusion 2 Executed through an APK on a VR headset

public void LaunchApp(string packageName)
    {
        RPC_LaunchApp(packageName);
    }

    [Rpc (RpcSources.All, RpcTargets.StateAuthority)]
    public void RPC_LaunchApp(string packageName)
    {
        Debug.Log("We are in the Launch App Method");
        bool fail = false;
        string bundleId = (string.IsNullOrEmpty(packageName) || packageName.ToUpper() == "TEST" ? Application.identifier : packageName).Trim();
        AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject ca = up.GetStatic<AndroidJavaObject>("currentActivity");
        AndroidJavaObject packageManager = ca.Call<AndroidJavaObject>("getPackageManager");

        AndroidJavaObject launchIntent = null;
        try
        {
            launchIntent = packageManager.Call<AndroidJavaObject>("getLaunchIntentForPackage", bundleId);
        }
        catch (System.Exception e)
        {
            Debug.Log(e);
            fail = true;
        }

        if (fail)
        {
            //open app in store
            Application.OpenURL("https://google.com");
        }
        else
        {
            //open the app
            ca.Call("startActivity", launchIntent);
        }

        up.Dispose();
        ca.Dispose();
        packageManager.Dispose();
        launchIntent.Dispose();
    }

I've attempted the code above and a few different versions of the RPC attribute so far.

1

There are 1 answers

0
Paweł Łęgowski On

Are you sure you need a RPC there? Your script is attached to a NetworkObject, so ONE of the Players (or server) has authority over it. And your RPC has RpcTarget set to StateAuthority, so basically whichever player uses LaunchApp method it invokes the RPC_LaunchApp on the player who has authority over that object. I suppose you might want the Authority/Host player to launch app for all players, in that case I would set Source and Target the opposite way in

[Rpc(RpcSources.StateAuthority, RpcTargets.All)]