/// <summary> /// Starts the native service recognition. /// </summary> /// <param name="recognitionOptions">Recognition options.</param> /// <param name="recognitionListener">Recognition listener(MainScript).</param> public void StartRecognition(RecognitionOptions recognitionOptions, IRecognitionListener recognitionListener) { StopRecognition(); SyncMarkersWithFolder(); _recognitionRunning = true; _active = true; _currentRecognitionOptions = recognitionOptions; _recognitionListener = recognitionListener; _dataProvider = new RecognitionDataProvider(recognitionOptions.getCloudInfo(), this, GetDeviceId()); #if !UNITY_EDITOR if (!LoadSavedCameraParams()) { _dataProvider.ExecuteGetCameraParamFromServer(true); } #endif PikkartARCore.ChangeMode(_currentRecognitionOptions.getStorage() != RecognitionOptions.RecognitionStorage.LOCAL); PikkartARCore.StartRecognition(_currentRecognitionOptions.getStorage() != RecognitionOptions.RecognitionStorage.LOCAL, false); PikkartARCore.StartEffect(); _markerId = ""; if (_currentRecognitionOptions.getMode() == RecognitionOptions.RecognitionMode.TAP_TO_SCAN) { scheduleTimers(); } }
/// <summary> /// Initializes a new instance of the <see cref="PikkartAR.RecognitionManager"/> class. /// </summary> /// <param name="width">Frame Width.</param> /// <param name="height">Frame Height.</param> /// <param name="localRecognitionService">Object that implements the communication interface.</param> public RecognitionManager(IMarkerObjectListener markerObjectListener) { _markerObjectListener = markerObjectListener; _recognitionRunning = false; #if UNITY_ANDROID && !UNITY_EDITOR AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject context = jc.GetStatic <AndroidJavaObject>("currentActivity"); AndroidJavaObject assetManager = context.Call <AndroidJavaObject>("getAssets"); #endif _deviceId = RecognitionManager.GetDeviceId(); // Native Recognition Service Initialization if (!_nativeWrapperInitialized) { int res = PikkartARCore.InitRecognition( #if UNITY_ANDROID && !UNITY_EDITOR assetManager.GetRawObject(), #endif _localMarkerNotFoundEventMinIntervalMillisecs, #if UNITY_EDITOR_OSX || (UNITY_IOS && !UNITY_EDITOR_WIN) GetAppDataPath(), #else new StringBuilder(GetAppDataPath()), #endif #if UNITY_EDITOR_WIN new StringBuilder(Application.streamingAssetsPath), #if UNITY_5_6_OR_NEWER new StringBuilder(PlayerSettings.applicationIdentifier), #else new StringBuilder(PlayerSettings.bundleIdentifier), #endif #elif UNITY_EDITOR_OSX Application.streamingAssetsPath, #if UNITY_5_6_OR_NEWER PlayerSettings.applicationIdentifier, #else PlayerSettings.bundleIdentifier, #endif #endif Constants.PROCESS_WIDTH, Constants.PROCESS_HEIGHT, ScreenUtilities.GetScreenInches(), Constants.CAMERA_REQUESTED_WIDTH, Constants.CAMERA_REQUESTED_HEIGHT, false); if (res > 0) { _licenceChecked = true; } else { _licenceChecked = false; } if (res == 0) { #if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR if (MonoBehaviour.FindObjectOfType <LicenseMessage>() != null) { MonoBehaviour.FindObjectOfType <LicenseMessage>().gameObject.SetActive(true); } if (MonoBehaviour.FindObjectOfType <TrialMessage>() != null) { MonoBehaviour.FindObjectOfType <TrialMessage>().gameObject.SetActive(false); } #elif UNITY_EDITOR if (MonoBehaviour.FindObjectOfType <TrialMessage>() != null) { MonoBehaviour.FindObjectOfType <TrialMessage>().gameObject.SetActive(false); } if (MonoBehaviour.FindObjectOfType <LicenseMessage>() != null) { MonoBehaviour.FindObjectOfType <LicenseMessage>().gameObject.SetActive(false); } if (EditorUtility.DisplayDialog("Licence error!", "You cannot use our sdk without a valid licence UNLESS you are in a trial!\n" + "Please register to developer.pikkart.com to obtain your own licence or set your application identifier to 'com.pikkart.trial' to evaluate our SDK.", "Ok")) { EditorApplication.isPlaying = false; } #endif } else if (res == 1) { #if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR if (MonoBehaviour.FindObjectOfType <TrialMessage>()) { MonoBehaviour.FindObjectOfType <TrialMessage>().gameObject.SetActive(true); } if (MonoBehaviour.FindObjectOfType <LicenseMessage>()) { MonoBehaviour.FindObjectOfType <LicenseMessage>().gameObject.SetActive(false); } #elif UNITY_EDITOR if (MonoBehaviour.FindObjectOfType <TrialMessage>()) { MonoBehaviour.FindObjectOfType <TrialMessage>().gameObject.SetActive(false); } if (MonoBehaviour.FindObjectOfType <LicenseMessage>()) { MonoBehaviour.FindObjectOfType <LicenseMessage>().gameObject.SetActive(false); } if (EditorUtility.DisplayDialog("No valid license", "No valid license or running as com.pikkart.trial, press Ok to run in trial mode", "Ok")) { EditorApplication.isPlaying = true; } #endif } else { if (MonoBehaviour.FindObjectOfType <TrialMessage>()) { MonoBehaviour.FindObjectOfType <TrialMessage>().gameObject.SetActive(false); } if (MonoBehaviour.FindObjectOfType <LicenseMessage>()) { MonoBehaviour.FindObjectOfType <LicenseMessage>().gameObject.SetActive(false); } } PikkartARCore.SetProjectionMatrix(Constants.CAM_LARGE_FOV, Constants.CAM_SMALL_FOV); _nativeWrapperInitialized = true; //_nativeArray = Marshal.AllocHGlobal(Constants.BASE_RES_WIDTH * Constants.BASE_RES_HEIGHT * 3); } else { if (MonoBehaviour.FindObjectOfType <TrialMessage>()) { MonoBehaviour.FindObjectOfType <TrialMessage>().gameObject.SetActive(false); } if (MonoBehaviour.FindObjectOfType <LicenseMessage>()) { MonoBehaviour.FindObjectOfType <LicenseMessage>().gameObject.SetActive(false); } } _dataProvider = new RecognitionDataProvider(null, this, _deviceId); }