🌥制作記録🌥

創作に関することを書いていきます。だいたいゲーム系

【Unity/PUN】ネットワークゲームにおける楽な動作確認方法

概要

ネットワークゲームの簡単な動作確認方法書きます

こんな人がよむ

動作確認の度にビルドして実行ファイルを書き出すのが面倒な人

前提

基本的なgitの使い方がわかっている

やり方

流れ

  1. ローカルマシーンに同様のプロジェクトを2つクローンする
  2. UnityEditorを2つ開く
  3. 片方のプロジェクトでコーディングを行う
  4. 2つのローカルリポジトリを同期させる (準備)
  5. 2つのローカルリポジトリを同期させる

ローカルマシーンに同様のプロジェクトを2つクローンする

とりあえず該当するプロジェクトをクローンしてきましょう。
今回はテスト用のプロジェクトをクローン。

github.com

$ git clone https://github.com/sim-mokomo/LocalGitRepoSyncTest.git
$ git clone https://github.com/sim-mokomo/LocalGitRepoSyncTest.git LocalGitRepoSyncTest2

UnityEditorを2つ開く

無事開けました。
片方の変更がもう一方に反映できていれば満足の結果です。

f:id:sim-mokomo:20191007220836p:plain
Unity Editor ひらいた

片方のプロジェクトでコーディングを行う

(LocalGitRepoSyncTest内)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestScript : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("同期できてる!!!");
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

2つのローカルリポジトリを同期させる (準備)

LocalGitRepoSyncTest に移動して以下のコマンドをたたきましょう。
remote add はいつも Githubリポジトリ Url をたたき込んでるかもしれません。

代わりに2つめにクローンしてきたプロジェクトの相対パスを打ち込みます。
これで変更をもう一方のローカルgitリポジトリに適用することができるようになりました。

$ git remote add LocalGitRepoSyncTest2Proj ../LocalGitRepoSyncTest2
$ git remote -v
LocalGitRepoSyncTest2Proj       ../LocalGitRepoSyncTest2 (fetch)
LocalGitRepoSyncTest2Proj       ../LocalGitRepoSyncTest2 (push)
origin  https://github.com/sim-mokomo/LocalGitRepoSyncTest.git (fetch)
origin  https://github.com/sim-mokomo/LocalGitRepoSyncTest.git (push)

2つのローカルリポジトリを同期させる

準備ができたので早速プッシュしてみます。

$ git add .
$ git commit -m "同期テスト"
$ git push LocalGitRepoSyncTest2Proj master
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 12 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 852 bytes | 426.00 KiB/s, done.
Total 5 (delta 1), reused 0 (delta 0)
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: is denied, because it will make the index and work tree inconsistent
remote: with what you pushed, and will require 'git reset --hard' to match
remote: the work tree to HEAD.
remote:
remote: You can set the 'receive.denyCurrentBranch' configuration variable
remote: to 'ignore' or 'warn' in the remote repository to allow pushing into
remote: its current branch; however, this is not recommended unless you
remote: arranged to update its work tree to match what you pushed in some
remote: other way.
remote:
remote: To squelch this message and still keep the default behaviour, set
remote: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To ../LocalGitRepoSyncTest2
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '../LocalGitRepoSyncTest2'

怒られました。

プッシュ先で以下のコマンドをたたくと許されます。
詳細はこちらを見てください。

www.nekotricolor.com

~/Documents/UnityProjects/LocalGitRepoSyncTest2 (master)
$ git config receive.denyCurrentBranch updateInstead

動作確認

f:id:sim-mokomo:20191007223603p:plain
同期できてる!!!!

宣伝

Unityネットワークゲーム開発 実践入門 UNET/ニフティクラウド mobile backend版

Unityネットワークゲーム開発 実践入門 UNET/ニフティクラウド mobile backend版