using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using JetBrains.Annotations; using UnityEditor; using UnityEngine; namespace NugetForUnity.Configuration { /// /// Serializable configuration about how native runtime assets (.dll's) are imported. /// [Serializable] internal class NativeRuntimeAssetConfiguration : ISerializationCallbackReceiver { [SerializeField] private string cpuArchitecture; [SerializeField] private string editorCpuArchitecture; [SerializeField] private string editorOperatingSystem; [SerializeField] private string runtime; [SerializeField] private List supportedPlatformTargets; /// /// Initializes a new instance of the class. /// This constructor is only for deserializer. /// [EditorBrowsable(EditorBrowsableState.Never)] public NativeRuntimeAssetConfiguration() { } /// /// Initializes a new instance of the class. /// /// The name of the runtime, the name of the folder inside the runtimes/native folder, for which this configuration is used. /// The cpu architecture of the target device for which assets of this runtime should be included in the build. /// The cpu architecture of the Unity Editor on which the assets should be included. /// The name of the operating system running the Unity Editor on which the assets should be used in. /// The target platforms for which this asset should be included in the build. public NativeRuntimeAssetConfiguration( [NotNull] string runtime, [CanBeNull] string cpuArchitecture, [CanBeNull] string editorCpuArchitecture, [CanBeNull] string editorOperatingSystem, [NotNull] params BuildTarget[] supportedPlatformTargets) { this.runtime = runtime; this.cpuArchitecture = cpuArchitecture; SupportedPlatformTargets = supportedPlatformTargets.ToList(); this.editorCpuArchitecture = editorCpuArchitecture; this.editorOperatingSystem = editorOperatingSystem; SetNullStringsToEmpty(); } /// /// Gets or sets the name of the runtime, the name of the folder inside the runtimes/native folder, for which this configuration is used. /// [NotNull] public string Runtime { get => runtime; set => runtime = value; } /// /// Gets or sets the target platforms for which assets of this runtime should be included in the build. /// [field: NonSerialized] [NotNull] public List SupportedPlatformTargets { get; set; } /// /// Gets or sets the cpu architecture of the target device for which assets of this runtime should be included in the build. /// If this is null / empty the assets are included for all cpu architectures. /// [CanBeNull] public string CpuArchitecture { get => cpuArchitecture; set => cpuArchitecture = value; } /// /// Gets or sets the cpu architecture of the Unity Editor on which the assets should be included. /// If this is null / empty the asset is used by all Unity Editors. /// [CanBeNull] public string EditorCpuArchitecture { get => editorCpuArchitecture; set => editorCpuArchitecture = value; } /// /// Gets or sets the name of the operating system running the Unity Editor on which the assets should be used in. /// If this is null the assets are only used in Runtime. /// [CanBeNull] public string EditorOperatingSystem { get => editorOperatingSystem; set => editorOperatingSystem = value; } /// public void OnAfterDeserialize() { if (SupportedPlatformTargets is null) { SupportedPlatformTargets = new List(); } else { SupportedPlatformTargets.Clear(); } foreach (var target in supportedPlatformTargets) { if (Enum.TryParse(target, true, out var parsedTarget)) { SupportedPlatformTargets.Add(parsedTarget); } } SetNullStringsToEmpty(); } /// public void OnBeforeSerialize() { supportedPlatformTargets = SupportedPlatformTargets.ConvertAll(target => target.ToString()); } private void SetNullStringsToEmpty() { if (editorOperatingSystem is null) { editorOperatingSystem = string.Empty; } if (cpuArchitecture is null) { cpuArchitecture = string.Empty; } if (editorCpuArchitecture is null) { editorCpuArchitecture = string.Empty; } } } }