Kanda Foundation 0.2.0
Loading...
Searching...
No Matches
App Settings

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:

  1. Navigate to Project Settings: Go to Project Settings > Kanda SDK to review and configure the available settings.
  2. 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.
  3. 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 Connection Settings

using UnityEngine;
public class ExampleUsage : MonoBehaviour
{
void Start()
{
var connectionSettings = AppServiceLocator.Get<IConnectionSettings>();
KandaLog.Write("Lobby Scene: " + connectionSettings.LobbySceneName);
KandaLog.Write("Session Scene: " + connectionSettings.SessionSceneName);
KandaLog.Write("Local Connection Port: " + connectionSettings.LocalConnectionPort);
}
}
An application-level service container which spans the lifetime of multiple scenes....
Definition AppServiceLocator.cs:26
Stores app settings about how to connect to multiplayer sessions.
Definition ConnectionSettings.cs:9
Definition AppServiceLocator.cs:4
Definition AppSettings.cs:5

Example: Accessing Cloud Settings

using UnityEngine;
public class CloudSettingsExample : MonoBehaviour
{
void Start()
{
var cloudSettings = AppServiceLocator.Get<ICloudSettings>();
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:

  1. Define the Settings Interface: Create an interface that inherits from IKandaSettings. This interface should define all the properties your settings will have.

    namespace YourNamespace
    {
    public interface IYourCustomSettings : IKandaSettings
    {
    string SomeSetting { get; }
    int AnotherSetting { get; }
    // Add more properties as needed
    }
    }
    A tag interface for settings assets related to the Kanda SDK.
    Definition IKandaSettings.cs:7
    Definition AppSettings.cs:5
  2. 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 other properties from IYourCustomSettings
    }
    }
  3. 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" }
    );
    }
    }
    }
  4. Register Your Custom Settings: Register your custom settings in your package's Startup.cs or equivalent initialization file.

    using UnityEngine;
    namespace YourNamespace
    {
    public static class Startup
    {
    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)]
    public static void Initialize()
    {
    IYourCustomSettings customSettings =
    RuntimeSettingsAssetUtils.LoadOrInstantiate<YourCustomSettings>(
    YourCustomSettings.AssetPath);
    AppServiceLocator.Register(customSettings);
    // Register other services or perform other initialization tasks here
    }
    }
    }
    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:10

Accessing Your Custom Settings

After registration, you can access your custom settings through the AppServiceLocator:

using UnityEngine;
public class CustomSettingsExample : MonoBehaviour
{
void Start()
{
var yourSettings = AppServiceLocator.Get<IYourCustomSettings>();
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.