반응형
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
- 유니티 해상도 고정
- ilviewer
- 엑셀 가져오기
- 알고리즘
- 유니티
- 스프레드시트 사용법
- 한달리뷰
- 진수 변환기
- git
- 라이더
- C#
- 다른 시트값
- ilcode
- navmesh
- navmeshagent
- 스프레드시트
- 다각형 중점
- 테크스트림
- 무장cg추가하기
- Rider
- Mac
- rider 설치
- 엑셀 내보내기
- cmd키 변경
- monocraft
- 백준
- 스프레드 시트
- unity
- unity 받기
- unity 구버전
Archives
- Today
- Total
코스모스 공작소
[Unity] Asset 내부 파일 유니티 에디터에서 복사하기 본문
반응형
안녕하세요! 오늘은 Unity 에디터 내부에서 파일을 복제하는 방법에 대해 알아보겠습니다!
물론 컨트롤 + c / 컨트롤 + v 하면 복사가 되지만 일부 안되거나 특수한 복사 환경일 때를 위해 구현해 놓은 방법입니다.
1. 코드 작성
using System.IO;
using UnityEditor;
using UnityEngine;
public class DuplicateManager : MonoBehaviour
{
[MenuItem("Assets/Duplicate")]
public static void StartDuplicate()
{
Debug.Log("Start_ Duplicate");
Debug.Log(AssetDatabase.GetAssetPath(Selection.activeObject));
if (Selection.count != 1)
{
Debug.Log("Only 1 File");
return;
}
string strDataPath = Application.dataPath;
string strFilePath = AssetDatabase.GetAssetPath(Selection.activeObject);
string strFullOriginPath = "";
string strFileoriginFileName = "";
if (strDataPath.Contains("Assets"))
{
strDataPath = strDataPath.Substring(0, strDataPath.Length - "Assets".Length);
strFullOriginPath = strDataPath + strFilePath;
FileInfo file = new FileInfo(strFullOriginPath); // 전체 경로를 받기 위해 생성
strFileoriginFileName = file.Name;
int index = 1;
while (true)
{
string fileNameTemp = Selection.activeObject.name;
string extention = Path.GetExtension(strFullOriginPath); // 확장자 분리
fileNameTemp += $" ({index})"; // {파일 이름} (index)
string strDestFileName = fileNameTemp + extention; // 복사된 파일의 이름
string strdest = strFilePath.Substring(0, strFilePath.Length - strFileoriginFileName.Length); // 복사된 파일의 경로
FileInfo file_Info = new FileInfo(strdest + strDestFileName); // 복사한 파일이 현재 경로에 있는지 확인용
if (file_Info.Exists) // 복사할 파일의 번호가 있으면 index 상승
{
index++;
continue;
}
AssetDatabase.CopyAsset(strFilePath, strdest + strDestFileName); // 원본 경로, 새로 생성할 파일의 경로
break;
}
}
}
}
스크립트를 하나 만들어서 위 코드를 넣습니다. AssetDatabase.CopyAsset 를 이용하기 때문에 FullPath를 이용하지는 않습니다.
2. 복사하기
코드를 저장하고 유니티를 리프레시하면 duplicate 항목이 노출됩니다.
이렇게 복제가 끝이 납니다.
지금까지 유니티 에디터 내부에서 파일을 복제하는 방법에 대해 알아보았습니다. 작업 중 컨트롤 C로 복제가 먹질 않는 문제가 있었는데 매번 씬에 넣었다가 저장하고 그러기가 너무 귀찮고 번거로워서 제작했습니다.. 복제할때 뭔가 중간에 체크해야할 것들이 있다던지 수행할 동작을 넣을때 요긴하게 쓰일 수도 있겠습니다. 감사합니다!

반응형
'프로그래밍 > Unity' 카테고리의 다른 글
[Unity] 유니티 테크 스트림 다운 받아보기 (0) | 2023.10.05 |
---|---|
[Unity] ScriptableObject 이용해서 데이터 만들고 사용해보기 (0) | 2023.09.29 |
[Unity] 프로젝트 패키지파일로 Export하기 (0) | 2023.09.10 |
[Unity] 다각형의 중점 구하기 (0) | 2023.07.22 |
[Unity] Unity 구버전 받기 (0) | 2023.07.21 |
Comments