This package uses settings assets to configure application behavior, such as which standard scenes should be used and how the app should connect to multiplayer services. You can review app settings for the SDK in Project Settings > Kanda SDK.
Settings assets are stored in the Resources/KandaSdk/AppSettings folder. If you don't set these up, default values will be used instead.
Change App Settings
To change Kanda app settings in your Unity project, follow these steps:
- Navigate to Project Settings: Go to Project Settings > Kanda SDK to review and configure the available settings.
- Create Settings Assets: Settings assets are stored in the Resources/KandaSdk/AppSettings folder. When opening the project settings tab, the relevant settings assets are automatically created, but you can also manipulate them using the Kanda SDK > App Settings menu items.
- Understand the Settings Structure: The settings assets include various configurations, such as scene names and connection ports, which specify the application's behavior.
Access App Settings
You can access app settings directly through the AppServiceLocator.
Example: Accessing Lifecycle Settings
using UnityEngine;
public class ExampleUsage : MonoBehaviour
{
void Start()
{
KandaLog.Write("Lobby Scene: " + lifecycleSettings.LobbySceneName);
KandaLog.Write("Session Scene: " + lifecycleSettings.SessionSceneName);
}
}
An application-level service container which spans the lifetime of multiple scenes....
Definition AppServiceLocator.cs:27
Stores app settings about how to connect to multiplayer sessions.
Definition LifecycleSettings.cs:23
Definition AppServiceLocator.cs:5
Definition AppSettings.cs:5
Example: Accessing Cloud Settings
using UnityEngine;
public class CloudSettingsExample : MonoBehaviour
{
void Start()
{
KandaLog.Write("API Hostname: " + cloudSettings.ApiHostname);
KandaLog.Write("Customer Identifier: " + cloudSettings.CustomerIdentifier);
}
}
Stores app settings about how to connect and interact with Kanda Cloud services.
Definition CloudSettings.cs:10
Creating New Settings Types
To create new settings types, follow these steps:
Define the Settings Interface: Create an interface that inherits from IKandaSettings. This interface should define all the properties your settings will have.
namespace YourNamespace
{
{
string SomeSetting { get; }
int AnotherSetting { get; }
}
}
A tag interface for settings assets related to the Kanda SDK.
Definition IKandaSettings.cs:6
Definition AppSettings.cs:5
Implement the Settings Class: Create a class that inherits from ScriptableObject and implements your custom settings interface.
using UnityEngine;
namespace YourNamespace
{
public class YourCustomSettings : ScriptableObject, IYourCustomSettings
{
public const string AssetPath = SettingsStandardPaths.AssetAppSettings + "/YourCustomSettings";
[field: SerializeField]
public string SomeSetting { get; set; } = "Default Value";
[field: SerializeField]
public int AnotherSetting { get; set; } = 0;
}
}
Implement a Custom Settings Provider: Create a custom settings provider to expose your settings in the Project Settings window.
using System.Collections.Generic;
using UnityEditor;
namespace YourNamespace.Editor
{
public class YourCustomSettingsProvider : KandaSettingsProvider<YourCustomSettings>
{
private YourCustomSettingsProvider(
string tabName,
string assetPath,
string info = null,
IEnumerable<string> searchKeywords = null
)
: base(tabName, assetPath, info, searchKeywords)
{
}
[SettingsProvider]
public static SettingsProvider CreateSettingsProvider()
{
return new YourCustomSettingsProvider(
"YourCustom",
YourCustomSettings.AssetPath,
"Use this tab to specify your custom settings",
new[] { "Kanda", "Custom", "YourKeywords" }
);
}
}
}
Register Your Custom Settings: Register your custom settings in your package's Startup.cs or equivalent initialization file.
using UnityEngine;
namespace YourNamespace
{
{
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)]
public static void Initialize()
{
IYourCustomSettings customSettings =
YourCustomSettings.AssetPath);
}
}
}
A collection of runtime utilities to read settings assets.
Definition RuntimeSettingsAssetUtils.cs:10
A main class with work intended to run on application start to configure features in this package.
Definition Startup.cs:12
Accessing Your Custom Settings
After registration, you can access your custom settings through the AppServiceLocator:
using UnityEngine;
public class CustomSettingsExample : MonoBehaviour
{
void Start()
{
KandaLog.Write("Some Setting: " + yourSettings.SomeSetting);
KandaLog.Write("Another Setting: " + yourSettings.AnotherSetting);
}
}
By following these steps, you can create and use custom settings that integrate seamlessly with the Kanda SDK's settings system.