예제 #1
0
        /// <summary>
        /// Initializes Poly Toolkit runtime. Must be called once, before any other use of the library.
        /// Call only once in your app's lifetime, not once per scene (Poly Toolkit survives scene loads).
        /// </summary>
        public static void Init(PolyAuthConfig?authConfig, PolyCacheConfig?cacheConfig)
        {
            string objName = Application.isPlaying ? "Poly Main" : "Poly Main (EDITOR)";

            PolyUtils.AssertTrue(instance == null, "PolyMainInternal.Init() already called. Can only be called once.");

            polyObject = PolyInternalUtils.CreateSingletonGameObject(objName);
            instance   = polyObject.AddComponent <PolyMainInternal>();
            instance.Setup(authConfig, cacheConfig);
        }
예제 #2
0
        public void FetchFormatFiles(PolyAsset asset, PolyFormatType formatType,
                                     PolyApi.FetchFormatFilesCallback completionCallback, FetchProgressCallback progressCallback = null)
        {
            PolyUtils.AssertNotNull(asset, "Asset can't be null.");
            PolyUtils.AssertNotNull(formatType, "formatType can't be null.");
            PolyFormat packageToFetch = asset.GetFormatIfExists(formatType);

            if (packageToFetch == null)
            {
                if (completionCallback != null)
                {
                    completionCallback(asset, PolyStatus.Error("Format type not present in asset"));
                }
                return;
            }

            PolyUtils.AssertNotNull(packageToFetch.root, "packageToFetch.root can't be null.");
            PolyUtils.AssertNotNull(packageToFetch.root.url, "packageToFetch.root.url can't be null.");
            PolyUtils.AssertNotNull(packageToFetch.resources, "packageToFetch.resources can't be null.");

            string accessToken = GetAccessToken();

            FetchOperationState state = new FetchOperationState();

            state.asset = asset;
            state.completionCallback  = completionCallback;
            state.progressCallback    = progressCallback;
            state.packageBeingFetched = packageToFetch;

            // Indicates how many files are pending download (1 for main file + 1 for each resource).
            state.totalFiles = state.pendingFiles = 1 + packageToFetch.resources.Count;

            // Note that the callbacks are asynchronous so they may complete in any order.  What we do know is that they
            // will all be called on the main thread, so they won't be called concurrently.

            long maxCacheAge = asset.IsMutable ? MUTABLE_ASSET_MAX_CACHE_AGE : IMMUTABLE_ASSET_MAX_CACHE_AGE;

            PolyClientUtils.GetRawFileBytes(packageToFetch.root.url, accessToken, maxCacheAge,
                                            (PolyStatus status, byte[] data) => { ProcessFileFetchResult(state, ROOT_FILE_INDEX, status, data); });

            for (int i = 0; i < packageToFetch.resources.Count; i++)
            {
                int thisIndex = i; // copy of variable, for closure below.
                PolyClientUtils.GetRawFileBytes(packageToFetch.resources[i].url, accessToken, maxCacheAge,
                                                (status, data) => { ProcessFileFetchResult(state, thisIndex, status, data); });
            }
        }
예제 #3
0
        /// <summary>
        /// Initializes the authenticator.
        ///
        /// Note that if config.autoLaunchSignInFlow is true (default), the sign-in flow (browser-based)
        /// will be launched immediately (unless the user is already authenticated).
        ///
        /// If config.autoLaunchSignInFlow is false, then you will remain in unauthenticated state
        /// until you manually call LaunchSignInFlow().
        /// </summary>
        /// <param name="config">The authentication configuration to use.</param>
        public static void Initialize(PolyAuthConfig config)
        {
            PolyUtils.AssertTrue(instance == null, "Authenticator.Initialize called twice.");

            GameObject hostObject = PolyInternalUtils.CreateSingletonGameObject("PolyToolkit Authenticator");

            instance = hostObject.AddComponent <Authenticator>();

            // Currently, authentication is only supported on Windows/Mac for now.
            PtDebug.LogFormat("Platform: {0}, authentication supported: {1}", Application.platform,
                              instance.IsAuthenticationSupported);
            if (instance.IsAuthenticationSupported)
            {
                InitializeCertificateValidation();
                instance.Setup(config);
            }
        }