Skip to content

Commit 229a645

Browse files
authored
Merge pull request #35 from marc-antoine-girard/#34-Add-Prefabs-AssetsItemBuilder
2 parents 29411d2 + b7799d5 commit 229a645

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

Editor/Builders/AssetsItemBuilder.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using TNRD.Utilities;
55
using UnityEditor;
66
using UnityEditor.IMGUI.Controls;
7+
using UnityEngine;
78
using UnityEngine.Assertions;
89

910
namespace TNRD.Builders
@@ -37,6 +38,12 @@ public AdvancedDropdownItem Build()
3738
{
3839
CreateItemForPath(root, assetPath);
3940
}
41+
else if (assetType == typeof(GameObject))
42+
{
43+
GameObject gameObject = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
44+
if (gameObject.GetComponent(interfaceType) != null)
45+
CreateItemForPath(root, assetPath);
46+
}
4047
}
4148

4249
return root;

Editor/Drawers/RawReferenceDrawer.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,13 @@ private void AvoidDuplicateReferencesInArray()
101101
if (previousPropertyPath == Property.propertyPath)
102102
return;
103103

104-
SerializedProperty rawReferenceProperty = Property.FindPropertyRelative("rawReference");
105104
object currentReferenceValue = RawReferenceValue;
106105

107106
if (currentReferenceValue == null)
108107
return;
109108

110109
if (previousReferenceValue == currentReferenceValue)
111-
{
112-
RawReferenceValue = CreateInstance(currentReferenceValue);
113-
rawReferenceProperty.serializedObject.ApplyModifiedProperties();
114-
}
110+
PropertyValue = CreateInstance(currentReferenceValue);
115111

116112
previousReferenceValue = currentReferenceValue;
117113
}

Editor/Drawers/ReferenceDrawer.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected object PropertyValue
8181
UnityReferenceProperty.objectReferenceValue = null;
8282
break;
8383
case ReferenceMode.Unity:
84-
UnityReferenceProperty.objectReferenceValue = (Object)value;
84+
UnityReferenceProperty.objectReferenceValue = GetUnityObject((Object)value);
8585
RawReferenceValue = null;
8686
break;
8787
default:
@@ -138,6 +138,7 @@ private void OnClicked()
138138

139139
private void OnDeletePressed()
140140
{
141+
ModeValue = default;
141142
PropertyValue = null;
142143
}
143144

@@ -199,7 +200,7 @@ private void HandleDragUpdated()
199200
{
200201
Type scriptType = monoScript.GetClass();
201202

202-
if (scriptType.IsSubclassOf(typeof(UnityEngine.Object)))
203+
if (scriptType.IsSubclassOf(typeof(Object)))
203204
{
204205
SetDragAndDropMode(false);
205206
return;
@@ -238,6 +239,13 @@ private void HandleDragPerform()
238239
}
239240
}
240241

242+
private Object GetUnityObject(Object objectReference)
243+
{
244+
if(objectReference is GameObject gameObject)
245+
return gameObject.GetComponent(GenericType);
246+
return objectReference;
247+
}
248+
241249
protected abstract void PingObject();
242250
}
243251
}

0 commit comments

Comments
 (0)