diff --git a/Facebook.Unity.Canvas/CanvasJSWrapper.cs b/Facebook.Unity.Canvas/CanvasJSWrapper.cs index 49dfbcd7d..ccb8a35bc 100644 --- a/Facebook.Unity.Canvas/CanvasJSWrapper.cs +++ b/Facebook.Unity.Canvas/CanvasJSWrapper.cs @@ -46,7 +46,10 @@ public void Init(string connectFacebookUrl, string locale, int debug, string ini public void Login(IEnumerable scope, string callback_id) { - login(scope, callback_id); + var scopeList = new List(scope); + var scopeListJson = MiniJSON.Json.Serialize(scope); + + login(scopeListJson, callback_id); } public void Logout() { @@ -58,7 +61,10 @@ public void ActivateApp() { } public void LogAppEvent(string eventName, float? valueToSum, string parameters) { - logAppEvent(eventName, valueToSum, parameters); + if (valueToSum.HasValue) + logAppEvent(eventName, valueToSum.Value, parameters); + else + logAppEventWithoutValue(eventName, parameters); } public void LogPurchase(float purchaseAmount, string currency, string parameters) { @@ -77,7 +83,7 @@ public void InitScreenPosition() { private static extern void init(string connectFacebookUrl, string locale, int debug, string initParams, int status); [DllImport("__Internal")] - private static extern void login(IEnumerable scope, string callback_id); + private static extern void login(string scope, string callback_id); [DllImport("__Internal")] private static extern void logout(); @@ -86,7 +92,10 @@ public void InitScreenPosition() { private static extern void activateApp(); [DllImport("__Internal")] - private static extern void logAppEvent(string eventName, float? valueToSum, string parameters); + private static extern void logAppEvent(string eventName, float valueToSum, string parameters); + + [DllImport("__Internal")] + private static extern void logAppEventWithoutValue(string eventName, string parameters); [DllImport("__Internal")] private static extern void logPurchase(float purchaseAmount, string currency, string parameters); diff --git a/Facebook.Unity.Canvas/Plugins/CanvasJSSDKBindings.jslib b/Facebook.Unity.Canvas/Plugins/CanvasJSSDKBindings.jslib index 8b3ba9933..2dd722c05 100644 --- a/Facebook.Unity.Canvas/Plugins/CanvasJSSDKBindings.jslib +++ b/Facebook.Unity.Canvas/Plugins/CanvasJSSDKBindings.jslib @@ -18,198 +18,259 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -var FBUnity = { - init: function(connectFacebookUrl, locale, debug, initParams, status) { - // make element for js sdk - if(!document.getElementById('fb-root')) { - var fbroot = document.createElement('div'); - fbroot.id = 'fb-root'; - var body = document.getElementsByTagName('body')[0]; - body.insertBefore(fbroot, body.children[0]); - } +var FBUnityLib = { + $FBUnity: { + init: function(connectFacebookUrl, locale, debug, initParams, status) { + // make element for js sdk + if (!document.getElementById('fb-root')) { + var fbroot = document.createElement('div'); + fbroot.id = 'fb-root'; + var body = document.getElementsByTagName('body')[0]; + body.insertBefore(fbroot, body.children[0]); + } - // load js sdk - var js, id = 'facebook-jssdk', ref = document.getElementsByTagName('script')[0]; - if (document.getElementById(id)) {return;} - js = document.createElement('script'); js.id = id; js.async = true; - js.src = connectFacebookUrl + '/' + locale + '/sdk' + (debug ? '/debug' : '') + '.js'; - ref.parentNode.insertBefore(js, ref); - // once jssdk is loaded, init - window.fbAsyncInit = function () { - initParams = JSON.parse(initParams); - initParams.hideFlashCallback = FBUnity.onHideUnity; - FB.init(initParams); - // send url to unity - needed for deep linking - FBUnity.sendMessage('OnUrlResponse', location.href); - if (status) { - FBUnity.onInitWithStatus(); - } else { + // load js sdk + var js, id = 'facebook-jssdk', ref = document.getElementsByTagName('script')[0]; + if (document.getElementById(id)) {return;} + js = document.createElement('script'); js.id = id; js.async = true; + js.src = connectFacebookUrl + '/' + locale + '/sdk' + (debug ? '/debug' : '') + '.js'; + ref.parentNode.insertBefore(js, ref); + // once jssdk is loaded, init + window.fbAsyncInit = function() { + initParams = JSON.parse(initParams); + initParams.hideFlashCallback = FBUnity.onHideUnity; + FB.init(initParams); + // send url to unity - needed for deep linking + FBUnity.sendMessage('OnUrlResponse', location.href); + if (status) { + FBUnity.onInitWithStatus(); + } else { + FBUnity.onInit(); + } + }; + }, + + initScreenPosition: function() { + if (!screenPosition) { + var body = document.getElementsByTagName('body')[0]; + var screenPosition = {omo : body.onmouseover || function(){}, iframeX: 0, iframeY: 0}; + body.onmouseover = function(e) { + // Distance from top of screen to top of client area + screenPosition.iframeX = e.screenX - e.clientX; + screenPosition.iframeY = e.screenY - e.clientY; + + screenPosition.omo(e); + } + } + }, + + sendMessage: function(method, param) { + SendMessage('FacebookJsBridge', method, param); + }, + + login: function(scope, callback_id) { + FB.login(FBUnity.loginCallback.bind(null, callback_id), scope ? {scope: scope, auth_type: 'rerequest', return_scopes: true} : {return_scopes: true}); + }, + + loginCallback: function(callback_id, response) { + response = {'callback_id': callback_id, 'response': response}; + FBUnity.sendMessage('OnLoginComplete', JSON.stringify(response)); + }, + + onInitWithStatus: function() { + var timeoutHandler = setTimeout(function() { requestFailed(); }, 3000); + + function requestFailed() { FBUnity.onInit(); } - }; - }, - initScreenPosition: function() { - if (!screenPosition) { - var body = document.getElementsByTagName('body')[0]; - var screenPosition = {omo : body.onmouseover || function(){}, iframeX: 0, iframeY: 0}; - body.onmouseover = function(e) { - // Distance from top of screen to top of client area - screenPosition.iframeX = e.screenX - e.clientX; - screenPosition.iframeY = e.screenY - e.clientY; - - screenPosition.omo(e); + // try to get the login status right after init'ing + FB.getLoginStatus(function(response) { + clearTimeout(timeoutHandler); + FBUnity.onInit(response); + }); + }, + + onInit: function(response) { + var jsonResponse = ''; + if (response && response.authResponse) { + jsonResponse = JSON.stringify(response); } - } - }, - sendMessage: function(method, param) { - SendMessage('FacebookJsBridge', method, param); - }, - - login: function(scope, callback_id) { - FB.login(FBUnity.loginCallback.bind(null, callback_id), scope ? {scope: scope, auth_type: 'rerequest', return_scopes: true} : {return_scopes: true}); - }, - - loginCallback: function(callback_id, response) { - response = {'callback_id': callback_id, 'response': response}; - FBUnity.sendMessage('OnLoginComplete', JSON.stringify(response)); - }, - - onInitWithStatus: function() { - var timeoutHandler = setTimeout(function() { requestFailed(); }, 3000); + FBUnity.sendMessage('OnInitComplete', jsonResponse); + FB.Event.subscribe('auth.authResponseChange', function(r){ FBUnity.onAuthResponseChange(r) }); - function requestFailed() { - FBUnity.onInit(); - } + FBUnity.logLoadingTime(response); + }, - // try to get the login status right after init'ing - FB.getLoginStatus(function(response) { - clearTimeout(timeoutHandler); - FBUnity.onInit(response); - }); - }, + logLoadingTime: function(response) { + FB.Canvas.setDoneLoading( + function(result) { + // send implicitly event to log the time from the canvas pages load to facebook init being called. + FBUnity.logAppEvent('fb_canvas_time_till_init_complete', result.time_delta_ms / 1000, null); + } + ); + }, - onInit: function(response) { - var jsonResponse = ''; - if(response && response.authResponse) { - jsonResponse = JSON.stringify(response); - } - - FBUnity.sendMessage('OnInitComplete', jsonResponse); - FB.Event.subscribe('auth.authResponseChange', function(r){ FBUnity.onAuthResponseChange(r) }); + onAuthResponseChange: function(response) { + FBUnity.sendMessage('OnFacebookAuthResponseChange', response ? JSON.stringify(response) : ''); + }, - FBUnity.logLoadingTime(response); - }, + apiCallback: function(query, response) { + response = {'query': query, 'response': response}; + FBUnity.sendMessage('OnFacebookAPIResponse', JSON.stringify(response)); + }, - logLoadingTime: function(response) { - FB.Canvas.setDoneLoading( - function (result) { - // send implicitly event to log the time from the canvas pages load to facebook init being called. - FBUnity.logAppEvent('fb_canvas_time_till_init_complete', result.time_delta_ms / 1000, null); - } - ); - }, + api: function(query) { + FB.api(query, FBUnity.apiCallback.bind(null, query)); + }, + + activateApp: function() { + FB.AppEvents.activateApp(); + }, + + uiCallback: function(uid, callbackMethodName, response) { + response = {'callback_id': uid, 'response': response}; + FBUnity.sendMessage(callbackMethodName, JSON.stringify(response)); + }, + + logout: function() { + FB.logout(); + }, + + logAppEvent: function(eventName, valueToSum, parameters) { + FB.AppEvents.logEvent( + eventName, + valueToSum, + JSON.parse(parameters) + ); + }, + + logPurchase: function(purchaseAmount, currency, parameters) { + FB.AppEvents.logPurchase( + purchaseAmount, + currency, + JSON.parse(parameters) + ); + }, - onAuthResponseChange: function(response) { - FBUnity.sendMessage('OnFacebookAuthResponseChange', response ? JSON.stringify(response) : ''); + ui: function(x, uid, callbackMethodName) { + x = JSON.parse(x); + FB.ui(x, FBUnity.uiCallback.bind(null, uid, callbackMethodName)); + }, + + + hideUnity: function(direction) { + direction = direction || 'hide'; + //TODO support this for webgl + var unityDiv = jQuery(u.getUnity()); + + if (direction == 'hide') { + FBUnity.sendMessage('OnFacebookFocus', 'hide'); + } else /*show*/ { + FBUnity.sendMessage('OnFacebookFocus', 'show'); + + if (FBUnity.showScreenshotBackground.savedBackground) { + /* + if(fbShowScreenshotBackground.savedBackground == 'sentinel') { + jQuery('body').css('background', null); + } else { + jQuery('body').css('background', fbShowScreenshotBackground.savedBackground); + } + */ + } + + hideUnity.savedCSS = FBUnity.showScreenshotBackground.savedBackground = null; + } + }, + + showScreenshotBackground: function(pngbytes) /*and hide unity*/ { + // window.screenxX and window.screenY = browser position + // window.screen.height and window.screen.width = screen size + // findPos, above, locates the iframe within the browser + /* + if (!fbShowScreenshotBackground.savedBackground) + fbShowScreenshotBackground.savedBackground = jQuery('body').css('background') || 'sentinel'; + + jQuery('body').css('background-image', 'url(data:image/png;base64,'+pngbytes+')'); + jQuery('body').css( + 'background-position', + -(screenPosition.iframeX)+'px '+ + -(screenPosition.iframeY)+'px' + ); + jQuery('body').css('background-size', '100%'); + jquery('body').css('background-repeat', 'no-repeat'); + // TODO: Zoom detection + */ + }, + + onHideUnity: function(info) { + if (info.state == 'opened') { + FBUnity.sendMessage('OnFacebookFocus', 'hide'); + } else { + FBUnity.sendMessage('OnFacebookFocus', 'show'); + } + } }, - apiCallback: function(query, response) { - response = {'query': query, 'response': response}; - FBUnity.sendMessage('OnFacebookAPIResponse', JSON.stringify(response)); + init: function(connectFacebookUrl, locale, debug, initParams, status) { + var connectFacebookUrlString = Pointer_stringify(connectFacebookUrl); + var localeString = Pointer_stringify(locale); + var initParamsString = Pointer_stringify(initParams); + + FBUnity.init(connectFacebookUrlString, localeString, debug, initParamsString, status); }, - api: function(query) { - FB.api(query, FBUnity.apiCallback.bind(null , query)); + initScreenPosition: function() { + FBUnity.initScreenPosition(); }, - activateApp: function() { - FB.AppEvents.activateApp(); + login: function(scope, callback_id) { + var scopeString = Pointer_stringify(scope); + var scopeArray = JSON.parse(scopeString); + + var callback_idString = Pointer_stringify(callback_id); + + FBUnity.login(scopeArray, callback_idString); }, - uiCallback: function(uid, callbackMethodName, response) { - response = {'callback_id': uid, 'response': response}; - FBUnity.sendMessage(callbackMethodName, JSON.stringify(response)); + activateApp: function() { + FBUnity.activateApp(); }, logout: function() { - FB.logout(); + FBUnity.logout(); }, logAppEvent: function(eventName, valueToSum, parameters) { - FB.AppEvents.logEvent( - eventName, - valueToSum, - JSON.parse(parameters) - ); - }, + var eventNameString = Pointer_stringify(eventName); + var parametersString = Pointer_stringify(parameters); - logPurchase: function(purchaseAmount, currency, parameters) { - FB.AppEvents.logPurchase( - purchaseAmount, - currency, - JSON.parse(parameters) - ); + FBUnity.logAppEvent(eventNameString, valueToSum, parametersString); }, - ui: function(x, uid, callbackMethodName) { - x = JSON.parse(x); - FB.ui(x, FBUnity.uiCallback.bind(null, uid, callbackMethodName)); + logAppEventWithoutValue: function(eventName, parameters) { + var eventNameString = Pointer_stringify(eventName); + var parametersString = Pointer_stringify(parameters); + + FBUnity.logAppEvent(eventNameString, null, parametersString); }, - - hideUnity: function(direction) { - direction = direction || 'hide'; - //TODO support this for webgl - var unityDiv = jQuery(u.getUnity()); - - if(direction == 'hide') { - FBUnity.sendMessage('OnFacebookFocus', 'hide'); - } else /*show*/ { - FBUnity.sendMessage('OnFacebookFocus', 'show'); - - if (FBUnity.showScreenshotBackground.savedBackground) { - /* - if(fbShowScreenshotBackground.savedBackground == 'sentinel') { - jQuery('body').css('background', null); - } else { - jQuery('body').css('background', fbShowScreenshotBackground.savedBackground); - } - */ - } + logPurchase: function(purchaseAmount, currency, parameters) { + var currencyString = Pointer_stringify(currency); + var parametersString = Pointer_stringify(parameters); - hideUnity.savedCSS = FBUnity.showScreenshotBackground.savedBackground = null; - } + FBUnity.logPurchase(purchaseAmount, currencyString, parametersString); }, - - showScreenshotBackground: function(pngbytes) /*and hide unity*/ { - // window.screenxX and window.screenY = browser position - // window.screen.height and window.screen.width = screen size - // findPos, above, locates the iframe within the browser - /* - if (!fbShowScreenshotBackground.savedBackground) - fbShowScreenshotBackground.savedBackground = jQuery('body').css('background') || 'sentinel'; - - jQuery('body').css('background-image', 'url(data:image/png;base64,'+pngbytes+')'); - jQuery('body').css( - 'background-position', - -(screenPosition.iframeX)+'px '+ - -(screenPosition.iframeY)+'px' - ); - jQuery('body').css('background-size', '100%'); - jquery('body').css('background-repeat', 'no-repeat'); - // TODO: Zoom detection - */ - }, - - onHideUnity: function(info) { - if(info.state == 'opened') { - FBUnity.sendMessage('OnFacebookFocus', 'hide'); - } else { - FBUnity.sendMessage('OnFacebookFocus', 'show'); - } + + ui: function(x, uid, callbackMethodName) { + var xString = Pointer_stringify(x); + var uidString = Pointer_stringify(uid); + var callbackMethodNameString = Pointer_stringify(callbackMethodName); + + FBUnity.ui(xString, uidString, callbackMethodNameString); } }; -mergeInto(LibraryManager.library, FBUnity); \ No newline at end of file +autoAddDeps(LibraryManager.library, '$FBUnity'); +mergeInto(LibraryManager.library, FBUnityLib); diff --git a/UnitySDK/Assets/FacebookSDK/link.xml b/UnitySDK/Assets/FacebookSDK/link.xml index a0e2e3d89..e1b30dc19 100644 --- a/UnitySDK/Assets/FacebookSDK/link.xml +++ b/UnitySDK/Assets/FacebookSDK/link.xml @@ -5,4 +5,7 @@ + + + diff --git a/scripts/build.sh b/scripts/build.sh index aac4c9148..fae7694be 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -67,6 +67,9 @@ GAMEROOM_NAMED_PIPE_DLL=$GAMEROOM_ROOT/bin/Release/FacebookNamedPipeClient.dll EDITOR_ROOT=$PROJECT_ROOT/Facebook.Unity.Editor EDITOR_DLL=$EDITOR_ROOT/bin/Release/Facebook.Unity.Editor.dll +CANVAS_ROOT=$PROJECT_ROOT/Facebook.Unity.Canvas +CANVAS_DLL=$CANVAS_ROOT/bin/Release/Facebook.Unity.Canvas.dll + IOS_ROOT=$PROJECT_ROOT/Facebook.Unity.IOS IOS_DLL=$IOS_ROOT/bin/Release/Facebook.Unity.IOS.dll @@ -129,6 +132,11 @@ if [ ! -d "$UNITY_EDITOR_PLUGIN" ]; then fi cp $EDITOR_DLL $UNITY_EDITOR_PLUGIN || die "Failed to copy Editor DLL" +if [ ! -d "$UNITY_CANVAS_PLUGIN" ]; then + mkdir -p $UNITY_CANVAS_PLUGIN || die "Failed to create Canvas plugins folder" +fi +cp $CANVAS_DLL $UNITY_CANVAS_PLUGIN || die "Failed to copy Canvas DLL" + if [ ! -d "$UNITY_IOS_PLUGIN" ]; then mkdir -p $UNITY_IOS_PLUGIN || die "Failed to create IOS plugins folder" fi diff --git a/scripts/common.sh b/scripts/common.sh index d6766b297..eaa08bf60 100755 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -30,6 +30,7 @@ UNITY_PACKAGE_PLUGIN=$UNITY_PACKAGE_ROOT/Assets/FacebookSDK/Plugins/ UNITY_ANDROID_PLUGIN=$UNITY_PACKAGE_PLUGIN/Android/ UNITY_GAMEROOM_PLUGIN=$UNITY_PACKAGE_PLUGIN/Gameroom/ UNITY_EDITOR_PLUGIN=$UNITY_PACKAGE_PLUGIN/Editor/ +UNITY_CANVAS_PLUGIN=$UNITY_PACKAGE_PLUGIN/Canvas/ UNITY_IOS_PLUGIN=$UNITY_PACKAGE_PLUGIN/iOS/ UNITY_SETTINGS_PLUGIN=$UNITY_PACKAGE_PLUGIN/Settings/