/**
         * Use this for initialization.
         */
        private void Start()
        {
            // Variable initialization
            this.ReadyToStartRecognition     = false;
            this.initFinished                = false;
            this.dataLoadingFinished         = false;
            this.objectRecognitionConfigured = false;
            this.openMenu = false;

            // Get reference to other scripts in the scene
            this.dataLoader        = DataLoader.Instance;
            this.config            = IPConfig.Instance;
            this.objectRecognition = ObjectRecognition.Instance;
            this.infoCanvas        = InfoCanvas.Instance;

            // Check references
            if ((this.dataLoader == null) || (this.config == null) || (this.objectRecognition == null) || (this.text == null) ||
                (this.cursor == null) || (this.mainMenu == null) || (this.infoCanvas == null))
            {
                Debug.Log("Initializer: Script references not set properly.");
                this.enabled = false;
            }
        }
Beispiel #2
0
        /**
         * Use this for initialization.
         */
        private void Start()
        {
            // Variable initialization
            this.Artworks = new Dictionary <int, Artwork>();
            this.Artists  = new Dictionary <int, Artist>();
            this.Videos   = new Dictionary <int, Video>();
            this.Audio    = new Dictionary <int, Audio>();
            this.NeedsManualConfiguration = false;
            this.DataLoadingFinished      = false;
            this.ArtistPath      = "";
            this.ArtworkPath     = "";
            this.VideoPath       = "";
            this.AudioPath       = "";
            this.JsonPath        = "";
            this.config          = IPConfig.Instance;
            this.logger          = DebugLogger.Instance;
            this.timestamp       = 0;
            this.loadDataCounter = 0;
            this.protocolString  = (this.protocol == Protocol.HTTP) ? "http://" : "https:://";

            // Deactivate this script if necessary components are missing
            if ((this.config == null) || (this.logger == null))
            {
                Debug.LogError("DataLoader: Script references not set properly.");
                this.enabled = false;
                return;
            }

#if ENABLE_WINMD_SUPPORT
            // Set necessary data paths
            Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
            this.ArtistPath  = localFolder.Path + PATH_SEPARATOR + ARTIST_DIRECTORY;
            this.ArtworkPath = localFolder.Path + PATH_SEPARATOR + ARTWORK_DIRECTORY;
            this.VideoPath   = localFolder.Path + PATH_SEPARATOR + VIDEO_DIRECTORY;
            this.AudioPath   = localFolder.Path + PATH_SEPARATOR + AUDIO_DIRECTORY;
            this.JsonPath    = localFolder.Path + PATH_SEPARATOR + JSON_FILE;

            // Create image directories (if they do not already exist)
            System.IO.Directory.CreateDirectory(this.ArtistPath);
            System.IO.Directory.CreateDirectory(this.ArtworkPath);
            System.IO.Directory.CreateDirectory(this.VideoPath);
            System.IO.Directory.CreateDirectory(this.AudioPath);

            // Read current data file
            this.logger.Log("Read current data file.");
            if (System.IO.File.Exists(this.JsonPath))
            {
                string        json = System.IO.File.ReadAllText(this.JsonPath);
                CompanionData data = JsonUtility.FromJson <CompanionData>(json);

                // Save current timestamp
                this.timestamp = data.timestamp;

                // Load artists
                foreach (Artist artist in data.artists)
                {
                    artist.localImagePath = this.ArtistPath + PATH_SEPARATOR + ARTIST_IMAGE_PREFIX + artist.artistID + IMAGE_FORMAT;
                    this.Artists.Add(artist.artistID, artist);
                }

                // Load artworks
                foreach (Artwork artwork in data.artworks)
                {
                    artwork.localImagePath = this.ArtworkPath + PATH_SEPARATOR + ARTWORK_IMAGE_PREFIX + artwork.artworkID + IMAGE_FORMAT;
                    this.Artworks.Add(artwork.artworkID, artwork);
                }

                // Load videos
                foreach (Video video in data.videos)
                {
                    video.localVideoPath = this.VideoPath + PATH_SEPARATOR + VIDEO_PREFIX + video.videoID + VIDEO_FORMAT;
                    video.localImagePath = this.VideoPath + PATH_SEPARATOR + VIDEO_PREFIX + video.videoID + IMAGE_FORMAT;
                    this.Videos.Add(video.videoID, video);
                }

                // Load audio
                foreach (Audio audio in data.audio)
                {
                    audio.localAudioPath = this.AudioPath + PATH_SEPARATOR + AUDIO_PREFIX + audio.audioID + AUDIO_FORMAT;
                    this.Audio.Add(audio.audioID, audio);
                }
            }
            else
            {
                this.logger.Log("No current data present.");
            }

            // Load server data
            this.logger.Log("Load new data.");
            this.loadDataCounter++;
            try {
                WWW request = new WWW(this.protocolString + this.host + ":" + this.port.ToString() + this.path);
                StartCoroutine(this.WaitForWWW(WebRequestFormat.Json, request));
            } catch (System.Exception ex) {
                this.logger.Log(ex.Message);
            }
#endif
        }