Code Monkey home page Code Monkey logo

unity-network-sample's Introduction

概要

Unityの ネットワークサンプル を簡略化したもです。
ThirdPersonControllerの同期、キューブの生成と同期を行なっています。

マスターサーバーを走らせる

ネットワークのサンプルを動かすにはマスターサーバーを立てる必要があります。
まずは Unity Networking Servers からMaster Serverをクリックしプロジェクトをダウンロードします。

MasterServer-2.0.1f1の中身

MacOSXの場合
  1. xcodeフォルダの中のプロジェクトを起動。
  2. 「Compiler for C/C++/Objective-C」で「LLVM GCC 4.2」を選択。
  3. Runでマスターサーバーを走らせる。
Windowsの場合
  1. VisualStudioフォルダの中のプロジェクトを起動。
  2. ビルドをしプロジェクトフォルダ内にできる「Debug」フォルダの「MasterServer.exe」をダブルクリックしてマスターサーバーを走らせる。

マスターサーバーへの接続

「Scene/loader」をクリックしてUnityプロジェクトを開き「Prefab/ConnectionGUI」に付加されている「ConnectGuiMasterServer」の「Ip Address」をプライベートIPアドレスに変更する。

  1. ここでプラットフォーム「スタンドアローン」を選択してビルドする。そしてアプリを起動。
  2. 片方のゲームビューの「サーバーコンソール」から「サーバー起動」を選択しサーバーを走らせ、「Third Person」をクリックする。
  3. 残りのもう片方は一度「サーバーコンソール」の「リフレッシュ」を押す。
    すると下のようなウィンドウが現れる。

「接続」ボタンを押すと「Third Person」のシーンへ移動する。

これで同期は取れてますので「Lerpz」を動かしまくりましょう

キューブの生成

本家のサンプルでは少しごちゃごちゃしていてわかりにくかったので、
こちらでRigidbodyの付いたキューブを生成するコードを書いてみました。(zでキューブ生成)

多少はわかりやすいはず…

キューブを生成するアクションを起こすコードは「Scripts/ThirdPersonAction」に記述しています。

Network.Instantiateで生成するというもの。

「Prefab/Cube」が生成されるオブジェクトです。「NetworkView」をつけることでIDが割り当てられ、管理をすることができます。

「NetworkRigidbody」をつけることによって物理演算処理の同期をとることができます。

生成するオブジェクトがRigidbodyでない場合は「NetworkInterpolatedTransform」を付加させましょう(たぶん)

unity-network-sample's People

Contributors

anchan828 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.