Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- draganddrop
- Google Refund
- nodejs
- unity
- docker
- screencapture
- Git
- server
- MySQL
- springboot
- Unity Editor
- Camera Zoom
- react
- spread 연산자
- express
- Spring Boot
- OverTheWire
- SDK upgrade
- Google Developer API
- linux
- css framework
- mongoDB
- rpg server
- Digital Ocean
- critical rendering path
- Unity IAP
- java
- --watch
- Packet Network
- Camera Movement
Archives
- Today
- Total
우당탕탕 개발일지
[Unity] CustomEditor - 자동으로 addressable 활성화하기 본문
scriptableObject를 사용하면서, SkillData를 상속받은 여러 종류의 스킬들을 정의했다(strikeSkill , rangeSkill, buffSkill등등..)
나는 addressable을 로드하기때문에 각 scriptableObject의 addressable을 활성화하고 라벨을 설정해야하는데, 이걸 자동으로 설정하게끔 만들어보았다.
OnEnable() 과 OnInspectorGUI() 호출시, addressable이 활성화되지않았다면 활성화 후 , 내가원하는 label을 지정해준다.
라벨 설정할때, entry.label.clear()을 해주는데, 종종 동일한라벨이 여러개 설정되는 버그가 있어서 clear후 새로 넣어주는 방법으로 변경했다.
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEditor.AddressableAssets;
using UnityEditor.AddressableAssets.Settings;
using UnityEngine;
[CustomEditor(typeof(SkillData), true)]
public class SkillDataEditor : Editor
{
protected virtual void OnEnable()
{
//...
skillData = (SkillData)target;
EnforceAddressable();
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EnforceAddressable();
serializedObject.ApplyModifiedProperties();
}
private void EnforceAddressable()
{
AddressableAssetSettings settings = AddressableAssetSettingsDefaultObject.Settings;
if (settings == null)
{
Debug.LogError("Addressable 설정을 찾을 수 없습니다.");
return;
}
// SkillData가 저장된 에셋인지 확인 (메모리에만 있는 경우 무시)
if (!EditorUtility.IsPersistent(skillData)) return;
// SkillData의 Asset Path 가져오기 (파일 전체 경로)
string assetPath = AssetDatabase.GetAssetPath(skillData.GetInstanceID());
if (string.IsNullOrEmpty(assetPath))
{
Debug.LogError("SkillData의 Asset Path를 찾을 수 없습니다.");
return;
}
// Addressable 설정 확인 및 적용
string guid = AssetDatabase.AssetPathToGUID(assetPath);
AddressableAssetEntry entry = settings.FindAssetEntry(guid);
// Addressable이 이미 정상적으로 설정되어 있다면 중간에서 return
if (entry != null && entry.address == assetPath && entry.labels.Count == 1 && entry.labels.Contains("skillDatas")) return;
// Addressable이 설정되지 않은 경우 자동 추가
if (entry == null) entry = settings.CreateOrMoveEntry(guid, settings.DefaultGroup);
// Addressable 이름을 에셋 경로(Assets/...)로 강제 설정
if (entry.address != assetPath) entry.address = assetPath;
entry.labels.Clear();
entry.SetLabel("skillDatas", true, true);
// 변경 사항 저장
settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryModified, entry, true);
AssetDatabase.SaveAssets();
}
}
'Unity' 카테고리의 다른 글
[Unity] CustomEditor - Dictionary 사용하기 (0) | 2025.03.17 |
---|---|
[Unity] Custom Editor - enum값을 dropdown에서 선택하기 + 원하는값만 나타내기 (0) | 2025.03.17 |
[Unity][Build Err] ClassNotFoundException: com.google.android.gms.ads.initialization (0) | 2024.11.14 |
[Unity] ScreenShot 촬영 및 저장하기 (0) | 2024.08.11 |
[Unity] 스크린샷 및 갤러리에 저장하기 (0) | 2024.05.08 |