Unity/코드 예제들
프리팹 저장하기
소나무꼴
2022. 6. 21. 15:46
에디트 상에서 선택된 프리팹이 저장할 일이 있을때 사용.
컴퍼넌트 데이터들이 변경되어도 Save 버튼이 활성화 되지 않는 경우가 있어서 제작
PrefabUtility.SavePrefabAsset(eff.gameObject, out isSuccess);
/*
#if UNITY_2021_2_OR_NEWER
var stage = UnityEditor.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();
#elif UNITY_2018_3_OR_NEWER
var stage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();
#endif
#if UNITY_2018_3_OR_NEWER
if (stage != null && stage.scene.isLoaded)
{
#if UNITY_2020_1_OR_NEWER
string prefabAssetPath = stage.assetPath;
#else
string prefabAssetPath = stage.prefabAssetPath;
#endif
PrefabUtility.SaveAsPrefabAsset(stage.prefabContentsRoot, prefabAssetPath);
}
else
{
bool isSuccess = false;
PrefabUtility.SavePrefabAsset(eff.gameObject, out isSuccess);
Debug.Log($"저장 여부 {isSuccess}");
}
#endif
*/