Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Pass parameter in action

Discussion in 'Scripting' started by avicenteUnity1234, Aug 9, 2023.

  1. avicenteUnity1234

    avicenteUnity1234

    Joined:
    Jun 2, 2023
    Posts:
    7
    hi, i have this method:

    /// </summary>
    /// <param name="callback">The callback:
    /// * `0`: disconnect
    /// * `1`: connect
    /// * `2`: no microphone permission
    /// </param>
    /// <returns>
    /// * `0`: failure
    /// * `1`: success
    /// Returns `0` when there is no microphone permission.
    /// </returns>

    public static int PICOCastInit(Action<int> callback)
    {
    return PXR_EnterprisePlugin.UPxr_PICOCastInit(callback);
    }


    How could I pass the action parameter with the value 1,
    I tried this but it gives error :

    Action<int> initCast;
    PICOCastInit(initCast(1));

    Thanks
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,362
  3. avicenteUnity1234

    avicenteUnity1234

    Joined:
    Jun 2, 2023
    Posts:
    7
  4. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,362
    Ah, I think it is asking to use the Action itself as a parameter. Now you are initiating the action while passing it through.
    PICOCastInit(initCast); might work
     
  5. avicenteUnity1234

    avicenteUnity1234

    Joined:
    Jun 2, 2023
    Posts:
    7
    It works but the callback returns zero, that's why I was trying to send the action with the parameter 1
     
  6. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,362
    Check back on the documentation or ask on the pico dev forums
     
  7. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,495
    This doesn't make much sense. The callback gets an int value from the caller. So whoever actually invokes the callback is passing an int argument to your callback.

    A quick google search gave me this which is probably related to your code. As you can read in the documentation when the callback is called, it would pass a value of 0, 1 or 2 to your callback method. This is not an argument you specify. It's a value you get back.

    So you would do something like

    Code (CSharp):
    1. PICOCastInit(OnInitCast);
    2.  
    3.  
    4. // [ ... ]
    5.  
    6. void OnInitCast(int aState)
    7. {
    8.     Debug.Log("InitCast state: " + aState);
    9. }
    So a value of 0 would indicate that you're disconnected, a value of 1 indicates that you are connected and a value of 2 means it doesn't have permissions to use the mic. Again, this is a callback and that int value is a result value, not an argument that you have to specify.
     
    Lurking-Ninja and DevDunk like this.
  8. avicenteUnity1234

    avicenteUnity1234

    Joined:
    Jun 2, 2023
    Posts:
    7
    A ok ok, thanks.
    Thanks again to both of you for the help.