ProjectDDD/Assets/0.Datas/02.Scripts/GenerateGoogleSheet/Core/GoogleSheetAddressableAutoSetup.cs

66 lines
2.1 KiB (Stored with Git LFS)
C#

#if UNITY_EDITOR
using System.IO;
using UnityEditor;
using UnityEditor.AddressableAssets;
using UnityEditor.AddressableAssets.Settings;
using UnityEditor.AddressableAssets.Settings.GroupSchemas;
using UnityEngine;
public static class GoogleSheetAddressableAutoSetup
{
private const string TargetGroupName = "GoogleSheetSo_Group";
private const string TargetLabel = "GoogleSheetSo";
public static void AutoRegisterSo(string assetPath)
{
var settings = AddressableAssetSettingsDefaultObject.Settings;
if (settings == null)
{
Debug.LogError("Addressable 설정을 찾을 수 없습니다.");
return;
}
string guid = AssetDatabase.AssetPathToGUID(assetPath);
if (string.IsNullOrEmpty(guid)) return;
// 그룹 가져오기 또는 생성
var group = settings.FindGroup(TargetGroupName);
if (group == null)
{
group = settings.CreateGroup(TargetGroupName, false, false, false, null,
typeof(BundledAssetGroupSchema), typeof(ContentUpdateGroupSchema));
var bundledSchema = group.GetSchema<BundledAssetGroupSchema>();
bundledSchema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackTogether;
}
// 엔트리 추가
var entry = settings.FindAssetEntry(guid);
if (entry == null)
{
entry = settings.CreateOrMoveEntry(guid, group);
}
else if (entry.parentGroup != group)
{
settings.MoveEntry(entry, group);
}
// Address 설정
string name = Path.GetFileNameWithoutExtension(assetPath);
entry.address = name;
// Label 설정
if (!entry.labels.Contains(TargetLabel))
{
entry.SetLabel(TargetLabel, true, true);
}
// 저장
EditorUtility.SetDirty(settings);
settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, entry, true);
AssetDatabase.SaveAssets();
Debug.Log($"✅ Addressables에 등록 완료: {name}, 그룹: {TargetGroupName}, 라벨: {TargetLabel}");
}
}
#endif