본문 바로가기

카테고리 없음

Photon 공부하면서 배운 것

chat 먼저 import -> pun2 import : pun2에 chat이 포함되어있기 때문에

 

 

이것만 했을때는 버튼으로 클릭해야 채팅문구 전송가능

Send버튼을 눌러도 입력한 텍스트는 없어지지 않음 -> 해당부분 수정 필요

 

블로그보고 InputField에 On End Edit 추가

추가 후 엔터로 메세지 전송가능

but 여기에서도 채팅을 보낸 후 내가 쓴 메세지가 입력칸에 그대로 남아있음...ㅠ

 

 

 

0604 오후 6시 

채팅 손건들기 전에 코드

이제 수정하기전에 .. 일단 복붙해놓는다..ㅠ

using ExitGames.Client.Photon;
using Photon.Chat;
using Photon.Pun;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
// using System;
// using Photon.Realtime;
// using AuthenticationValues = Photon.Chat.AuthenticationValues;
// using ExitGames.Client.Photon;

public class ChatManager : MonoBehaviour, IChatClientListener
{
    private ChatClient chatClient;

    public TMP_InputField plrName;
    public TextMeshProUGUI connectionState;
    public TMP_InputField msgInput;
    public TextMeshProUGUI msgArea;

    public GameObject intoPanel;
    public GameObject msgPanel;

    private string worldchat;
    [SerializeField] private string userID;

    // Start is called before the first frame update
    void Start()
    {
        Application.runInBackground = true;
        if(string.IsNullOrEmpty(PhotonNetwork.PhotonServerSettings.AppSettings.AppIdChat))
        {
            Debug.LogError("No AppID Provided");
            return;
        }

        worldchat = "world";
    }

    // Update is called once per frame
    void Update()
    {
        if (chatClient != null)
        {
            chatClient.Service();
        }
    }


    public void GetConnected()
    {
        Debug.Log("connecting");
        chatClient = new ChatClient(this);
        chatClient.Connect(PhotonNetwork.PhotonServerSettings.AppSettings.AppIdChat, PhotonNetwork.AppVersion, new Photon.Chat.AuthenticationValues(plrName.text));
    }

    public void SendMsg()
    {
        chatClient.PublishMessage(worldchat, msgInput.text);
    }


    public void DebugReturn(DebugLevel level, string message)
    {
       
    }

    public void OnChatStateChange(ChatState state)
    {
       
    }

    public void OnConnected()
    {
        intoPanel.SetActive(false);
        msgPanel.SetActive(true);
        chatClient.Subscribe(new string[] { worldchat });
        chatClient.SetOnlineStatus(ChatUserStatus.Online);
    }

    
    public void OnDisconnected()
    {
       
    }

    public void OnGetMessages(string channelName, string[] senders, object[] messages)
    {
        for (int i = 0; i < senders.Length; i++)
        {
            msgArea.text += senders[i] + ": " + messages[i] + "\n";
        }
    }

    public void OnPrivateMessage(string sender, object message, string channelName)
    {
        
    }

    public void OnStatusUpdate(string user, int status, bool gotMessage, object message)
    {
        
    }

    public void OnSubscribed(string[] channels, bool[] results)
    {
        foreach(var channel in channels)
        {
            this.chatClient.PublishMessage(channel, "joined");
        }
        connectionState.text = "Connected";
    }

    public void OnUnsubscribed(string[] channels)
    {
      
    }

    public void OnUserSubscribed(string channel, string user)
    {
       
    }

    public void OnUserUnsubscribed(string channel, string user)
    {
       
    }
   
    

}

https://ojui.tistory.com/74?category=894110 

 

TMP(Text Mesh Pro) 한글 생성

🔷 TMP 한글 생성 - TMP에 한글을 작성하면 네모로 보임 (ex : □□□...) - 이를 해결하는 방법 🔶 원하는 폰트 다운로드 후 가져오기 https://fonts.google.com/ Google Fonts Making the web more beautiful, f..

ojui.tistory.com