Esempio n. 1
0
        private void Awake()
        {
            this.rigidbodyComponent = this.GetComponent <Rigidbody>();
            this.animatorComponent  = this.GetComponent <Animator>();

            // Player名が変更になった時のコールバック指定
            this.playerName.OnValueChanged += OnChangePlayerName;

            // あとServer時に余計なものを削除します
#if UNITY_SERVER
            NetworkUtility.RemoveAllStandaloneComponents(this.gameObject);
#elif ENABLE_AUTO_CLIENT
            if (NetworkUtility.IsBatchModeRun)
            {
                NetworkUtility.RemoveAllStandaloneComponents(this.gameObject);
            }
#endif
        }
        // 接続時
        void Awake()
        {
            // ターゲットフレームレートをちゃんと設定する
            // ※60FPSにしないと Headlessサーバーや、バッチクライアントでブン回りしちゃうんで…
            Application.targetFrameRate = 60;


#if CLIENT || SERVER
            localIPAddr = "HostName: " + Dns.GetHostName();            
#else
            localIPAddr = NetworkUtility.GetLocalIP(); //GameLift環境では動作しない
#endif

            this.localIpInfoText.text = "あなたのIPアドレスは、" + localIPAddr;

            this.connectInfo = ConnectInfo.LoadFromFile();
            ApplyConnectInfoToUI();

            this.resetButton.onClick.AddListener(OnClickReset);
            this.hostButton.onClick.AddListener(OnClickHost);
            this.clientButton.onClick.AddListener(OnClickClient);
            connectGameLiftButton.onClick.AddListener(OnClickGameLiftConnect);
        }
        // 
        private void Start()
        {
            // サーバービルド時
#if UNITY_SERVER
            Debug.Log("Server Build.");
            this.connectInfo.port = serverPort;
            ApplyConnectInfoToNetworkManager();
            this.serverManager.Setup(this.connectInfo, localIPAddr);
            // あと余計なものをHeadless消します
            NetworkUtility.RemoveUpdateSystemForHeadlessServer();

            // MLAPIでサーバーとして起動
            var tasks = MLAPI.NetworkingManager.Singleton.StartServer();
            this.serverManager.SetSocketTasks(tasks);
#elif ENABLE_AUTO_CLIENT
            if (NetworkUtility.IsBatchModeRun)
            {
                // バッチモードでは余計なシステム消します
                NetworkUtility.RemoveUpdateSystemForBatchBuild();
                //OnClickClient();
                OnClickGameLiftConnect();
            }
#endif
        }