/// <summary> /// Retrieves the <see cref="GameSettingsAsset"/> from the given <see cref="Package"/> if available, /// or otherwise attempts to retrieve it from the from the <see cref="PackageSession.CurrentPackage"/> of the session. /// If none is available, this method returns a new default instance. /// </summary> /// <param name="package">The package from which to retrieve the game settings.</param> /// <returns>The <see cref="GameSettingsAsset"/> from either the given package or the session if available. A new default instance otherwise.</returns> public static GameSettingsAsset GetGameSettingsAssetOrDefault(this Package package) { var gameSettings = package.GetGameSettingsAsset(); if (gameSettings == null) { gameSettings = package.Session.CurrentProject?.Package.GetGameSettingsAsset(); } return(gameSettings ?? GameSettingsFactory.Create()); }
/// <summary> /// Retrieves the <see cref="GameSettingsAsset"/> from the given <see cref="Package"/> if available, /// or otherwise attempts to retrieve it from the from the <see cref="PackageSession.CurrentPackage"/> of the session. /// If none is available, this method returns a new default instance. /// </summary> /// <param name="package">The package from which to retrieve the game settings.</param> /// <returns>The <see cref="GameSettingsAsset"/> from either the given package or the session if available. A new default instance otherwise.</returns> public static GameSettingsAsset GetGameSettingsAssetOrDefault(this Package package) { var gameSettings = package.GetGameSettingsAsset(); if (gameSettings == null) { var session = package.Session; var currentPackage = session.CurrentPackage; if (currentPackage != null) { gameSettings = currentPackage.GetGameSettingsAsset(); } } return(gameSettings ?? GameSettingsFactory.Create()); }
/// <summary> /// Retrieves the <see cref="GameSettingsAsset"/> from the <see cref="PackageSession.CurrentPackage"/> of the given session if available, /// or a new default instance otherwise. /// </summary> /// <param name="session">The package session from which to retrieve the game settings.</param> /// <returns>The <see cref="GameSettingsAsset"/> from the given session if available. A new default instance otherwise.</returns> private static GameSettingsAsset GetGameSettingsAssetOrDefault(this PackageSession session) { return(session.CurrentPackage?.GetGameSettingsAsset() ?? GameSettingsFactory.Create()); }