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 |
Tags
- rpg server
- java
- spread 연산자
- screencapture
- linux
- express
- Unity IAP
- react
- critical rendering path
- OverTheWire
- Google Refund
- MySQL
- Packet Network
- SDK upgrade
- mongoDB
- --watch
- docker
- Digital Ocean
- Camera Zoom
- Camera Movement
- draganddrop
- Git
- Unity Editor
- css framework
- server
- springboot
- Google Developer API
- nodejs
- unity
- Spring Boot
Archives
- Today
- Total
우당탕탕 개발일지
[Unity] Custom Editor - MenuItem을 만들어보자 본문
유니티에서 테스트를 하다보면 로컬데이터를 삭제해야하는 일이 굉장히 많은데, 파일탐색기에서 찾아가자니 너무 귀찮아서 유니티 에디터에서 그냥 클릭-클릭 삭제하는 방법이 없을까? 하다가 MenuItem이라는 것을 알게되었다.
using System;
using UnityEditor; //이게 꼭 필요하다
using UnityEngine;
public class ESATools : MonoBehaviour // 상단메뉴에 ESATools라고 나온다
{
[MenuItem("ESATools/Delete Local Data")]
static void DoSomething()
{
try
{
string path = Application.persistentDataPath + "/saves/";
FileUtil.DeleteFileOrDirectory(path); //폴더를 삭제할때
//System.IO.File.Delete(path); 파일을 삭제할때
Debug.Log("delete complete!");
}
catch(Exception e)
{
Debug.LogWarning("delete local file failed. " + e.Message);
}
}
}
생각보다 너무 간단하다..!
참고로 Sytem.IO.File.Delete() 는 파일만 가능하다. 나의 경우 saves 라는 폴더자체를 삭제하고싶기 떄문에 FileUtil.DeleteFileOrDirectory() 를 사용했다.
++ 추가
Addressable 빌드를 하려는데 이 스크립트에서 에러가 발생했다. MenuItem은 에디터에서만 사용 가능하므로, 스크립트 전체를
#if UNITY_EDITOR
using...
using..
pubilc class ..
{
}
#endfif
로 감싸도록 하자
'Unity' 카테고리의 다른 글
[Unity] 메일 문의하기 (1) | 2023.08.08 |
---|---|
[Unity] Android 앱 이름 Localization (0) | 2023.08.06 |
[Unity] Unity IAP 설정 (0) | 2023.07.19 |
[Unity ] GPGS & Firebase 총정리 (0) | 2023.07.11 |
[Unity] 빌드시 체크사항 (0) | 2023.07.04 |