internal bool LogRuntimeWarnings(string pathToBuildLogs) { if (!File.Exists(pathToBuildLogs)) { return(false); } PackedPlayModeBuildLogs runtimeBuildLogs = JsonUtility.FromJson <PackedPlayModeBuildLogs>(File.ReadAllText(pathToBuildLogs)); bool messageLogged = false; foreach (var log in runtimeBuildLogs.RuntimeBuildLogs) { messageLogged = true; switch (log.Type) { case LogType.Warning: Addressables.LogWarning(log.Message); break; case LogType.Error: Addressables.LogError(log.Message); break; case LogType.Log: Addressables.Log(log.Message); break; } } return(messageLogged); }
/// <inheritdoc /> protected override TResult BuildDataImplementation <TResult>(AddressablesDataBuilderInput builderInput) { var timer = new System.Diagnostics.Stopwatch(); timer.Start(); var settingsPath = Addressables.BuildPath + "/settings.json"; var buildLogsPath = Addressables.BuildPath + "/buildLogs.json"; if (!File.Exists(settingsPath)) { IDataBuilderResult resE = new AddressablesPlayModeBuildResult() { Error = "Player content must be built before entering play mode with packed data. This can be done from the Addressables window in the Build->Build Player Content menu command." }; return((TResult)resE); } var rtd = JsonUtility.FromJson <ResourceManagerRuntimeData>(File.ReadAllText(settingsPath)); if (rtd == null) { IDataBuilderResult resE = new AddressablesPlayModeBuildResult() { Error = string.Format("Unable to load initialization data from path {0}. This can be done from the Addressables window in the Build->Build Player Content menu command.", settingsPath) }; return((TResult)resE); } PackedPlayModeBuildLogs buildLogs = new PackedPlayModeBuildLogs(); BuildTarget dataBuildTarget = BuildTarget.NoTarget; if (!Enum.TryParse(rtd.BuildTarget, out dataBuildTarget)) { buildLogs.RuntimeBuildLogs.Add(new PackedPlayModeBuildLogs.RuntimeBuildLog(LogType.Warning, $"Unable to parse build target from initialization data: '{rtd.BuildTarget}'.")); } else if (BuildPipeline.GetBuildTargetGroup(dataBuildTarget) != BuildTargetGroup.Standalone) { buildLogs.RuntimeBuildLogs.Add(new PackedPlayModeBuildLogs.RuntimeBuildLog(LogType.Warning, $"Asset bundles built with build target {dataBuildTarget} may not be compatible with running in the Editor.")); } if (buildLogs.RuntimeBuildLogs.Count > 0) { File.WriteAllText(buildLogsPath, JsonUtility.ToJson(buildLogs)); } //TODO: detect if the data that does exist is out of date.. var runtimeSettingsPath = "{UnityEngine.AddressableAssets.Addressables.RuntimePath}/settings.json"; PlayerPrefs.SetString(Addressables.kAddressablesRuntimeDataPath, runtimeSettingsPath); PlayerPrefs.SetString(Addressables.kAddressablesRuntimeBuildLogPath, buildLogsPath); IDataBuilderResult res = new AddressablesPlayModeBuildResult() { OutputPath = settingsPath, Duration = timer.Elapsed.TotalSeconds }; m_DataBuilt = true; return((TResult)res); }