This commit is contained in:
SoulliesOfficial
2025-12-17 04:19:38 -05:00
parent 7c1cb7e8e1
commit d15957c719
4315 changed files with 8260710 additions and 2940 deletions

View File

@@ -0,0 +1,49 @@
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
namespace GraphicsCat
{
[CustomPropertyDrawer(typeof(AutoLoadAttribute))]
public class AutoLoadDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
AutoLoadAttribute autoLoad = attribute as AutoLoadAttribute;
EditorGUI.PropertyField(position, property, label);
if (property.objectReferenceValue == null)
{
if (!string.IsNullOrEmpty(autoLoad.assetGUID))
{
string assetPath = AssetDatabase.GUIDToAssetPath(autoLoad.assetGUID);
if (!string.IsNullOrEmpty(assetPath))
{
System.Type fieldType = fieldInfo.FieldType;
Object loadedAsset = AssetDatabase.LoadAssetAtPath(assetPath, fieldType);
if (loadedAsset != null)
{
property.objectReferenceValue = loadedAsset;
Debug.Log($"Auto-loaded asset '{loadedAsset.name}' for field '{property.displayName}' using GUID.");
}
else
{
Debug.LogWarning($"AutoLoadDrawer: Failed to load asset with GUID '{autoLoad.assetGUID}'.");
}
}
}
}
if (property.objectReferenceValue != null)
{
string assetPath = AssetDatabase.GetAssetPath(property.objectReferenceValue);
string guid = AssetDatabase.AssetPathToGUID(assetPath);
autoLoad.assetGUID = guid;
}
}
}
}
#endif