Пример #1
0
        /// <summary>
        /// Plays the trailer
        /// </summary>
        /// <param name="showVideoControls">If set to <c>true</c> show video controls.</param>
        public IEnumerator PlayTrailer(bool showVideoControls = false)
        {
            StreamingAssetsStorage storage = new StreamingAssetsStorage(Game.ForceVision, null);
            string introVideoPath          = "";

            //copying to persistent data may work, you can also try prefixing the path with "jar://"
                        #if UNITY_ANDROID
            PersistentDataStorage persistentStorage = new PersistentDataStorage(Game.ForceVision);

            if (persistentStorage.FileExists(StarWarsIntroVideo) == false)
            {
                storage.LoadStreamingAssetsFile(StarWarsIntroVideo, (string error, byte[] bytes) =>
                {
                    if (string.IsNullOrEmpty(error))
                    {
                        //save file in persistentdata
                        bool writeSuccess = persistentStorage.SaveBytes(StarWarsIntroVideo, bytes);
                        if (writeSuccess)
                        {
                            introVideoPath = persistentStorage.GetPersistentDataPath(StarWarsIntroVideo);
                        }
                        else
                        {
                            //handle error
                            Log.Error("Error! Unable to save the video file to persistent data.");
                        }
                    }
                    else
                    {
                        //handle error
                        Log.Error("Error! Unable to load from streaming assets.");
                    }
                }, true);
            }
            else
            {
                introVideoPath = persistentStorage.GetPersistentDataPath(StarWarsIntroVideo);
            }
                        #else
            introVideoPath = storage.GetStreamingAssetPath(StarWarsIntroVideo);
                        #endif

            // checking that path is valid string
            if (!string.IsNullOrEmpty(introVideoPath))
            {
                if (PlayCount > 0)
                {
                    // setting button state
                    if (TrailerPlayButton)
                    {
                        TrailerPlayButton.interactable = false;
                    }

                    // stopping background music
                    AudioEvent.Play(AudioEventName.Ftue.Stereo.BackgroundMusicPause, gameObject);
                }

                if (Application.isEditor)
                {
                    Debug.Log("Playing Trailer (Trailer cannot play in Editor)");
                }
                else
                {
                    // playing intro video
                    Handheld.PlayFullScreenMovie(introVideoPath,
                                                 Color.black,
                                                 showVideoControls ? FullScreenMovieControlMode.CancelOnInput : FullScreenMovieControlMode.Hidden);
                }

                // adding pause
                yield return(new WaitForSeconds(1.5f));

                if (PlayCount > 0)
                {
                    // setting button state
                    if (TrailerPlayButton)
                    {
                        TrailerPlayButton.interactable = true;
                    }

                    // starting background music
                    AudioEvent.Play(AudioEventName.Ftue.Stereo.BackgroundMusicResume, gameObject);
                }

                // setting new play count
                StereoStorage.SetPrefInt(IntroPlayedCountKey, PlayCount + 1);
            }
        }
Пример #2
0
        /// <summary>
        /// Raises the download event.
        /// </summary>
        /// <param name="res">Res.</param>
        private void OnDownload(Response res)
        {
            if (isCancel == true)
            {
                return;
            }
            Log.Debug("[DEBUG-AUTH] AppController OnDownload " + res.ID + "  HTTPStatusCode: " + res.HttpStatusCode, Log.LogChannel.Download);
            if (res.HttpStatusCode == Response.HttpStatusOK)
            {
                //cache += res.ID + ":" + manifest["paths"][res.ID]["v"] + "\n";
                if (cache.ContainsKey(res.ID))
                {
                    cache[res.ID] = double.Parse(manifest["paths"][res.ID]["v"].ToString());
                }
                else
                {
                    cache.Add(res.ID, double.Parse(manifest["paths"][res.ID]["v"].ToString()));
                }

                if (res.ID.IndexOf(".json") > -1 || res.ID.IndexOf(".txt") > -1)
                {
                    persistentStore.SaveText(res.ID, res.Text, false);
                }
                else
                {
                    persistentStore.SaveBytes(res.ID, res.Bytes);
                }

                string downloadedFilePath = "";
                for (int i = 0; i < downloads.Count; i++)
                {
                    if (downloads[i] == res.ID)
                    {
                        downloadedFilePath = downloads[i];
                        downloads.Remove(res.ID);
                    }
                }

                StringBuilder result = new StringBuilder();
                foreach (KeyValuePair <string, double> entry in cache)
                {
                    result.Append(entry.Key);
                    result.Append(":");
                    result.Append(entry.Value);
                    result.Append("\n");
                }
                persistentStore.SaveText(CacheName, result.ToString(), false);
                result = null;

                if (downloads.Count <= 0)
                {
                    Log.Debug("[DEBUG-AUTH] AppController OnDownload downloads complete!", Log.LogChannel.Download);
                    Destroy();
                }
                else if (downloadedFilePath.Equals("ForceVision/languages.txt"))
                {
                    Log.Debug("Downloaded Languages file, update loc and reparse donwloads!", Log.LogChannel.Download);
                    Localizer.Load(true);
                    ParseDownloads();
                    DownloadNextFile();
                }
                else
                {
                    DownloadNextFile();
                }
            }
            else
            {
                Log.Debug("[DEBUG-AUTH] AppController OnDownload failed: " + res.ID + " with HTTPStatusCode: " + res.HttpStatusCode, Log.LogChannel.Download);
                if (res.Request.Attempts < maxAttempts)
                {
                    res.Request.Retry();
                }
                else
                {
                    Cancel();
                }
            }
        }