2017-02-21 41 views
0

我在Unity中創建了一個回調,使我能夠將結果從Android應用程序發送回Unity應用程序。我更喜歡UnitySendMessage,因爲它更「清潔」。對Unity的回調爲空

我這裏使用的給出的精確eample:Callback Listener in Unity - How to call script file method from UnityPlayerActivity in Android

統一的C#代碼:

public class MoviePlayer : MonoBehaviour { 

// Use this for initialization 
void Awake() { 

    AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); 
    AndroidJavaObject activity = jc.GetStatic<AndroidJavaObject>("currentActivity"); 


    StartUpCallback startupCallback = new StartUpCallback(); 
    AndroidJavaObject control = new AndroidJavaObject("vrbridge.Control", activity); 
    //control.Call("startUp"); 
    control.Call("startUp", startupCallback); 

} 

class StartUpCallback: AndroidJavaProxy 
{ 
    public StartUpCallback() : base("vrbridge.StartUpCallback") { } 

    public void OnSuccess() { } 
    public void OnFailure() { } 
} 
} 

的Android代碼:

public class Control implements LibraryManagerInitStartDialogFragment.ConfigurationFragmentListener{ 

String TAG = "QuickPlayTest"; 


private Activity _activity; 
private StartUpCallback _startUpCallback; 

public Control(){ 
    Log.d(TAG, "Constructor."); 

} 

public Control(Activity activity){ 
    Log.d(TAG, "Constructor. Activity = " + activity); 
    _activity = activity; 
} 


public void startUp(StartUpCallback startUpCallback){ 
    Log.d(TAG, "startUp. Callback = " + startUpCallback); 
    _startUpCallback = startUpCallback; 
    new LibraryManagerInitStart(_activity, this); 
    Log.d(TAG, "startUp - end"); 
} 
} 

public interface StartUpCallback { 
    public void onSuccess(); 
    public void onFailure(); 
} 

出於某種原因,參數startUpCallback在啓動()總是空值。

我試着將它移到構造函數中,得到了相同的結果。 OTOH,活動的價值是好的。

我錯過了什麼嗎?

回答

0

也許問題是你的C#代理沒有正確實現Java接口。請注意「on/On」一詞中的大寫差異。