public void Init() { FacebookLogger.Instance = new FacebookTestLogger(); Type type = this.GetType(); var callbackManager = new CallbackManager(); if (Attribute.GetCustomAttribute(type, typeof(AndroidTestAttribute)) != null) { var mockWrapper = new MockAndroid(); Constants.CurrentPlatform = FacebookUnityPlatform.Android; var facebook = new AndroidFacebook(mockWrapper, callbackManager); this.Mock = mockWrapper; this.Mock.Facebook = facebook; FB.FacebookImpl = facebook; } else if (Attribute.GetCustomAttribute(type, typeof(IOSTestAttribute)) != null) { var mockWrapper = new MockIOS(); Constants.CurrentPlatform = FacebookUnityPlatform.IOS; var facebook = new IOSFacebook(mockWrapper, callbackManager); this.Mock = mockWrapper; this.Mock.Facebook = facebook; FB.FacebookImpl = facebook; } else if (Attribute.GetCustomAttribute(type, typeof(GameroomTestAttribute)) != null) { var mockWrapper = new MockGameroom(); Constants.CurrentPlatform = FacebookUnityPlatform.Gameroom; var facebook = new GameroomFacebook(mockWrapper, callbackManager); this.Mock = mockWrapper; this.Mock.Facebook = facebook; FB.FacebookImpl = facebook; } else if (Attribute.GetCustomAttribute(type, typeof(CanvasTestAttribute)) != null) { var mockWrapper = new MockCanvas(); Constants.CurrentPlatform = FacebookUnityPlatform.WebGL; var facebook = new CanvasFacebook(mockWrapper, callbackManager); this.Mock = mockWrapper; this.Mock.Facebook = facebook; FB.FacebookImpl = facebook; } else if (Attribute.GetCustomAttribute(type, typeof(EditorTestAttribute)) != null) { var mockWrapper = new MockEditor(); // The editor works for all platforms but claim to be android for testing. Constants.CurrentPlatform = FacebookUnityPlatform.Android; var facebook = new EditorFacebook(mockWrapper, callbackManager); this.Mock = mockWrapper; this.Mock.Facebook = facebook; FB.FacebookImpl = facebook; } else { throw new Exception("Failed to specify platform specified on test class"); } this.OnInit(); }
private void OnGUIDialog(int windowId) { GUI.enabled = !this.isLoggingIn; GUILayout.Space(10f); GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.BeginVertical(new GUILayoutOption[0]); GUILayout.Space(10f); GUILayout.Label("User Access Token:", new GUILayoutOption[0]); GUILayout.EndVertical(); GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.MinWidth(400f) }; this.accessToken = GUILayout.TextField(this.accessToken, GUI.skin.textArea, options); GUILayout.EndHorizontal(); GUILayout.Space(20f); GUILayout.BeginHorizontal(new GUILayoutOption[0]); if (GUILayout.Button("Find Access Token", new GUILayoutOption[0])) { Application.OpenURL(string.Format("https://developers.facebook.com/tools/accesstoken/?app_id={0}", FB.AppId)); } GUILayout.FlexibleSpace(); GUIContent content = new GUIContent("Login"); if (GUI.Button(GUILayoutUtility.GetRect(content, GUI.skin.button), content)) { EditorFacebook component = FBComponentFactory.GetComponent <EditorFacebook>(IfNotExist.AddNew); component.AccessToken = this.accessToken; Dictionary <string, string> formData = new Dictionary <string, string>(); formData["batch"] = "[{\"method\":\"GET\", \"relative_url\":\"me?fields=id\"},{\"method\":\"GET\", \"relative_url\":\"app?fields=id\"}]"; formData["method"] = "POST"; formData["access_token"] = this.accessToken; FB.API("/", HttpMethod.GET, new FacebookDelegate(component.MockLoginCallback), formData); this.isLoggingIn = true; } GUI.enabled = true; GUIContent content2 = new GUIContent("Cancel"); Rect rect = GUILayoutUtility.GetRect(content2, this.greyButton); if (GUI.Button(rect, content2, this.greyButton)) { FBComponentFactory.GetComponent <EditorFacebook>(IfNotExist.AddNew).MockCancelledLoginCallback(); UnityEngine.Object.Destroy(this); } GUILayout.EndHorizontal(); if (Event.current.type == EventType.Repaint) { this.windowHeight = (rect.y + rect.height) + GUI.skin.window.padding.bottom; } }