시작하기
필수 변경사항
샘플 코드를 다운로드 받으면 반드시 channelKey
값을 변경해야 합니다.
하단의 설명을 통해서 변경할 부분을 확인하여서 변경해주시면 됩니다.
소스코드를 다운로드 후 진행
- CMS 화면에서 개설한 채팅방의
Channel Key
를 복사합니다. - Unity SDK를 Unity Hub 로 빈 3D 프로젝트를 생성합니다.
- 패키지 매니져를 이용해 git 으로 https://github.com/PimDeWitte/UnityMainThreadDispatcher.git 를 추가합니다.
- 패키지 매니져를 이용해 git 으로 https://github.com/e7works-git/vchatcloud-unity-sample.git 를 추가합니다.
- 추가된 VChatCloudUnitySDK 패키지의 /Runtime 밑의 내용들을 Asset 에 복사하여 추가해줍니다.
- Asset/Plugins/UnityVChat.cs 파일을 열고
room_id
라는 변수명 값에 1번에서 복사한 key 값을 붙여 넣어줍니다.nick_name
에는 채팅방에서 사용할 닉네임을 정하여 넣어줍니다.
cs
private async Task ConnectAndJoinRoomAsync()
{
// 방 접속을 위한 값 생성
room_id = "YOUR_ROOM_ID";
nick_name = "U-User";
1
2
3
4
5
6
7
2
3
4
5
6
7
:::
VChatCloud 객체
VChatCloud 클래스
VChatCloud 인스턴스는 싱글톤으로 호출이 가능합니다.
cs
VChatCloud.getInstance()
1
channel 메소드 선언
channel는 VChatCloud 인스턴스에 구현된 메소드입니다.
channel 메소드를 이용하여 채팅방에 진입하고, 메시지 이벤트들을 컨트롤할 수 있습니다.
아래 코드는 채팅방 진입만 다루고 있고, 메시지 전송, 공지등은 자세한 이벤트 설명은 좌측 메뉴리스트의 메시지
를 참고해주세요.
cs
channel = VChatCloud.GetInstance().JoinChannel(options, new JoinChannelCallbackImpl((history, e) =>
{
}));
channel.SetHandler(new MessageHandlerEx(this));
1
2
3
4
5
6
2
3
4
5
6
파라미터 값(options)
값 식별자 설명 ChannelKey String 채팅방 생성 후 발급받은 Channel Key ClientKey String 접속 단말 설정 고유키 NickName String 채팅방 입장 유저의 별명 UserInfo String 유저 프로필정보 결과 값
- error
값 식별자 설명 code String 에러 코드 type String 에러 타입 message String 에러 메시지 - history
값 식별자 설명 logType String 로그타입 roomId String 채팅방 생성 후 발급받은 Channel Key clientKey String 접속 단말 설정 고유키 message String 메시지내용 mimeType String 메시지형태 (text: 일반텍스트, emoji: 이모지) messageType String 빈값이면 일반 메시지, 공지일경우 : "notice" nickName String 채팅방 입장 유저의 별명 date String 전송시간 grade String 유저등급