유니티(unity)
[unity/Simple Disk Utils]ios/android/windows 남은 용량 확인(with source)
개발자 고포고
2024. 2. 7. 16:23
반응형
[unity/Simple Disk Utils]ios/android/windows 남은 용량 확인(with source)
https://assetstore.unity.com/packages/tools/simple-disk-utils-59382
Simple Disk Utils | 도구 | Unity Asset Store
Get the Simple Disk Utils package from Dikra Prasetya and speed up your game development process. Find this & other 도구 options on the Unity Asset Store.
assetstore.unity.com
위 어셋을 활용하여 최적화 하였다. 이미 위 코드만으로도 코드가 잘 정리되어있지만 남아있는 용량에 대한 부분만 필요해서 활용하였다.
#응용 코드
public class DiskUtilsHelper : MonoBehaviour {
[SerializeField]
Text text;
string obj = "A";
void Update(){
if (obj.Length >= 3000000)
return;
obj += obj;
if (obj.Length < 3000000)
return;
StartCoroutine(GetAvailStorage());
}
void PrintStorageStats () {
int megabytes = DiskUtils.CheckAvailableSpace();
double gigabytes = megabytes / 1024.0; // MB를 GB로 변환
gigabytes = Math.Round(gigabytes, 2);
text.text = $"{gigabytes} GB";
}
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
void PrintStorageStats(string drive)
{
int megabytes = DiskUtils.CheckAvailableSpace(drive);
double gigabytes = megabytes / 1024.0; // MB를 GB로 변환
gigabytes = Math.Round(gigabytes, 2);
text.text = $"{gigabytes} GB";
}
#endif
IEnumerator GetAvailStorage()
{
foreach (string drive in DiskUtils.GetDriveNames())
{
PrintStorageStats(
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
drive
#endif
);
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
}
#endif
yield return null;
}
}
#unity #남은 용량 #ios #android #Simple Disk Utils
반응형