using System;
using System.Runtime.Serialization;
using Unity.PerformanceTesting.Runtime;
namespace Unity.PerformanceTesting.Data
{
///
/// Settings store
/// @TODO make it public along with guidelines of how and when to use
/// @TODO add a property bag
///
[Serializable]
internal class RunSettings : IDeserializationCallback
{
public RunSettings(params string[] args)
{
if (int.TryParse(Utils.GetArg(args, "-performance-measurement-count"), out var measurementMultiplier))
{
MeasurementCount = measurementMultiplier;
}
}
private static RunSettings m_Instance;
///
/// Singleton instance of settings.
///
public static RunSettings Instance
{
get
{
if (m_Instance == null)
{
m_Instance = ResourcesLoader.Load(Utils.RunSettings, Utils.PlayerPrefKeySettingsJSON);
}
return m_Instance;
}
set { m_Instance = value; }
}
///
/// Measurement counts will be overriden by specified value when using Measure.Method and Measure.Frames.
///
public int MeasurementCount = -1;
///
/// Validates the deserialized object.
///
/// The object that initiated the deserialization process.
public void OnDeserialization(object sender)
{
if (MeasurementCount < -1)
{
throw new SerializationException("MeasurementCount cannot be negative, except for the initial value of -1.");
}
}
}
}