Samples: Updated to 2.0.0
This commit is contained in:
parent
55d0393cf8
commit
2bcd3c63af
8 changed files with 208 additions and 4 deletions
92
Samples~/SamplesToolbarBurst/MainToolbarBurstElement.cs
Normal file
92
Samples~/SamplesToolbarBurst/MainToolbarBurstElement.cs
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
#if UNITY_6000_3_OR_NEWER
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Toolbars;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
namespace Module.NavigationTool.Editor.Burst.Toolbar
|
||||
{
|
||||
internal static class MainToolbarBurstElement
|
||||
{
|
||||
[Preserve]
|
||||
[MainToolbarElement("Toolbar/Burst", ussName = "", defaultDockIndex = 0, defaultDockPosition = MainToolbarDockPosition.Middle, menuPriority = 500)]
|
||||
public static MainToolbarElement Draw()
|
||||
{
|
||||
Styles.Initialize();
|
||||
|
||||
var isBurstEnabled = IsBurstEnabled();
|
||||
var icon = isBurstEnabled ? Styles.IconEnabled : Styles.IconDisabled;
|
||||
var content = new MainToolbarContent(icon, "Enable/disable burst compiler");
|
||||
return new MainToolbarToggle(content, IsBurstEnabled(), _ =>
|
||||
{
|
||||
EditorApplication.ExecuteMenuItem("Jobs/Burst/Enable Compilation");
|
||||
MainToolbar.Refresh("Toolbar/Burst");
|
||||
});
|
||||
}
|
||||
|
||||
private static bool IsBurstEnabled()
|
||||
{
|
||||
const string typeFullname = "Unity.Burst.Editor.BurstEditorOptions, Unity.Burst";
|
||||
const string propertyName = "EnableBurstCompilation";
|
||||
|
||||
var type = Type.GetType(typeFullname, false, true);
|
||||
|
||||
if (type == null)
|
||||
{
|
||||
Debug.LogWarningFormat("Failed to find type with name: {0}", typeFullname);
|
||||
return false;
|
||||
}
|
||||
|
||||
var property = type.GetProperty(propertyName, BindingFlags.Public | BindingFlags.Static);
|
||||
|
||||
if (property == null)
|
||||
{
|
||||
Debug.LogWarningFormat("Failed to find property with name: {0} on type: {1}", propertyName, typeFullname);
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool)property.GetValue(null);
|
||||
}
|
||||
|
||||
private static class Styles
|
||||
{
|
||||
private static bool _isInitialized;
|
||||
public static Texture2D IconEnabled;
|
||||
public static Texture2D IconDisabled;
|
||||
|
||||
private const string EditorIconFileNameLight = "tex_icon_burst_light";
|
||||
private const string EditorIconFileNameDark = "tex_icon_burst_dark";
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
if (_isInitialized)
|
||||
return;
|
||||
|
||||
IconEnabled = LoadIcon("_enabled");
|
||||
IconDisabled = LoadIcon("_disabled");
|
||||
_isInitialized = true;
|
||||
}
|
||||
|
||||
private static Texture2D LoadIcon(string postfix)
|
||||
{
|
||||
var iconPrefix = EditorGUIUtility.isProSkin ? EditorIconFileNameDark : EditorIconFileNameLight;
|
||||
var filename = $"{iconPrefix}{postfix}";
|
||||
var guids = AssetDatabase.FindAssets("t:texture " + filename);
|
||||
|
||||
for (var i = 0; i < guids.Length; i++)
|
||||
{
|
||||
var path = AssetDatabase.GUIDToAssetPath(guids[i]);
|
||||
var tex = AssetDatabase.LoadAssetAtPath<Texture2D>(path);
|
||||
|
||||
if (tex != null)
|
||||
return tex;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9987eb28543a4bf288fc7cd66a5b707f
|
||||
timeCreated: 1765029787
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
#if !UNITY_6000_3_OR_NEWER
|
||||
using Module.NavigationTool.Editor.Toolbar;
|
||||
using UnityEditor;
|
||||
|
||||
|
|
@ -24,4 +25,5 @@ namespace Module.NavigationTool.Editor.Burst.Toolbar
|
|||
IsEnabled = EditorGUILayout.Toggle("Enable Burst", IsEnabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#if !UNITY_6000_3_OR_NEWER
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using JetBrains.Annotations;
|
||||
|
|
@ -95,4 +96,5 @@ namespace Module.NavigationTool.Editor.Burst.Toolbar
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue