# Overview

# Unity

vchatCloud sdk는 채팅 클라이언트 구현을 쉽게 할 수 있도록 도와줍니다.
Unity에서 vchatCloud sdk를 이용하여 실시간 채팅을 빠르고 효율적으로 사용해보세요.
퀵 가이드에서는 vchatCloud sdk의 구조 및 기능에 대한 간략한 내용을 안내하고 있고,
각 항목에서는 자세한 설명을 바탕으로 실무 프로젝트에 적용하기위한 가이드를 제공하고 있습니다.

# 채팅서비스 체험하기

# 채팅방 진입

    # 채팅 하기

      # 구현코드 확인

      # 채팅방 진입

      // UnityVChat.cs
      public class UnityVChat : MonoBehaviour
      {
      
          [SerializeField]
          private TextField chatInput;
      
          [SerializeField]
          private Button sendButton;
      
          [SerializeField]
          private ScrollView chatScrollView;
      
          public string deviceUuid;
          private string room_id;
          private string nick_name;
          private string profile;
          private static JObject userInfo = null;
          private static Channel channel = null;
          private ChannelOptions options;
          
          private async void OnEnable()
          {
              var root = GetComponent<UIDocument>().rootVisualElement;
      
              chatInput = root.Q<TextField>("chatInput");
              sendButton = root.Q<Button>("sendButton");
              chatScrollView = root.Q<ScrollView>("chatScrollView");
      
              sendButton.clicked += OnSendButtonClicked;
      
              await ConnectAndJoinRoomAsync();
          }
          
      
          private async Task ConnectAndJoinRoomAsync()
          {
      
              // 방 접속을 위한 값 생성 
              room_id = "NpWXoXqzSG-ofk6E5p1xA-20240716140303";
              nick_name = "U-User";
              profile = DateTime.Now.ToString("HHmmss");
      
              Guid originalGuid = Guid.NewGuid();
              deviceUuid = originalGuid.ToString("D").Substring(0, 8);
      
              userInfo = new JObject();
              userInfo["profile"] = profile;
      
              options = new ChannelOptions();
      
              options.SetChannelKey(room_id).SetClientKey(deviceUuid).SetNickName(nick_name).SetUserInfo(userInfo);
      
              // 채팅서버 접속 
              SocketManager.Instance.OnConnectionOpened += () => ReceiveOpenEventAsync().GetAwaiter();
              SocketManager.Instance.OnConnectionFailed += ex => UnityEngine.Debug.Log("접속실패 " + ex.Message);
              SocketManager.Instance.OnConnectionClosed += () => UnityEngine.Debug.Log("접속종료");
              SocketManager.Instance.OnMessageReceived += async message => await ReceiveJoinMessagesAsync(message);
      
              VChatCloud.GetInstance().SetSocketStatus(SocketSet.CLOSED);
      
              try
              {
                  SocketManager.Instance.Connect(StringSet.SERVER);
              }
              catch (Exception ex)
              {
                  UnityEngine.Debug.Log(ex.ToString());                                                                                                            
              }                                                                                                    
      
          }        
      }
      
      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
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
      56
      57
      58
      59
      60
      61
      62
      63
      64
      65
      66
      67
      68
      69
      70
      71
      72

      # 채널객체 이벤트 처리

        Copyright 2022. E7Works Inc. & JOYTUNE Corp. All Rights Reserved.