Created
September 13, 2022 14:41
-
-
Save monry/1928e6cf4e2ba90aaf3de8ab3fe5f202 to your computer and use it in GitHub Desktop.
ご家庭の IMGUI / UI Toolkit Wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Diagnostics.CodeAnalysis; | |
using UnityEditor; | |
using UnityEditor.UIElements; | |
using UnityEngine; | |
using UnityEngine.UIElements; | |
namespace Monry.Editor.Extensions | |
{ | |
/// <summary> | |
/// 全てのインスペクタ表示を IMGUI から UIToolkit ベースに切り替える | |
/// </summary> | |
/// <seealso href="https://forum.unity.com/threads/property-drawers.595369/page-2#post-7644859"/> | |
[SuppressMessage("ReSharper", "InvertIf")] | |
[CustomEditor(typeof(Object), true)] | |
public class ImguiToToolkitWrapper : UnityEditor.Editor | |
{ | |
public override VisualElement CreateInspectorGUI() | |
{ | |
var root = new VisualElement(); | |
var prop = serializedObject.GetIterator(); | |
if (prop.NextVisible(true)) | |
{ | |
do | |
{ | |
var field = new PropertyField(prop); | |
if (prop.name == "m_Script") // フィールド名ベタ書き… :skull: | |
{ | |
// SetEnable(false) だとダブルクリックによる Edit Script ができないのがアレだが、回避策が見つからず | |
field.SetEnabled(false); | |
} | |
root.Add(field); | |
} | |
while (prop.NextVisible(false)); | |
} | |
return root; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unity Forum によれば、Unity 2022.1 からは標準で UI Toolkit になるらしいので、このスクリプトは不要になるはず。