public void CreateWithMatchmakerUI(MatchRequest request, IRealTimeMultiplayerListener listener) { Util.NullArgumentTest(request); Util.NullArgumentTest(listener); if (mCurrentMatchmakerVC != null) { Debug.Log("Ignoring CreateWithMatchmakerUI call because another matchmaker UI is being shown."); return; } // Create a new GKMatchmakerViewController. var vc = InteropObjectFactory <GKMatchmakerViewController> .Create( () => { using (var gkReq = request.ToGKMatchRequest()) return(new GKMatchmakerViewController(gkReq)); }, viewController => { return(viewController.ToPointer()); }); // Create a delgate for the vc. vc.MatchmakerDelegate = new InternalGKMatchmakerViewControllerDelegateImpl(this, listener); // Store the VC ref. mCurrentMatchmakerVC = vc; // Now show the VC. using (var unityVC = UIViewController.UnityGetGLViewController()) unityVC.PresentViewController(vc, true, null); }
public void TakePicture(CameraType cameraType, Action <string, MediaResult> callback) { Util.NullArgumentTest(callback); if (mPickerController != null) { Debug.Log("Ignoring TakePicture call because another image picker UI is being shown."); return; } callback = RuntimeHelper.ToMainThread(callback); if (!IsCameraAvailable(cameraType)) { callback(cameraType.ToString() + " camera is not supported on this device.", null); return; } // Create a new image picker. var picker = InteropObjectFactory <UIImagePickerController> .Create( () => new UIImagePickerController(), c => c.ToPointer()); // Source type must be camera. picker.SourceType = UIImagePickerController.SourceTypeEnum.Camera; // Set camera type. picker.CameraDevice = cameraType == CameraType.Front ? UIImagePickerController.CameraDeviceEnum.Front : UIImagePickerController.CameraDeviceEnum.Rear; // Only allow image. NSMutableArray <NSString> mediaTypes = new NSMutableArray <NSString>(); mediaTypes.AddObject(UTTypeConstants.kUTTypeImage); picker.MediaTypes = mediaTypes; // Create a delegate for the TBM VC. picker.Delegate = new InternalUIImagePickerControllerDelegate(InternalUIImagePickerControllerDelegate.PickerOperation.TakePicture) { CloseAndResetVC = () => { if (mPickerController != null) { mPickerController.DismissViewController(true, null); mPickerController = null; } }, CompleteCallback = (error, result) => { callback(error, result); } }; // Store the VC ref. mPickerController = picker; // Now show the VC. using (var unityVC = UIViewController.UnityGetGLViewController()) unityVC.PresentViewController(picker, true, null); }
public void PickContact(Action <string, Contact> callback) { var picker = InteropObjectFactory <CNContactPickerViewController> .Create( () => new CNContactPickerViewController(), c => c.ToPointer()); picker.DisplayedPropertyKeys = GetPropertyKeys(); picker.Delegate = new iOSContactsPickerCallback(callback, picker); using (var unityVC = UIViewController.UnityGetGLViewController()) unityVC.PresentViewController(picker, true, null); }
public void Pick(Action <string, MediaResult[]> callback) { Util.NullArgumentTest(callback); if (mPickerController != null) { Debug.Log("Ignoring Pick call because another image picker UI is being shown."); return; } callback = RuntimeHelper.ToMainThread(callback); // Create a new image picker. var picker = InteropObjectFactory <UIImagePickerController> .Create( () => new UIImagePickerController(), c => c.ToPointer()); // Source type must be photo library. picker.SourceType = UIImagePickerController.SourceTypeEnum.PhotoLibrary; // Allow image & video. NSMutableArray <NSString> mediaTypes = new NSMutableArray <NSString>(); mediaTypes.AddObject(UTTypeConstants.kUTTypeImage); mediaTypes.AddObject(UTTypeConstants.kUTTypeMovie); picker.MediaTypes = mediaTypes; // Create a delegate for the TBM VC. picker.Delegate = new InternalUIImagePickerControllerDelegate(InternalUIImagePickerControllerDelegate.PickerOperation.PickGallery) { CloseAndResetMatchmakerVC = () => { if (mPickerController != null) { mPickerController.DismissViewController(true, null); mPickerController = null; } }, CompleteCallback = (error, result) => { callback(error, result != null ? new MediaResult[] { result } : null); } }; // Store the VC ref. mPickerController = picker; // Now show the VC. using (var unityVC = UIViewController.UnityGetGLViewController()) unityVC.PresentViewController(picker, true, null); }
public static GKMatchRequest ToGKMatchRequest(this MatchRequest matchRequest) { var gkRequest = InteropObjectFactory <GKMatchRequest> .Create( () => new GKMatchRequest(), req => req.ToPointer()); gkRequest.MinPlayers = matchRequest.MinPlayers; gkRequest.MaxPlayers = matchRequest.MaxPlayers; /* We're not using DefaultNumberOfPlayers. */ /* We're not using InviteMessage. */ gkRequest.PlayerGroup = matchRequest.Variant; // GameKit playerGroup is equivalent to variant gkRequest.PlayerAttributes = ~matchRequest.ExclusiveBitmask; // cross-platform API uses "1" bits to exclude, while GameKit uses "0" bits. return(gkRequest); }
public void AcceptInvitation(Invitation invitation, bool showWaitingRoomUI, IRealTimeMultiplayerListener listener) { Util.NullArgumentTest(invitation); Util.NullArgumentTest(listener); if (showWaitingRoomUI) { // Close the current matchmakerVC if any. if (mCurrentMatchmakerVC != null) { mCurrentMatchmakerVC.DismissViewController(true, null); mCurrentMatchmakerVC = null; } // Create a new GKMatchmakerViewController from the invitation. var vc = InteropObjectFactory <GKMatchmakerViewController> .Create( () => new GKMatchmakerViewController(invitation.GK_Invite), viewController => viewController.ToPointer() ); // Create a delgate for the vc. vc.MatchmakerDelegate = new InternalGKMatchmakerViewControllerDelegateImpl(this, listener); // Store the VC ref. mCurrentMatchmakerVC = vc; // Now show the VC. using (var unityVC = UIViewController.UnityGetGLViewController()) unityVC.PresentViewController(vc, true, null); } else { // Create a GKMatch from the invitation without any UI. GKMatchmaker.SharedMatchmaker().MatchForInvite(invitation.GK_Invite, (gkMatch, nsError) => { // If new match is created successfully, store it and the given listener. if (gkMatch != null) { SetupCurrentMatchAndListener(gkMatch, listener); } RuntimeHelper.RunOnMainThread(() => { ReportRoomSetupProgress(listener, gkMatch, nsError); }); }); } }
public void GetContacts(Action <string, Contact[]> callback) { if (isFetchingAllContacts) { callback(FetchingContactsThreadRunningMessage, null); return; } isFetchingAllContacts = true; new Thread(() => { try { List <Contact> result = new List <Contact>(); var contactStore = InteropObjectFactory <CNContactStore> .Create( () => new CNContactStore(), c => c.ToPointer()); CNContactFetchRequest request = CNContactFetchRequest.InitWithKeysToFetch(GetPropertyKeys()); request.SortOrder = CNContactSortOrder.CNContactSortOrderUserDefault; request.UnifyResults = true; NSError error = null; contactStore.EnumerateContactsWithFetchRequest(request, out error, (CNContact cnContact, out bool stop) => { stop = false; result.Add(cnContact.ToContact()); }); if (error != null && !string.IsNullOrEmpty(error.ToString())) { Debug.LogError(error.ToString()); } RuntimeHelper.RunOnMainThread(() => callback(null, result.ToArray())); } catch (Exception e) { Debug.LogError(e.Message); RuntimeHelper.RunOnMainThread(() => callback(e.Message, null)); } finally { isFetchingAllContacts = false; } }).Start(); }
private static ListenerForwarder CreateListenerForwarder() { // First create subforwarder. var inviteEventLF = InteropObjectFactory <GKInviteEventListenerForwarder> .Create( () => new GKInviteEventListenerForwarder(), fwd => fwd.ToPointer()); var tbEventLF = InteropObjectFactory <GKTurnBasedEventListenerForwarder> .Create( () => new GKTurnBasedEventListenerForwarder(), fwd => fwd.ToPointer()); // Now create and return main forwarder composited from subforwarders. return(InteropObjectFactory <ListenerForwarder> .Create( () => new ListenerForwarder(inviteEventLF, tbEventLF), fwd => fwd.ToPointer())); }
public void CreateWithMatchmakerUI(MatchRequest request, Action cancelCallback, Action <string> errorCallback) { Util.NullArgumentTest(request); if (mCurrentMatchmakerVC != null) { Debug.Log("Ignoring CreateWithMatchmakerUI call because another matchmaker UI is being shown."); return; } // Create a new TBM VC. var vc = InteropObjectFactory <GKTBMVC> .Create( () => { using (var gkReq = request.ToGKMatchRequest()) return(new GKTBMVC(gkReq)); }, viewController => { return(viewController.ToPointer()); }); // This VC is not showing existing matches. vc.ShowExistingMatches = false; // Create a delegate for the TBM VC. vc.TurnBasedMatchmakerDelegate = new InternalGKTBMVCDelegateImpl() { CancelCallback = cancelCallback, ErrorCallback = errorCallback, ResetMatchmakerVC = () => mCurrentMatchmakerVC = null }; // Store the VC ref. mCurrentMatchmakerVC = vc; // Now show the VC. using (var unityVC = UIViewController.UnityGetGLViewController()) unityVC.PresentViewController(vc, true, null); }
public void ShowMatchesUI() { if (mCurrentMatchmakerVC != null) { Debug.Log("Ignoring CreateWithMatchmakerUI call because another matchmaker UI is being shown."); return; } // Create a dummy request with the widest range of players possible. var gkRequest = new GKMatchRequest(); gkRequest.MinPlayers = 2; gkRequest.MaxPlayers = GKMatchRequest.MaxPlayersAllowedForMatchType(GKMatchRequest.GKMatchType.TurnBased); // Create a new TBM VC with the dummy request. var vc = InteropObjectFactory <GKTBMVC> .Create( () => new GKTBMVC(gkRequest), viewController => viewController.ToPointer()); // This VC should show existing matches. vc.ShowExistingMatches = true; // Create a delegate for the TBM VC with no callbacks. // The delegate is necessary so the VC can be closed. vc.TurnBasedMatchmakerDelegate = new InternalGKTBMVCDelegateImpl() { CancelCallback = null, ErrorCallback = null, ResetMatchmakerVC = () => mCurrentMatchmakerVC = null }; // Store the VC ref. mCurrentMatchmakerVC = vc; // Now show the VC. using (var unityVC = UIViewController.UnityGetGLViewController()) unityVC.PresentViewController(vc, true, null); }