朱峰社區(qū)首頁(yè) 朱峰社區(qū)

搜索資源 注冊(cè)|登陸

等待

返回 展開菜單
按功能 按軟件

繪制真實(shí)照片

繪制真實(shí)照片

包含9節(jié)視頻教程

這是臨摹的終極表現(xiàn)!在臨摹領(lǐng)域達(dá)到真實(shí)照片的級(jí)別,讓你的繪畫讓別人驚呼吧!這不是照片,真的是繪畫出來的。我們一起來學(xué)習(xí)吧!

關(guān)閉

Unity組件:Network View 網(wǎng)絡(luò)視圖

關(guān)注:1649 留言:0 樓主:廣州三悟(35VI) 發(fā)帖時(shí)間:15年11月16日

廣州三悟(35VI)

普通會(huì)員

廣州三悟(35VI)

社區(qū)新人:1級(jí)

關(guān)注2585人

  • 積分

    1

  • 登陸

    1

  • 發(fā)帖

    2

  • 留言

    1

  • 作品

    1

間隔線

Network Views are the gateway to creating networked multiplayer games in Unity. They are simple to use, but they are extremely powerful. For this reason, it is recommended that you understand the fundamental concepts behind networking before you start experimenting with Network Views. You can learn and discover the fundamental concepts in the Network Reference Guide.

網(wǎng)絡(luò)視圖是在Unity中創(chuàng)建網(wǎng)絡(luò)多人游戲的重要一步。易于使用,而且非常強(qiáng)大。在你開始練習(xí)使用網(wǎng)絡(luò)視圖之前你應(yīng)該更多了解網(wǎng)絡(luò)背后的基本概念。你能通過Network Reference Guide學(xué)到這些知識(shí)。


The Network View Inspector

In order to use any networking capabilities, including State Synchronization or Remote Procedure Calls, your GameObject must have a Network View attached.

為了使用包括狀態(tài)同步或者遠(yuǎn)程過程調(diào)用等網(wǎng)絡(luò)功能,首先你必須創(chuàng)建一個(gè)綁定了網(wǎng)絡(luò)視圖組件的游戲?qū)ο蟆?/p>

Properties 屬性
  • State Synchronization
    狀態(tài)同步
    The type of State Synchronization used by this Network View
    通過網(wǎng)絡(luò)視圖生效的狀態(tài)同步的類型
  •     Off 關(guān)閉
    No State Synchronization will be used. This is the best option if you only want to send RPCs
    如果你只使用RPCs最好關(guān)閉狀態(tài)同步功能。
  •     Reliable Delta Compressed
        延遲的使用壓縮的可靠性
    The difference between the last state and the current state will be sent, if nothing has changed nothing will be sent. This mode is ordered. In the case of packet loss, the lost packet is re-sent automatically
    發(fā)生變化的狀態(tài)會(huì)被通過網(wǎng)絡(luò)傳遞,如果沒有變化,沒有傳遞。這種模式是次序化得,因此,如果有包丟失,丟失的包會(huì)自動(dòng)重傳。
  •     Unreliable 不可靠的
    The complete state will be sent. This uses more bandwidth, but the impact of packet loss is minimized
    完整的傳遞所有狀態(tài)。這會(huì)導(dǎo)致更多帶寬被占用,但因?yàn)閬G包而導(dǎo)致的影響會(huì)降到最低。
  • Observed
    被觀察的對(duì)象
    The Component data that will be sent across the network
    會(huì)通過網(wǎng)絡(luò)進(jìn)行同步的組件數(shù)據(jù)。
  • View ID 視圖編號(hào)
    The unique identifier for this Network View. These values are read-only in the Inspector
    網(wǎng)絡(luò)視圖的唯一編號(hào),這個(gè)值是只讀的。
  •     Scene ID 場(chǎng)景編號(hào)
    The number id of the Network View in this particular scene
    在當(dāng)前視圖里的網(wǎng)絡(luò)視圖的數(shù)字編號(hào)。
  •     Type 類型
    Either saved to the Scene or Allocated at runtime
    這個(gè)選項(xiàng)將決定是在視圖中預(yù)先創(chuàng)建或是實(shí)時(shí)創(chuàng)建。
Details 細(xì)節(jié)

When you add a Network View to a GameObject, you must decide two things

當(dāng)你添加了一個(gè)網(wǎng)絡(luò)視圖到游戲?qū)ο螅惚仨毻瓿蓛蓚(gè)步驟。

  1. What kind of data you want the Network View to send
    你希望通過網(wǎng)絡(luò)視圖發(fā)送何種數(shù)據(jù)
  2. How you want to send that data
    你希望以何種方式發(fā)送這些數(shù)據(jù)
Choosing data to send 選擇數(shù)據(jù)來發(fā)送

The Observed property of the Network View can contain a single Component. This can be a Transform, an Animation, a RigidBody, or a script. Whatever the Observed Component is, data about it will be sent across the network. You can select a Component from the drop-down, or you can drag any Component header directly to the variable. If you are not directly sending data, just using RPC calls, then you can turn off synchronization (no data directly sent) and nothing needs to be set as the Observed property. RPC calls just need a single network view present so you don't need to add a view specifically for RPC if a view is already present.

網(wǎng)絡(luò)視圖的觀察者屬性用來指定單個(gè)組件?梢允且粋(gè)變換、一個(gè)動(dòng)畫、或是一個(gè)剛體、或者一個(gè)腳本。總之,觀察者組件是將會(huì)通過網(wǎng)絡(luò)發(fā)送的數(shù)據(jù)。你可以通過下拉菜單選擇的一個(gè)組件,或者你直接拖動(dòng)某個(gè)組件到該網(wǎng)絡(luò)視圖的觀察者屬性為其賦值。如果你不直接發(fā)送數(shù)據(jù),只是使用RPC調(diào)用,那你可以關(guān)閉同步(沒有數(shù)據(jù)會(huì)被直接發(fā)送)并且設(shè)置觀察者屬性為空。RPC調(diào)用只需要有一個(gè)網(wǎng)絡(luò)視圖存在,因此如果有一個(gè)視圖已經(jīng)存在你不需要再添加一個(gè)特殊的視圖。

How to send the data 如何發(fā)送數(shù)據(jù)

You have 2 options to send the data of the Observed Component: State Synchronization and Remote Procedure Calls.

你有兩種發(fā)送數(shù)據(jù)觀察者組件數(shù)據(jù)的選擇:狀態(tài)同步和遠(yuǎn)程過程調(diào)用。

To use State Synchronization, set State Synchronization of the Network View to Reliable Delta Compressed or Unreliable. The data of the Observed Component will now be sent across the network automatically.

當(dāng)設(shè)置網(wǎng)絡(luò)視圖的狀態(tài)同步為可靠的延遲的加密的模式或者不可靠的模式。觀察者屬性所關(guān)聯(lián)的數(shù)據(jù)會(huì)自動(dòng)通過網(wǎng)絡(luò)發(fā)送。

Reliable Delta Compressed is ordered. Packets are always received in the order they were sent. If a packet is dropped, that packet will be re-sent. All later packets are queued up until the earlier packet is received. Only the difference between the last transmissions values and the current values are sent and nothing is sent if there is no difference.

RDC是有序的。包總是以他們發(fā)送的次序被接收。如果包丟失了,包會(huì)被重發(fā)。后續(xù)的所有包會(huì)被緩存起來直到丟失的包被接收到。只有最后傳輸?shù)闹岛彤?dāng)前的值之間發(fā)生改變的值會(huì)被傳送。如果沒有改變沒有值會(huì)被傳送。

If it is observing a Script, you must explicitly Serialize data within the script. You do this within the OnSerializeNetworkView() function.

如果被觀察的是一個(gè)腳本組件,你必須明確的指出和腳本相關(guān)聯(lián)的數(shù)據(jù),你可以通過在OnSerializeNetworkView()中返回?cái)?shù)據(jù)來實(shí)現(xiàn)。

function OnSerializeNetworkView (stream : BitStream, info : NetworkMessageInfo) {
	var horizontalInput : float = Input.GetAxis ("Horizontal");
	stream.Serialize (horizontalInput);
}

The above function always writes (an update from the stream) into horizontalInput, when receiving an update and reads from the variable writing into the stream otherwise. If you want to do different things when receiving updates or sending you can use the isWriting attribute of the BitStream class.

上述函數(shù)中的代碼總是寫入(或者是從流中提。┑絟orizontalInput,為了接收到一個(gè)更新或是讀出一個(gè)正寫入流中的變量。如果你想在接收更新或者發(fā)送時(shí)能做些別的事情,你能通過使用BitStream上的isWriting屬性來實(shí)現(xiàn)。

function OnSerializeNetworkView (stream : BitStream, info : NetworkMessageInfo) {
	var horizontalInput : float = 0.0;
	if (stream.isWriting) {
		// Sending
		horizontalInput = Input.GetAxis ("Horizontal");
		stream.Serialize (horizontalInput);
	} else {

		// Receiving
		stream.Serialize (horizontalInput);
		// ... do something meaningful with the received variable
	}
}

OnSerializeNetworkView is called according to the sendRate specified in the network manager project settings. By default this is 15 times per second.

OnSerializeNetworkView根據(jù)在網(wǎng)絡(luò)管理器工程設(shè)定里的sendRate(發(fā)送速率)進(jìn)行調(diào)用。默認(rèn)的是每秒鐘調(diào)用15次。

If you want to use Remote Procedure Calls in your script all you need is a NetworkView component present in the same GameObject the script is attached to. The NetworkView can be used for something else, or in case it's only used for sending RPCs it can have no script observed and state synchronization turned off. The function which is to be callable from the network must have the @RPC attribute. Now, from any script attached to the same GameObject, you call networkView.RPC() to execute the Remote Procedure Call.

如果你想在腳本中使用RPC你所需要做的是在腳本組件所在的游戲?qū)ο笊辖壎ㄒ粋(gè)網(wǎng)絡(luò)視圖組件對(duì)象。網(wǎng)絡(luò)組件還能被用作其他用途,或者只用于發(fā)送RPC, 網(wǎng)絡(luò)組件上不綁定任何腳本組件并且狀態(tài)同步選項(xiàng)被關(guān)閉?梢酝ㄟ^網(wǎng)絡(luò)組件進(jìn)行訪問的RPC函數(shù)必須具備@RPC屬性。現(xiàn)在,從任何綁定在游戲?qū)ο蟮哪_本組件中都可以通過調(diào)用networkView.RPC()來執(zhí)行遠(yuǎn)程調(diào)用操作。

var playerBullet : GameObject;

function Update () {
	if (Input.GetButtonDown ("Fire1")) {
		networkView.RPC ("PlayerFire", RPCMode.All);
	}
}

@RPC
function PlayerFire () {
	Instantiate (playerBullet, playerBullet.transform.position, playerBullet.transform.rotation);
}

RPCs are transmitted reliably and ordered. For more information about RPCs, see the RPC Details page.

RPC被可靠的傳輸。在RPC Details可以獲得更多RPC的詳細(xì)細(xì)節(jié)。

Hints 提示
  • Read through the Network Reference Guide if you're still unclear about how to use Network Views
    通過閱讀Network Reference Guide,如果你還清楚如何使用網(wǎng)絡(luò)視圖。
  • State Synchronization does not need to be disabled to use Remote Procedure Calls
    使用RPC不需要關(guān)閉狀態(tài)同步
  • If you have more than one Network View and want to call an RPC on a specific one, use GetComponents(NetworkView)[i].RPC().
    如果你想通過在多個(gè)網(wǎng)絡(luò)視圖中選擇一個(gè)來完成RPC時(shí),請(qǐng)使用GetComponents(NetworkView)[i].RPC()。

贊0 踩0

未知用戶

2005-2025 朱峰社區(qū) 版權(quán)所有 遼ICP備2021001865號(hào)-1
2005-2025 ZhuFeng Community All Rights Reserved

VIP

朱峰社區(qū)微信公眾號(hào)

回頂部

1.復(fù)制文本發(fā)給您的QQ好友或群、微信等;好友點(diǎn)擊鏈接以后,轉(zhuǎn)發(fā)就成功了。 2.如朋友點(diǎn)擊您的鏈接,您需要需刷新一下才行;同一個(gè)好友僅能點(diǎn)擊一次。
購(gòu)買VIP,觀看所有收費(fèi)教程!!