コード例 #1
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;
            }

            // Initialize plugin
            if (!_trackerPlugin.InitPlugin())
            {
                Debug.LogError("[KudanAR] Error initializing 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] Initializing Plugin Version {0} (Native Framework Version {1})", version, nativeVersion));

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

                _trackerPlugin.SetMarkerRecoveryStatus(_markerRecoveryMode);
                _trackerPlugin.SetMarkerExtensibilityStatus(_markerExtensibility);
                _trackerPlugin.SetMaximumSimultaneousTracking(_maxToTrack);

                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");
                }
            }
        }