Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Editor/Builders/AssetsItemBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using TNRD.Utilities;
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
using UnityEngine.Assertions;

namespace TNRD.Builders
Expand Down Expand Up @@ -37,6 +38,12 @@ public AdvancedDropdownItem Build()
{
CreateItemForPath(root, assetPath);
}
else if (assetType == typeof(GameObject))
{
GameObject gameObject = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I have a feeling that this might become very slow for larger projects

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, so much so that I ended up making this: #57
If this is to remain I think it would be very nice with a setting to exclude this behaviour, as it is very painful for me to wait like 5 seconds for the dropdown to open haha

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof yeah that is pretty bad! I'll have a look at your PR!

Copy link
Contributor Author

@marc-antoine-girard marc-antoine-girard Nov 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sorry about that! It became so slow in our project that we had to comment it out. We were looking in a way to stream the assets instead of loading them. I believe the new Search package in Unity does that, but I'm not sure how to use their API yet.

Edit: Had we had the Preference window, I think it would've made sense to have Prefab lookup disabled by default. In small project, I'm sure it can have value, but it sure doesn't scale well.

if (gameObject.GetComponent(interfaceType) != null)
CreateItemForPath(root, assetPath);
}
}

return root;
Expand Down
6 changes: 1 addition & 5 deletions Editor/Drawers/RawReferenceDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,13 @@ private void AvoidDuplicateReferencesInArray()
if (previousPropertyPath == Property.propertyPath)
return;

SerializedProperty rawReferenceProperty = Property.FindPropertyRelative("rawReference");
object currentReferenceValue = RawReferenceValue;

if (currentReferenceValue == null)
return;

if (previousReferenceValue == currentReferenceValue)
{
RawReferenceValue = CreateInstance(currentReferenceValue);
rawReferenceProperty.serializedObject.ApplyModifiedProperties();
}
PropertyValue = CreateInstance(currentReferenceValue);

previousReferenceValue = currentReferenceValue;
}
Expand Down
12 changes: 10 additions & 2 deletions Editor/Drawers/ReferenceDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected object PropertyValue
UnityReferenceProperty.objectReferenceValue = null;
break;
case ReferenceMode.Unity:
UnityReferenceProperty.objectReferenceValue = (Object)value;
UnityReferenceProperty.objectReferenceValue = GetUnityObject((Object)value);
RawReferenceValue = null;
break;
default:
Expand Down Expand Up @@ -138,6 +138,7 @@ private void OnClicked()

private void OnDeletePressed()
{
ModeValue = default;
PropertyValue = null;
}

Expand Down Expand Up @@ -199,7 +200,7 @@ private void HandleDragUpdated()
{
Type scriptType = monoScript.GetClass();

if (scriptType.IsSubclassOf(typeof(UnityEngine.Object)))
if (scriptType.IsSubclassOf(typeof(Object)))
{
SetDragAndDropMode(false);
return;
Expand Down Expand Up @@ -238,6 +239,13 @@ private void HandleDragPerform()
}
}

private Object GetUnityObject(Object objectReference)
{
if(objectReference is GameObject gameObject)
return gameObject.GetComponent(GenericType);
return objectReference;
}

protected abstract void PingObject();
}
}