您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

81 行
2.3 KiB

using System;
using UnityEngine;
namespace Unity.Services.Core.Configuration
{
/// <summary>
/// Wrapper for project configuration values.
/// </summary>
[Serializable]
class ConfigurationEntry
{
[SerializeField]
string m_Value;
/// <summary>
/// Get the stored configuration value.
/// </summary>
public string Value => m_Value;
[SerializeField]
bool m_IsReadOnly;
/// <summary>
/// If true, <see cref="Value"/> can't be changed.
/// </summary>
public bool IsReadOnly
{
get => m_IsReadOnly;
internal set => m_IsReadOnly = value;
}
/// <summary>
/// Create a new instance of the <see cref="ConfigurationEntry"/> class.
/// </summary>
/// <remarks>
/// Required for serialization.
/// </remarks>
public ConfigurationEntry() {}
/// <summary>
/// Create a new instance of the <see cref="ConfigurationEntry"/> class.
/// </summary>
/// <param name="value">
/// The value to store.
/// </param>
/// <param name="isReadOnly">
/// If true, the value can't be changed after construction.
/// </param>
public ConfigurationEntry(string value, bool isReadOnly = false)
{
m_Value = value;
m_IsReadOnly = isReadOnly;
}
/// <summary>
/// Set <see cref="Value"/> only if <see cref="IsReadOnly"/> is false.
/// Does nothing otherwise.
/// </summary>
/// <param name="value">
/// The new value to store.
/// </param>
/// <returns>
/// Return true if <see cref="IsReadOnly"/> is false;
/// return false otherwise.
/// </returns>
public bool TrySetValue(string value)
{
if (IsReadOnly)
{
return false;
}
m_Value = value;
return true;
}
public static implicit operator string(ConfigurationEntry entry) => entry.Value;
public static implicit operator ConfigurationEntry(string value) => new ConfigurationEntry(value);
}
}