Example #1
0
 public static bool CanAttemptToConnectToCDN()
 {
                 #if RC_BUILD
     return(true);
                 #else
     CloudStorageAPI        cloudStorageAPI        = new CloudStorageAPI(null);
     StreamingAssetsStorage streamingAssetsStorage = new StreamingAssetsStorage(Game.None, null);
     bool ret = true;
     streamingAssetsStorage.LoadStreamingAssetsFile(cloudStorageAPI.cloudData.P12Path, (error, p12Bytes) =>
     {
         if (!string.IsNullOrEmpty(error))
         {
             Log.Warning("Unable to load " + cloudStorageAPI.cloudData.P12Path);
             ret = false;
         }
     }, true);
     if (string.IsNullOrEmpty(cloudStorageAPI.cloudData.Password))
     {
         Log.Warning("No cloudData.Password specified " + cloudStorageAPI.cloudData.Password);
         ret = false;
     }
     if (!ret)
     {
         Log.Warning("You need to have both a .p12 file and password to run this locally");
     }
     return(ret);
                 #endif
 }
Example #2
0
        protected void OnSdkReady()
        {
            // no further initialization needed if FTUE is complete
            if (FtueDataController.IsFtueComplete(FtueType.Intro))
            {
                return;
            }

            // adding controller
            saberPeripheral = new ControllerPeripheral(VisionSDK.ControllerName,
                                                       ControllerTransform,
                                                       null,
                                                       container.GetSavedSaberColorID());
            Sdk.Connections.AddPeripheral(saberPeripheral);

            // adding beacon
            Sdk.Tracking.OnBeaconStateChange += OnBeaconStateChange;

            // checking beacon signal
            if (Sdk.Tracking.IsBeaconTracked)
            {
                beaconSeen = true;

                // playing audio - signal acquired
                AudioEvent.Play(AudioEventName.Ftue.Computer.SignalAcquired, gameObject);
            }
            else
            {
                // playing audio - searching for signal
                AudioEvent.Play(AudioEventName.Ftue.Computer.AcquireSignal, gameObject);
            }

            // setting input handler
            Sdk.Input.OnButtonDown += OnButtonDown;

            // adding input listeners
            Sdk.Connections.OnPeripheralStateChange += OnPeripheralConnected;
            Sdk.Connections.OnPeripheralStateChange += OnPeripheralDisconnected;

            // adding animation listener
            HolocronAnimations.OnAnimationComplete += OnHolocronEnterAnimationComplete;

            // loading animation sequence config
            StreamingAssetsStorage loader = new StreamingAssetsStorage(Game.ForceVision, null);

            loader.LoadStreamingAssetsText(AnimationConfigFile, OnConfigLoaded, true);

            // playing sound
            AudioEvent.Play(AudioEventName.Ftue.MusicStart, gameObject);
        }
Example #3
0
        protected void OnSdkReady()
        {
            // no further initialization needed if FTUE is complete
            if (FtueDataController.IsFtueComplete(FtueType.DarkSide))
            {
                return;
            }

            // adding controller
            saberPeripheral = new ControllerPeripheral(
                VisionSDK.ControllerName,
                ControllerTransform,
                null,
                container.GetSavedSaberColorID()
                );
            Sdk.Connections.AddPeripheral(saberPeripheral);

            // adding beacon
            Sdk.Tracking.OnBeaconStateChange += OnBeaconStateChange;

            // checking beacon signal
            if (Sdk.Tracking.IsBeaconTracked)
            {
                beaconSeen = true;
            }
            else
            {
            }

            // setting input handler
            Sdk.Input.OnButtonDown += OnButtonDown;

            // adding input listeners
            Sdk.Connections.OnPeripheralStateChange += OnPeripheralConnected;
            Sdk.Connections.OnPeripheralStateChange += OnPeripheralDisconnected;

            // loading animation sequence config
            StreamingAssetsStorage loader = new StreamingAssetsStorage(Game.ForceVision, null);

            loader.LoadStreamingAssetsText(AnimationConfigFile, OnConfigLoaded, true);

            // playing the menu FTUE animation
            Menu.GetComponent <Animator>().Play(MenuFtue);
        }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Disney.ForceVision.ContainerAPI"/> class.
        /// </summary>
        /// <param name="game">Game.</param>
        public ContainerAPI(Game game)
        {
            // We need a MonoBehaviour for Native to call into as well for Streaming Asset loading.
            GameObject bridge = GameObject.Find("ForceVisionNativeBridge") ?? new GameObject("ForceVisionNativeBridge",
                                                                                             typeof(NativeBridge));

            NativeBridge = bridge.GetComponent <NativeBridge>();

            // Data Storage / Loading
            StreamingAssets   = new StreamingAssetsStorage(game, NativeBridge);
            PersistentData    = new PersistentDataStorage(game);
            PlayerPrefs       = new PlayerPrefsStorage(game);
            cdnAssetLoaderApi = new Disney.ForceVision.Internal.CdnAssetLoaderApi(NativeBridge);

            // Native Settings
            NativeSettings = new NativeSettings();

                        #if UNITY_ANDROID && !UNITY_EDITOR
            NativeBridge.StartLowMemoryPoll(NativeSettings);
                        #endif
        }
Example #5
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);
            }
        }
Example #6
0
        public void AuthenticateWithGAE(Action <Response> callback = null, Action <float> fileProgressCallback = null, Func <string, Dictionary <string, string>, Dictionary <string, string>, int> OverrideRequestMethod = null)
        {
            Log.Debug("[DEBUG-AUTH] CloudStorageAPI AuthenticateWithGAE", Log.LogChannel.General);

                        #if RC_BUILD
            callback(null);
            return;
                        #endif

            Dictionary <string, string> requestFields = new Dictionary <string, string>();
            Dictionary <string, string> headers       = new Dictionary <string, string>();
            X509Certificate2            cert;
            try
            {
                StreamingAssetsStorage streamingAssetsStorage = new StreamingAssetsStorage(Game.None, null);
                byte[] bytes = null;
                streamingAssetsStorage.LoadStreamingAssetsFile(cloudData.P12Path, (success, p12Bytes) =>
                {
                    bytes = p12Bytes;
                }, true);

                Log.Debug("p12 bytes length =  " + bytes.Length);

                cert = new X509Certificate2(bytes, cloudData.Password, X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet);

                RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
                rsa.FromXmlString(cert.PrivateKey.ToXmlString(true));

                long assertionTime = GetTimeInSeconds();

                string claimSet = string.Format(ClaimSetSchema, cloudData.ServiceAccountEmail, ScopeStorageReadOnly, ApiEndpoint, assertionTime, assertionTime + expiration);

                string headerClaim = string.Format("{0}.{1}", Convert.ToBase64String(Encoding.UTF8.GetBytes(ClaimHeader)), Convert.ToBase64String(Encoding.UTF8.GetBytes(claimSet)));

                byte[] dataToSign = Encoding.UTF8.GetBytes(headerClaim);
                byte[] signedData = rsa.SignData(dataToSign, "SHA256");
                string sgn        = Convert.ToBase64String(signedData);
                string jwt        = string.Format("{0}.{1}", headerClaim, sgn);

                requestFields["grant_type"]     = "assertion";
                requestFields["assertion_type"] = AssertionType;
                requestFields["assertion"]      = jwt;

                headers["Content-Type"] = "application/x-www-form-urlencoded";
            }
            catch (Exception e)
            {
                                #if CI_BUILD || QA_BUILD || RC_BUILD
                Log.Exception(e);
                                #else
                Log.Warning("missing p12 file: " + cloudData.P12Path + e.Message);
                                #endif
                callback(null);
                return;
            }
            if (OverrideRequestMethod != null)
            {
                OverrideRequestMethod(ApiEndpoint, headers, requestFields);
            }
            else
            {
                Request authRequest = new Request(requestRunner, callback, "authRequest", ApiEndpoint, headers, requestFields, fileProgressCallback);
                authRequest.PostData();
            }
        }
Example #7
0
        /// <summary>
        /// Purges the cpipe cache.
        /// Called when app starts and runs if the app version on disk is older then the app verison.
        /// The purge will delete any english or non loc specific files and update the cache with all of the latest version from the embedded manifest.
        /// </summary>
        public static void PurgeCpipeCache()
        {
            bool doPurge = false;
            Dictionary <string, string> cache = new Dictionary <string, string>();
            PersistentDataStorage       persistentDataStorage  = new PersistentDataStorage(Game.None);
            StreamingAssetsStorage      streamingAssetsStorage = new StreamingAssetsStorage(Game.None, null);

            //if app version has increased, do purge
            AppVersion appVersion = new AppVersion(Application.version);

            if (persistentDataStorage.FileExists(appVerisonFile))
            {
                AppVersion storedVersion = new AppVersion(persistentDataStorage.LoadText(appVerisonFile));
                if (storedVersion.Major > appVersion.Major)
                {
                    doPurge = true;
                }
                else if (storedVersion.Major >= appVersion.Major && storedVersion.Minor > appVersion.Minor)
                {
                    doPurge = true;
                }
                else if (storedVersion.Major >= appVersion.Major && storedVersion.Minor >= appVersion.Minor && storedVersion.Revision > appVersion.Revision)
                {
                    doPurge = true;
                }
            }
            else
            {
                doPurge = true;
            }
            Log.Debug("dopurge " + doPurge, Log.LogChannel.General);

            if (doPurge == false)
            {
                return;
            }

            string oldCache = "";

            if (persistentDataStorage.FileExists(CacheName))
            {
                oldCache = persistentDataStorage.LoadText(CacheName);
                string[] tempOldCacheLines = oldCache.Split('\n');
                for (int i = 0; i < tempOldCacheLines.Length; i++)
                {
                    if (!string.IsNullOrEmpty(tempOldCacheLines[i]))
                    {
                        string   rawLine           = tempOldCacheLines[i];
                        string[] rawLineComponents = rawLine.Split(':');
                        cache[rawLineComponents[0]] = rawLineComponents[1];
                    }
                }
            }

            Log.Debug("load manifest from streaming at " + Application.streamingAssetsPath + "/" + Game.ForceVision + "/" + EmbeddedCpipeManifestFile, Log.LogChannel.General);
            //load streaming assets manifest and write cache file of embedded content
            streamingAssetsStorage.LoadStreamingAssetsText(Game.ForceVision + "/" + EmbeddedCpipeManifestFile, (error, text) =>
            {
                if (string.IsNullOrEmpty(error))
                {
                    try
                    {
                        JSONObject manifest = new JSONObject(text);

                        WriteManifestVersion(manifest["version"].ToString());

                        JSONObject paths      = manifest["paths"];
                        string newCacheString = "";
                        for (int i = 0; i < paths.keys.Count; i++)
                        {
                            string folder = paths.keys[i];
                            string v      = paths[i]["v"].ToString();

                            //update english only
                            bool isEnglishFile = true;
                            foreach (string languageFolder in Localizer.LanguageFolders)
                            {
                                if (folder.Contains("GeneratedSoundBanks") && folder.Contains("/" + languageFolder + "/") && languageFolder != Localizer.LanguageFolders[0])
                                {
                                    isEnglishFile = false;
                                    Log.Debug("non english file found. path = " + folder, Log.LogChannel.Download);
                                }
                            }

                            if (isEnglishFile)
                            {
                                if (cache.ContainsKey(folder))
                                {
                                    //if in cache already then update to local version and delete local file
                                    if (persistentDataStorage.FileExists(folder))
                                    {
                                        persistentDataStorage.DeleteFile(folder);
                                        Log.Debug("deleteing file in " + folder, Log.LogChannel.Download);
                                    }
                                }
                                newCacheString += folder + ":" + v + "\n";
                            }
                            else
                            {
                                if (cache.ContainsKey(folder))
                                {
                                    newCacheString += folder + ":" + v + "\n";
                                }
                            }
                        }
                        persistentDataStorage.SaveText(CacheName, newCacheString, false);

                        persistentDataStorage.SaveText(appVerisonFile, Application.version, false);
                    }
                    catch (System.Exception e)
                    {
                        Log.Exception(e);
                    }
                }
                else
                {
                                        #if !UNITY_EDITOR
                    Log.Error("error loading manifest from streamingassets. " + error);
                                        #endif
                }
            }, true);
        }