Ejemplo n.º 1
0
        /// <summary>
        /// Method called when this behaviour is scheduled to be destroyed.
        /// OnDestroy will only be called on objects that have previously been active.
        /// </summary>
        void OnDestroy()
        {
            if (_trackerPlugin != null)
            {
                _trackerPlugin.StopInput();
                _trackerPlugin.DeinitPlugin();
                _trackerPlugin = null;
            }

            if (_lineMaterial != null)
            {
                Material.Destroy(_lineMaterial);
                _lineMaterial = null;
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Gets the appropriate tracker Plugin for the platform being used
 /// </summary>
 void GetPlugin()
 {
                 #if UNITY_EDITOR_OSX
     _trackerPlugin = new TrackerOSX();
     checkEditorLicenseKey();
     checkLicenseKeyValidity();
                 #elif UNITY_EDITOR_WIN
     _trackerPlugin = new TrackerWindows();
     checkEditorLicenseKey();
     checkLicenseKeyValidity();
                 #elif UNITY_IOS
     _trackerPlugin = new TrackeriOS(_background);
                 #elif UNITY_ANDROID
     _trackerPlugin = new TrackerAndroid(_background);
                 #endif
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Start is called only once on the frame the script is enabled.
        /// </summary>
        void Start()
        {
            CreateDebugLineMaterial();

            // Create the platform specific plugin interface
            _trackerPlugin = new Tracker(_background);

            if (_trackerPlugin == null)
            {
                Debug.LogError("[KudanAR] Failed to get tracker plugin");
                this.enabled = false;
                return;
            }

            // Initialise plugin
            if (!_trackerPlugin.InitPlugin())
            {
                Debug.LogError("[KudanAR] Error initialising plugin");
                this.enabled = false;
            }
            else
            {
                                #if UNITY_EDITOR
                // Check the Editor API Key and validity of the Native API Key
                if (!string.IsNullOrEmpty(_EditorAPIKey))
                {
                    checkEditorLicenseKey();
                }
                else
                {
                    Debug.LogError("Editor API Key field is Empty");
                }

                if (!string.IsNullOrEmpty(_APIKey))
                {
                    checkLicenseKeyValidity();
                }
                else
                {
                    Debug.LogWarning("API Key field is Empty");
                }
#else
                // Set the API key
                if (!string.IsNullOrEmpty(_APIKey))
                {
                    _trackerPlugin.SetApiKey(_APIKey, Application.identifier);
                }
                else
                {
                    Debug.LogError("API Key field is Empty");
                }
#endif

                // Print plugin version
                string version       = _trackerPlugin.GetPluginVersion();
                float  nativeVersion = _trackerPlugin.GetNativePluginVersion();
                Debug.Log(string.Format("[KudanAR] Initialising Plugin Version {0} (Native Framework Version {1})", version, nativeVersion));

                // Initialise all included tracking methods
                foreach (TrackingMethodBase method in _trackingMethods)
                {
                    method.Init();
                }

                _trackerPlugin.SetMarkerRecoveryStatus(_markerRecoveryMode);
                _trackerPlugin.SetMarkerAutoCropStatus(_markerAutoCrop);
                _trackerPlugin.SetMarkerExtensibilityStatus(_markerExtensibility);

                ChangeTrackingMethod(_defaultTrackingMethod);

                if (_trackerPlugin.GetNumCameras() > 0)
                {
                    // Start the camera
                    #if UNITY_EDITOR
                    if (_trackerPlugin.StartInputFromCamera(_playModeWebcamID, DefaultCameraWidth, DefaultCameraHeight))
                    #else
                    int cameraIndex = 0;

                    // As rear-facing cameras are always put first in the array on iOS and Android and front-facing cameras at the end, when wanting the front-facing camera, get the camera at the end of the array.
                    if (_useFrontFacingCameraOnMobile)
                    {
                        cameraIndex = _trackerPlugin.GetNumCameras() - 1;
                    }

                    if (_trackerPlugin.StartInputFromCamera(cameraIndex, DefaultCameraWidth, DefaultCameraHeight))
                    #endif
                    {
                        // Start tracking
                        if (_startOnEnable)
                        {
                            _trackerPlugin.StartTracking();
                        }
                    }
                    else
                    {
                        Debug.LogError("[KudanAR] Failed to start camera, is it already in use?");
                    }
                }
                else
                {
                    Debug.LogWarning("No Cameras Detected");
                }
            }
        }
Ejemplo n.º 4
0
        void Start()
        {
            // Check there is only a single instance of this component
            if (FindObjectsOfType <KudanTracker>().Length > 1)
            {
                Debug.LogError("[KudanAR] There should only be one instance of KudanTracker active at a time");
                return;
            }

            CreateDebugLineMaterial();

            // Create the platform specific plugin interface
#if KUDAN_DEVELOPMENT && (UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN)
            _trackerPlugin = new TrackerWindows();
#elif UNITY_ANDROID
            _trackerPlugin = new TrackerAndroid();
#elif UNITY_IOS
            _trackerPlugin = new TrackeriOS(_background);
            Application.targetFrameRate = 60;
#else
            Debug.LogWarning("[KudanAR] not supported on this platform");
#endif

            if (_trackerPlugin == null)
            {
                Debug.LogError("[KudanAR] Failed to initialise");
                this.enabled = false;
                return;
            }

            // Check licensing
            this.StartCoroutine("RunLicensing");

            // Initialise plugin
            if (!_trackerPlugin.InitPlugin())
            {
                Debug.LogError("[KudanAR] Error initialising plugin");
                this.enabled = false;
            }
            else
            {
                // Set the API key
                if (!string.IsNullOrEmpty(_apiKey))
                {
                    _trackerPlugin.SetApiKey(_apiKey, Application.bundleIdentifier);
                }
                else
                {
                    Debug.LogWarning("[KudanAR] No API key specified");
                }

                // Print plugin version
                float version       = _trackerPlugin.GetPluginVersion();
                float nativeVersion = _trackerPlugin.GetNativePluginVersion();
                Debug.Log(string.Format("[KudanAR] Initialising v{0} (native v{1})", version, nativeVersion));

                // Don't destroy this component between level loads
                if (_makePersistent)
                {
                    GameObject.DontDestroyOnLoad(this.gameObject);
                }

                foreach (TrackingMethodBase method in _trackingMethods)
                {
                    method.Init();
                }

                ChangeTrackingMethod(_defaultTrackingMethod);

                // Start the camera
                if (_trackerPlugin.StartInputFromCamera(0, DefaultCameraWidth, DefaultCameraHeight))
                {
                    // Start tracking
                    if (_startOnEnable)
                    {
                        _trackerPlugin.StartTracking();
                    }
                }
                else
                {
                    Debug.LogError("[KudanAR] Failed to start camera, is it already in use?");
                }
            }
        }