12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using Sirenix.OdinInspector.Editor;
- using Sirenix.OdinInspector.Editor.ValueResolvers;
- using Sirenix.Utilities.Editor;
- using UnityEngine;
- using UnityEditor;
- using KairoEngine.Core;
- namespace KairoEngine.Core.Editor
- {
- public class IconFoldoutGroupAttributeDrawer : OdinGroupDrawer<IconFoldoutGroupAttribute>
- {
- private LocalPersistentContext<bool> isExpanded;
- protected override void Initialize()
- {
- this.isExpanded = this.GetPersistentValue<bool>(
- "IconFoldoutGroupAttributeDrawer.isExpanded",
- GeneralDrawerConfig.Instance.ExpandFoldoutByDefault);
- }
- protected override void DrawPropertyLayout(GUIContent label)
- {
- SirenixEditorGUI.BeginBox();
- SirenixEditorGUI.BeginBoxHeader();
- string text = ValueResolver.GetForString(this.Property, this.Attribute.text, null).GetValue();
- string path = ValueResolver.GetForString(this.Property, this.Attribute.iconPath, null).GetValue();
- Texture2D image = EditorGUIUtility.FindTexture(path);
- if(image == null)
- {
- image = new Texture2D(1, 1);
- var data = System.IO.File.ReadAllBytes(path);
- if(data != null) image.LoadImage(data);
- image.Apply();
- }
- label = new GUIContent(text);
- var styleCollapse = new GUIStyle(EditorStyles.foldout);
- Rect rect = EditorGUILayout.GetControlRect();
- GUI.DrawTexture(new Rect(rect.x, rect.y + 2, 14, 14), image);
- rect.x += 18;
- rect.width -= 18;
- this.isExpanded.Value = SirenixEditorGUI.Foldout(rect, this.isExpanded.Value, label, styleCollapse);
- SirenixEditorGUI.EndBoxHeader();
- if (SirenixEditorGUI.BeginFadeGroup(this, this.isExpanded.Value))
- {
- for (int i = 0; i < this.Property.Children.Count; i++)
- {
- this.Property.Children[i].Draw();
- }
- }
- SirenixEditorGUI.EndFadeGroup();
- SirenixEditorGUI.EndBox();
- }
- }
- }
|