유니티 버전 - 2022.3.59f1
목차
- 코드의 의도
- .gitignore 설정
- ApiConfig
코드의 의도
에디터에서 사용해야하는 Api 키를 빌드 혹은 git에 올리게 된다면 보안 취약점이 발생하기때문에, 에디터에서 사용하면서도 git에는 올라가지 않도록 하기 위함입니다
구글 시트의 데이터를 가져와 ScriptableObject를 만들기위한 키를 숨기기 위하여 작성하였습니다
.gitignore 설정
.gitignore를 텍스트 편집기로 열기
2. 제외하고자하는 파일이 있는 경로를 입력
- 파일이 루트가 아닌 에셋과 같이 하위 폴더에 존재하는 경우 전부 기재해야합니다
- 반드시 파일을 만들기 전에 .gitignore를 작성, 작성전에 만들어진 파일은 git에서 계속해서 추적합니다
ApiConfig
Assets/Settings/config.json의 값을 읽어와 필요한 때에 사용할 수 있도록 하였습니다, 물론 config.json파일은 로컬에만 존재하고 git에는 업로드 되어있지않습니다
using System.IO;
using UnityEngine;
#if UNITY_EDITOR
public static class ApiConfig
{
private const string Path = "Assets/Settings/config.json";
public static string GetGoogleSheetApiKey()
{
if (File.Exists(Path))
{
string json = File.ReadAllText(Path);
ConfigData config = JsonUtility.FromJson<ConfigData>(json);
return config.googleSheetApiKey;
}
Debug.LogError("config.json 파일이 존재하지 않습니다. config.sample.json을 참고하여 생성하세요.");
return null;
}
}
#endif
[System.Serializable]
public class ConfigData
{
public string googleSheetApiKey;
}
또한 config.sample.json을 업로드하여 협업시 config의 작성법을 명시하여줍니다
{
"googleSheetApiKey": "key"
}
'코드 및 공부 > 기타' 카테고리의 다른 글
GPT를 이용한 내 코드 작성 경향과 약점 개선하기 (1) | 2025.04.21 |
---|---|
CS0162: Unreachable code detected, 이 코드가 경험적으로 도달할 수 없습니다 (0) | 2025.03.13 |
Application 클래스 (0) | 2025.03.13 |
컴파일 경고 끄기 (#pragma warning disable 0000) (0) | 2025.01.17 |
The type or namespace name 'EditorWindow' 오류 (0) | 2025.01.09 |