2017-07-03 69 views
0

我有以下lib.jslib文件Pointer_stringify將返回亂碼

mergeInto(LibraryManager.library, { 
    IsGuestUser: function (objectName, objectMethodName) { 
    gamesmart.user.isGuest(function (result) { 
     console.log(Pointer_stringify(objectName), Pointer_stringify(objectMethodName), result); 
     gameSmartGameInstance.SendMessage(Pointer_stringify(objectName), Pointer_stringify(objectMethodName), result); 
    }); 
    } 
}); 

後者從這裏稱爲:

namespace GameSmart { 
    public class User : API { 
    [DllImport("__Internal")] 
    public static extern void IsGuestUser(string objectName, string objectMethodName); 

    public static void IsGuest(string objectName, string objectMethodName) { 
     IsGuestUser(objectName, objectMethodName); 
    } 
    } 
} 

,並開始像這樣:

public class Test : MonoBehaviour { 
    void Start() { 
    GameSmart.User.IsGuest("GameSmart", "OnIsGuest"); 
    } 
} 

正如所看到的上面我將GameSmartOnIsGuest傳遞給JavaScript,並且當它到達我在這兩個值上調用了Pointer_stringify()

當轉換並記錄下來,我得到下面的輸出:0Zހﳀ�我應該得到GameSmartOnIsGuest回去,但我沒有什麼原因造成這種情況?

回答

0

因此,對於這個修復是移動Pointer_stringify外的匿名函數的,所以它看起來是這樣的:

mergeInto(LibraryManager.library, { 
    IsGuestUser: function (objectName, objectMethodName) { 
    var jsObjectName = Pointer_stringify(objectName); 
    var jsObjectMethodName = Pointer_stringify(objectMethodName); 
    gamesmart.user.isGuest(function (result) { 
     gameSmartGameInstance.SendMessage(jsObjectName, jsObjectMethodName, result); 
    }); 
    } 
});