public ResourceProviderManager(ResourceProviderConfiguration config)
        {
            this.config = config;

            if (ResourcePolicy == ResourcePolicy.Dynamic && config.OptimizeLoadingPriority)
            {
                Application.backgroundLoadingPriority = ThreadPriority.Low;
            }
        }
예제 #2
0
        public ScriptPlayer(ScriptPlayerConfiguration config, ResourceProviderConfiguration providerConfig,
                            IScriptManager scriptManager, IInputManager inputManager, IStateManager stateManager)
        {
            Configuration       = config;
            this.providerConfig = providerConfig;
            this.scriptManager  = scriptManager;
            this.inputManager   = inputManager;
            this.stateManager   = stateManager;

            GosubReturnSpots     = new Stack <PlaybackSpot>();
            playedScriptRegister = new PlayedScriptRegister();
            commandExecutionCTS  = new CancellationTokenSource();
        }
예제 #3
0
        public static void PreprocessBuild(BuildPlayerOptions options)
        {
            config = Configuration.LoadOrDefault <ResourceProviderConfiguration>();

            useAddressables = AddressableHelper.Available && config.UseAddressables;
            if (!useAddressables)
            {
                Debug.Log("Consider installing the Addressable Asset System (via Unity's package manager) and enabling `Use Addressables` in the Naninovel's `Resource Provider` configuration menu. When the system is not available, all the assets assigned as Naninovel resources and not stored in `Resources` folders will be copied and re-imported when building the player, which could significantly increase the build time.");
            }

            if (useAddressables)
            {
                AddressableHelper.RemovePreviousEntries();
            }

            EditorUtils.CreateFolderAsset(tempResourcesPath);

            var records          = EditorResources.LoadOrDefault().GetAllRecords();
            var projectResources = ProjectResources.Get();
            var progress         = 0;

            foreach (var record in records)
            {
                progress++;

                var resourcePath      = record.Key;
                var assetGuid         = record.Value;
                var resourceAssetPath = AssetDatabase.GUIDToAssetPath(assetGuid);
                if (string.IsNullOrEmpty(resourceAssetPath) || !EditorUtils.AssetExistsByPath(resourceAssetPath))
                {
                    Debug.LogWarning($"Failed to resolve `{resourcePath}` asset path from GUID stored in `EditorResources` asset. The resource won't be included to the build.");
                    continue;
                }

                var resourceAsset = AssetDatabase.LoadAssetAtPath <Object>(resourceAssetPath);
                if (string.IsNullOrEmpty(resourceAssetPath))
                {
                    Debug.LogWarning($"Failed to load `{resourcePath}` asset. The resource won't be included to the build.");
                    continue;
                }

                if (EditorUtility.DisplayCancelableProgressBar("Processing Naninovel Resources", $"Processing '{resourceAssetPath}' asset...", progress / (float)records.Count))
                {
                    PostprocessBuild(); // Remove temporary assets.
                    throw new System.OperationCanceledException("Build was cancelled by the user.");
                }

                if (resourceAsset is SceneAsset)
                {
                    ProcessSceneResource(resourcePath, resourceAsset as SceneAsset);
                }
                else if (resourceAsset is UnityEngine.Video.VideoClip && options.target == BuildTarget.WebGL)
                {
                    ProcessVideoResourceForWebGL(resourcePath, resourceAsset);
                }
                else
                {
                    ProcessResourceAsset(assetGuid, resourcePath, resourceAsset, projectResources);
                }
            }

            AssetDatabase.SaveAssets();

            if (useAddressables && config.AutoBuildBundles)
            {
                EditorUtility.DisplayProgressBar("Processing Naninovel Resources", "Building asset bundles...", 1f);
                AddressableHelper.RebuildPlayerContent();
            }

            EditorUtility.ClearProgressBar();
        }