PUN Classic (v1), PUN 2, Bolt는 휴업 모드입니다. Unity2022에 대해서는 PUN 2에서 서포트하지만, 신기능의 추가는 없습니다. 현재 이용중인 고객님의 PUN 및 Bolt 프로젝트는 중단되지 않고, 퍼포먼스나 성능이 떨어지는 일도 없습니다. 앞으로의 새로운 프로젝트에는 Photon Fusion 또는 Quantum을 사용해 주십시오.

헤드리스(headless) 서버

때로는 적은 자원을 사용하는 서버를 수행하고 싶을 수 있을 것 입니다. 이것과 같은 Unity 어플리케이션을 수행하기 위해서 -batchmode -nographics 로 실행하기를 원할 수도 있습니다. 예를 들어 "myGame.exe -batchmode -nographics" 와 같이 명령어 라인에서 할 수 있습니다. 게임에서 헤드리스로 수행되고 있는지를 체크해야 할 필요가 있습니다.

C#

using UnityEngine;
using System.Collections;
using System;
using UdpKit;

public class Init : Bolt.GlobalEventListener
{

    bool client = false;
    string host = "127.0.0.1:25000";

    string serverAddress = "127.0.0.1";
    int serverPort = 25000;

    string[] args;
    int map;

    void Start()
    {
        args = System.Environment.GetCommandLineArgs();

        if (System.Array.IndexOf(args, "-batchmode") >= 0)
        {
            Bolt.ConsoleWriter.Open();

            map = System.Array.IndexOf(args, "-map");

            if (map >= 0)
            {
                BoltLauncher.StartServer(new UdpEndPoint(UdpIPv4Address.Any, (ushort)serverPort));
                BoltNetwork.LoadScene(args[map + 1]);
            }
            else
            {
                Console.WriteLine("You have to specify a map");
                Application.Quit();
            }
        }
    }

    void OnGUI()
    {
        host = GUILayout.TextField(host, GUILayout.ExpandWidth(true));

        if (GUILayout.Button("Connect To Server", GUILayout.ExpandWidth(true)))
        {
            BoltLauncher.StartClient();
            client = true;
            
        }
    }

    public override void BoltStartDone()
    {
        if (client == true)
        {
            BoltNetwork.Connect(UdpKit.UdpEndPoint.Parse(host));

        }
        else
        {
            Console.WriteLine("Server Started On: {0}", BoltNetwork.UdpSocket.LanEndPoint);
            BoltNetwork.LoadScene(args[map + 1]);
        }
    }

}

초기 씬의 이 스크립트로 "myGame.exe -batchmode -nographics -map Level1" 을 입력할 수 있으며 씬 Level1에 대한 서버를 실행하게 될 것 입니다. 물론 추가적인 아큐먼트 체크를 하여 포트, 다른 게임모드들을 사용할 수 있도록 커스터마이징 할 수 있습니다.

헤드리스 서버로 수행할 때 게임내에서 커서를 잠그거나 플레어어를 스폰하거나 음악등을 사용하지 않도록 하길 원할 수도 있을 것 입니다. 튜토리얼 PlayerCamera.cs 안에 "Screen.lockCursor = true" 가 있는데 이 스크립트를 변경하여 헤드리스 모드가 아니더라도 커서만 잠그도록 변경할 수 있습니다. ServerCallbacks.cs 안에 Player.serverPlayer.InstantiateEntity() 도 동일합니다.

Back to top