Skip to content

3월4주차

kimhaneu1 edited this page Apr 2, 2025 · 9 revisions

서버 변경사항

  • Photon 연동
ServerManager 클래스

using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine.UI;

public class ServerManager : MonoBehaviourPunCallbacks
{
    private string gameVerion = "1";


    public void Match()
    {
        Debug.Log("매치실행해따");
        PhotonNetwork.GameVersion = gameVerion;
        PhotonNetwork.ConnectUsingSettings();

        //joinButton.interactable = false;
        Debug.Log("게임 서버에 접속중...");
    }

    public override void OnConnectedToMaster()
    {
        //joinButton.interactable = true;
        Debug.Log("온라인: 게임 서버와 연결됨");
    }

    public override void OnDisconnected(DisconnectCause cause)
    {
        //joinButton.interactable = false;
        Debug.Log("오프라인 : 게임 서버와 연결되지 않음\n접속 재시도 중...");
        PhotonNetwork.ConnectUsingSettings();
    }

    public void Connect()
    {
        //joinButton.interactable = false;

        if (PhotonNetwork.IsConnected)
        {
            Debug.Log("룸에 접속...");
            PhotonNetwork.JoinRandomRoom();
        }
        else
        {
            Debug.Log("오프라인: 게임 서버와 연결되지 않음\n접속 재시도 중...");
            PhotonNetwork.ConnectUsingSettings();
        }
    }

    public override void OnJoinRandomFailed(short returnCode, string message)
    {
        Debug.Log("빈 방이 없음, 새로운 방 생성...");

        PhotonNetwork.CreateRoom(null, new RoomOptions { MaxPlayers = 2 });
    }

    public override void OnJoinedRoom()
    {
        Debug.Log("방 참가 성공");
        PhotonNetwork.LoadLevel("GameScene");
    }
}


아래 코드로 매칭을 잡는데 왜 "게임시작버튼 활성화"로그가 안뜨지 계속 찾아보다가 유니티에서는 EventSystem이 없으면 UI가 기능을 상실하는걸 알게되어 수정하였다!


GetObject((int)GameObjects.GameStartImage).BindEvent((evt) =>
{
    Debug.Log("게임시작버튼 활성화");
    Managers.Server.Match();
});

  • GameReadyScene 씬 제작

UI 변경사항

GameReadyScene

dotween.mp4

Title DOTween

  • Dotween script
    public static Tween ApplyFadeMovement(TMP_Text target, float duration = 1.0f)
    {
        if (target == null) return null;

        Sequence sequence = DOTween.Sequence();

        sequence
            .Append(target.DOFade(1f, duration / 100))
            .Append(target.DOFade(0f, duration))
            .SetLoops(-1, LoopType.Yoyo)
            .SetUpdate(UpdateType.Normal, true);

        return sequence;
    }
  • Scene script
GetText((int)Texts.DisplayText).text = $"Touch To Start";
// 애니메이션
UI_DOTween.ApplyFadeMovement(GetText((int)Texts.DisplayText), 1.0f);

Clone this wiki locally