#if UNITY_EDITOR
using System;
using System.IO;
using UnityEditor;
using UnityEngine;
namespace Unity.Burst.Editor
{
///
/// Allow disabling of the Burst compiler for specific assemblies.
/// ProjectSettings/Burst_DisableAssembliesForEditorCompilation.json
/// ProjectSettings/Burst_DisableAssembliesForPlayerCompilation.json
/// ProjectSettings/Burst_DisableAssembliesForPlayerCompilation_{platform}.json // if exists taken in preference to the one immediately above
///
internal static class BurstAssemblyDisable
{
public enum DisableType
{
Editor,
Player
}
private static string GetPath(DisableType type, string platformIdentifier)
{
if (DisableType.Editor == type)
{
return "ProjectSettings/Burst_DisableAssembliesForEditorCompilation.json";
}
var platformSpecicPath = $"ProjectSettings/Burst_DisableAssembliesForPlayerCompilation_{platformIdentifier}.json";
if (File.Exists(platformSpecicPath))
{
return platformSpecicPath;
}
return "ProjectSettings/Burst_DisableAssembliesForPlayerCompilation.json";
}
public static string[] GetDisabledAssemblies(DisableType type, string platformIdentifier)
{
var pathForSettings = GetPath(type, platformIdentifier);
if (!File.Exists(pathForSettings))
{
return Array.Empty();
}
var settings = new BackwardsCompatWrapper();
JsonUtility.FromJsonOverwrite(File.ReadAllText(pathForSettings),settings);
if (settings == null || settings.MonoBehaviour == null || settings.MonoBehaviour.DisabledAssemblies == null)
{
return Array.Empty();
}
return settings.MonoBehaviour.DisabledAssemblies;
}
}
///
/// Settings file -
///
///{
/// "MonoBehaviour": {
/// "DisabledAssemblies":
/// [
/// "Example.Assembly"
/// ]
/// }
///}
///
[Serializable]
class BackwardsCompatWrapper
{
public BurstDisableSettings MonoBehaviour;
}
[Serializable]
class BurstDisableSettings
{
public string[] DisabledAssemblies;
}
}
#endif