PUN Classic (v1), PUN 2 and Bolt are in maintenance mode. PUN 2 will support Unity 2019 to 2022, but no new features will be added. Of course all your PUN & Bolt projects will continue to work and run with the known performance in the future. For any upcoming or new projects: please switch to Photon Fusion or Quantum.

헤드리스(headless) 서버

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

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() 도 동일합니다.

기술문서 TOP으로 돌아가기