Skip to content

Commit 84cf011

Browse files
authored
Expandable Inline Editor for Unity Objects (#32)
* expandable inline editor for unity objects * package references added * pushable layer added * fixes for ExpandablePropertyDrawer and items in item adapters now expandable
1 parent e35e709 commit 84cf011

File tree

11 files changed

+311
-103
lines changed

11 files changed

+311
-103
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using Core.Common;
2+
using UnityEditor;
3+
using UnityEngine;
4+
5+
namespace Core.Editor
6+
{
7+
[CustomPropertyDrawer(typeof(ExpandableAttribute))]
8+
public class ExpandablePropertyDrawer : PropertyDrawer
9+
{
10+
private UnityEditor.Editor _editor;
11+
12+
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
13+
{
14+
float width = position.width;
15+
16+
position.width = 0.05f * width;
17+
18+
property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, GUIContent.none);
19+
20+
position.x += position.width;
21+
22+
position.width = width - position.width;
23+
24+
EditorGUI.PropertyField(position, property, label, true);
25+
26+
if (property.objectReferenceValue == null)
27+
{
28+
return;
29+
}
30+
31+
if (property.isExpanded)
32+
{
33+
if (!_editor)
34+
{
35+
UnityEditor.Editor.CreateCachedEditor(property.objectReferenceValue, null, ref _editor);
36+
}
37+
38+
EditorGUILayout.BeginVertical(GUI.skin.box);
39+
40+
_editor.OnInspectorGUI();
41+
42+
EditorGUILayout.EndVertical();
43+
}
44+
}
45+
}
46+
}

Packages/com.ekaka.core/Editor/ExpandablePropertyDrawer.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using UnityEngine;
5+
6+
namespace Core.Common
7+
{
8+
[AttributeUsage(AttributeTargets.Field)]
9+
10+
public class ExpandableAttribute : PropertyAttribute
11+
{
12+
public ExpandableAttribute()
13+
{
14+
15+
}
16+
}
17+
}

Packages/com.ekaka.core/Runtime/Common/ExpandableAttribute.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/com.ekaka.inventory/Runtime/Main/Item/Item.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Inventory.Main.Item
1212
[Serializable]
1313
public abstract class Item<T> : IItem where T : ItemReference
1414
{
15-
[SerializeField] protected T reference;
15+
[SerializeField, Expandable] protected T reference;
1616

1717
[SerializeField] [HideInInspector] private string id = Utils.NewGuid();
1818

SampleProject/Assets/Samples/Player/0.0.1/Universal RP Demo/Prefabs/Player.prefab

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1883,6 +1883,7 @@ MonoBehaviour:
18831883
<TargetGroup>k__BackingField: {fileID: 5590362405879292995}
18841884
<Targeter>k__BackingField: {fileID: 0}
18851885
<Vitality>k__BackingField:
1886+
<Immutable>k__BackingField: 0
18861887
<LowerLimit>k__BackingField: 0
18871888
<FullValue>k__BackingField: 100
18881889
<Death>k__BackingField: {fileID: 4702685486435802194}
@@ -1899,6 +1900,7 @@ MonoBehaviour:
18991900
<Invulnerable>k__BackingField: 0
19001901
<Value>k__BackingField: 0
19011902
<Endurance>k__BackingField:
1903+
<Immutable>k__BackingField: 0
19021904
<LowerLimit>k__BackingField: 0
19031905
<FullValue>k__BackingField: 100
19041906
<RecoveryRate>k__BackingField: 2
@@ -1933,7 +1935,7 @@ MonoBehaviour:
19331935
m_EditorClassIdentifier:
19341936
pushLayers:
19351937
serializedVersion: 2
1936-
m_Bits: 64
1938+
m_Bits: 128
19371939
canPush: 1
19381940
interpolate: 1
19391941
strength: 5

0 commit comments

Comments
 (0)