인프런 커뮤니티 질문&답변
로컬 알림과 다국어 지원에 대해 궁금합니다.
해결된 질문
작성
·
53
0
안녕하세요.
유니티 시스템 프로그래밍 파트 1, 파트 2 강의 잘 듣고 있습니다. (두개 모두 번갈아 가며 필요한 부분 먼저 듣고 있는 상태입니다. )
모바일 게임 서비스에 중요한 요소중에 하나로 로컬 알림과 서버 알림이 있는데 이 중에서도 로컬 알림에 대한 강의는 없는 것 같습니다. 혹시 제가 못 찾은 건지 아니면 이 강의가 없다면 추가로 강의를 만들어주실 수 있으신지 궁금합니다.
다국어 부분에서 CSV 파일을 로드해서 각 나라에 맞게 언어를 바꾸고 있긴 한데 CSV 파일 내 문자열에서 , 가 포함되어 있는 경우는 문제가 되지 않을까 싶습니다. 혹시 이런 경우일 때 어떻게 처리를 하실지 궁금합니다.
이상입니다.
유용한 강의 감사드립니다~
답변 2
0
안녕하세요! BurningCarrot입니다. 문의해 주신 내용에 답변 드립니다.
로컬 알림
제가 이전에 사용하던 코드를 공유 드리겠습니다.
로컬 알림 sdk 다운로드
Package Manager에서 Mobile Notifications로 검색해서 설치아래 코드를 싱글턴 게임 오브젝트로 적용
LocalNotifyType은 수강생분이 새로운 로컬 알림을 추가하실 때마다 타입을 추가하시면 되겠습니다. 하트(자원) 충전, 가챠(뽑기) 박스 충전 등 알림의 종류를 의미하는 값입니다. 각 타입마다 적용해 주실 ID값을 적절하게 설정해 주세요. 저는 예시로 TypeA, TypeB, TypeC 이런식으로 표기해 두었습니다. 게임이 중단되거나 종료될 때 디바이스 플랫폼에 따라 알림이 실행되어야 할 시간을 계산해서 SetAOSNotification, SetIOSNotification 함수를 호출하시면 될 것입니다. 유니티 매뉴얼 링크도 같이 첨부 드립니다. https://docs.unity3d.com/Packages/com.unity.mobile.notifications@1.0/manual/index.html
#if UNITY_ANDROID
using Unity.Notifications.Android;
#elif UNITY_IOS
using Unity.Notifications.iOS;
#endif
using System.Collections;
using System;
public enum LocalNotifyType
{
TYPE_A,
TYPE_B,
TYPE_C
}
public class LocalNotificationManager : SingletonBehaviour<LocalNotificationManager>
{
private string m_IOSTypeAID = string.Empty;
private string m_IOSTypeBID = string.Empty;
private string m_IOSTypeCID = string.Empty;
protected override void Init()
{
base.Init();
#if UNITY_ANDROID
InitAOS();
#elif UNITY_IOS
InitIOS();
#endif
}
public void SetNotification(LocalNotifyType notifyType, string notiTitle, string notiText, int days, int hours, int minutes, int seconds)
{
#if UNITY_ANDROID
SetAOSNotification(notifyType, notiTitle, notiText, days, hours, minutes, seconds);
#elif UNITY_IOS
SetIOSNotification(notifyType, notiTitle, notiText, days, hours, minutes, seconds);
#endif
}
public void CancelAllNotification()
{
#if UNITY_ANDROID
CancelAllAOSNotification();
#elif UNITY_IOS
CancelAllIOSNotification();
#endif
}
#region AOS
private void InitAOS()
{
#if UNITY_ANDROID
AndroidNotificationCenter.Initialize();
var typeAChannel = new AndroidNotificationChannel()
{
Id = "AOS_TypeA_Id",
Name = "AOS_TypeA_Channel",
Importance = Importance.Default,
Description = "AOS_TypeA_Notification",
};
AndroidNotificationCenter.RegisterNotificationChannel(typeAChannel);
var typeBChannel = new AndroidNotificationChannel()
{
Id = "AOS_TypeB_Id",
Name = "AOS_TypeB_Channel",
Importance = Importance.Default,
Description = "AOS_TypeB_Notification",
};
AndroidNotificationCenter.RegisterNotificationChannel(typeBChannel);
var typeCChannel = new AndroidNotificationChannel()
{
Id = "AOS_TypeC_Id",
Name = "AOS_TypeC_Channel",
Importance = Importance.Default,
Description = "AOS_TypeC_Notification",
};
AndroidNotificationCenter.RegisterNotificationChannel(typeCChannel);
#endif
}
private void SetAOSNotification(LocalNotifyType notifyType, string notiTitle, string notiText, int days, int hours, int minutes, int seconds)
{
#if UNITY_ANDROID
var notification = new AndroidNotification();
notification.SmallIcon = "small_icon";
notification.LargeIcon = "large_icon";
notification.Title = notiTitle;
notification.Text = notiText;
notification.FireTime = DateTime.Now.AddDays(days).AddHours(hours).AddMinutes(minutes).AddSeconds(seconds);
switch (notifyType)
{
case LocalNotifyType.TYPE_A:
AndroidNotificationCenter.SendNotification(notification, "AOS_TypeA_Id");
break;
case LocalNotifyType.TYPE_B:
AndroidNotificationCenter.SendNotification(notification, "AOS_TypeB_Id");
break;
case LocalNotifyType.TYPE_C:
AndroidNotificationCenter.SendNotification(notification, "AOS_TypeC_Id");
break;
default:
break;
}
#endif
}
private void CancelAllAOSNotification()
{
#if UNITY_ANDROID
AndroidNotificationCenter.CancelAllNotifications();
#endif
}
#endregion
#region IOS
private void InitIOS()
{
StartCoroutine(RequestAuthorization());
}
private IEnumerator RequestAuthorization()
{
#if UNITY_IOS
using (var req = new AuthorizationRequest(AuthorizationOption.Alert | AuthorizationOption.Badge, true))
{
while (!req.IsFinished)
{
yield return null;
};
string res = "\n RequestAuthorization: \n";
res += "\n finished: " + req.IsFinished;
res += "\n granted : " + req.Granted;
res += "\n error: " + req.Error;
res += "\n deviceToken: " + req.DeviceToken;
Logger.Log(res);
}
#endif
yield return null;
}
private void SetIOSNotification(LocalNotifyType notifyType, string notiTitle, string notiText, int days, int hours, int minutes, int seconds)
{
#if UNITY_IOS
var timeTrigger = new iOSNotificationTimeIntervalTrigger()
{
TimeInterval = new TimeSpan(days, hours, minutes, seconds),
Repeats = false
};
var identifier = string.Empty;
var categoryIdentifier = string.Empty;
var threadIdentifier = string.Empty;
switch (notifyType)
{
case LocalNotifyType.TYPE_A:
identifier = "IOS_TypeA_Id";
categoryIdentifier = "Category_TypeA";
threadIdentifier = "Thread_TypeA";
m_IOSTypeAID = identifier;
break;
case LocalNotifyType.TYPE_B:
identifier = "IOS_TypeB_Id";
categoryIdentifier = "Category_TypeB";
threadIdentifier = "Thread_TypeB";
m_IOSTypeBID = identifier;
break;
case LocalNotifyType.TYPE_C:
identifier = "IOS_TypeC_Id";
categoryIdentifier = "Category_TypeC";
threadIdentifier = "Thread_TypeC";
m_IOSTypeCID = identifier;
break;
default:
break;
}
var notification = new iOSNotification()
{
Identifier = identifier,
Title = notiTitle,
Body = notiText,
ShowInForeground = true,
ForegroundPresentationOption = (PresentationOption.Alert | PresentationOption.Sound),
CategoryIdentifier = categoryIdentifier,
ThreadIdentifier = threadIdentifier,
Trigger = timeTrigger,
};
iOSNotificationCenter.ScheduleNotification(notification);
#endif
}
private void CancelIOSNotification(LocalNotifyType notifyType)
{
#if UNITY_IOS
var notifyID = string.Empty;
switch (notifyType)
{
case LocalNotifyType.TYPE_A:
notifyID = m_IOSTypeAID;
break;
case LocalNotifyType.TYPE_B:
notifyID = m_IOSTypeBID;
break;
case LocalNotifyType.TYPE_C:
notifyID = m_IOSTypeCID;
break;
default:
break;
}
iOSNotificationCenter.RemoveScheduledNotification(notifyID);
#endif
}
private void CancelAllIOSNotification()
{
#if UNITY_IOS
iOSNotificationCenter.RemoveAllScheduledNotifications();
iOSNotificationCenter.RemoveAllDeliveredNotifications();
#endif
}
#endregion
}CSV 파일 내 문자열에서 ,
CSV파일에서 그냥 전체 문자열을 ""로 감싸주시면 됩니다. "안녕하세요, BurningCarrot입니다." 이렇게 해주시면 됩니다.
0
안녕하세요, 인프런 AI 인턴입니다. 크리스팍님.
먼저, 유니티 시스템 프로그래밍 강의를 열심히 수강해주셔서 감사합니다. 질문하신 내용에 대해 답변드리겠습니다.
- 로컬 알림:
로컬 알림은 모바일 게임에서 중요한 요소 중 하나로, 게임의 재방문율을 증가시키는 데 매우 유용합니다. 현재 강의에서는 로컬 알림에 대한 직접적인 내용이 포함되어 있지 않을 수 있습니다. 이런 경우, Unity에서의 로컬 알림은 ‘Unity Notification’ 패키지를 사용하여 구현할 수 있습니다. 해당 패키지를 활용하면 여러 플랫폼(iOS, Android)에서 로컬 알림을 손쉽게 설정할 수 있습니다. 다만, 강의의 확장 여부는 강사님께 별도로 요청하셔야 할 수도 있습니다.
- CSV 파일 내 문자열 처리:
CSV 파일 사용 시, 문자열 내에 , 등의 구분자가 포함되어 있을 때 문제가 발생할 수 있습니다. 일반적으로 이를 해결하기 위해 다음과 같은 방법들이 사용됩니다:
- 따옴표로 문자열 감싸기: CSV 파일 내에서 문자열을 큰따옴표(
" ")로 감싸면, 그 내부의,는 데이터의 일부로 인식됩니다.
- CSV 파서 사용: Unity용 CSV 파서나 외부 라이브러리를 사용하여 CSV 파일을 읽어들일 때, 자동으로 따옴표를 처리하도록 설정합니다.
이와 관련하여 기존의 CSV 처리 방법에 대한 자세한 설명과 코드 구현 사례를 찾아보실 수 있는 관련된 질문과 답변들을 추천드립니다:
저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다.
현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏
추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.





참고해서 다시 구현해보도록 하겠습니다~!!
답변 감사합니다~!! 많은 도움이 되었습니다~