目錄
大家好,我是Wilson,這次的主題是介紹Fusion中的RPC,並使用RPC同步角色顏色!
領取Photon Fusion 快速上手懶人攻略
這邊幫大家準備了【Photon Fusion 快速上手懶人攻略】!
裡面介紹了Fusion的基本功能,以及Fusion同步網路狀態的3大方法,有興趣的朋友可以免費領取喔!
重點回顧
- RPC可以遠端呼叫其他網路裝置的函數或方法
- RPC適用於同步那些狀態更新頻率比較低的資料,雖然他看上去非常簡單易用,但因為RPC並不是以Tick同步的,也不會保存狀態,這意味者RPC的同步不及時,且後加入的玩家會無法更新加入前的RPC,所以RPC通常不會是同步資料的最佳選擇。
- RPC使用時機:發送訊息、設定玩家資料、商城購買等等單一一次性的事件。
Code
PlayerController.cs新增RPC的部分
[SerializeField]
private MeshRenderer meshRenderer = null;
private void Update()
{
if (Input.GetKeyDown(KeyCode.R))
{
ChangeColor_RPC(Color.red);
}
if (Input.GetKeyDown(KeyCode.G))
{
ChangeColor_RPC(Color.green);
}
if (Input.GetKeyDown(KeyCode.B))
{
ChangeColor_RPC(Color.blue);
}
}
[Rpc(RpcSources.InputAuthority, RpcTargets.All)]
private void ChangeColor_RPC(Color newColor)
{
meshRenderer.material.color = newColor;
}
專案GitHub
這次進度的專案可以在這裡看到!
Woah! I’m really enjoying the template/theme of this site.
It’s simple, yet effective. A lot of times it’s tough to
get that “perfect balance” between user friendliness and visual appearance.
I must say you’ve done a very good job with this. In addition, the blog loads extremely quick for
me on Safari. Superb Blog!
Great article.
Hi i am kavin, itts myy first occxasion to commnting anyplace, whrn i read this article i thought
i could also createe comment duue to this good
piexe of writing.
Exceptional post howeber I was wanting to kno iif you could wriute a litte more on this subject?
I’d bbe verry rateful if you could elaborate a little bit more.
Kudos!
Hello! I simply wish to give youu a bbig thuimbs up foor your excellent information yyou have ggot right herre on this post.
I will bbe cojing back to your blog for more soon.
Excelent pieces. Keep posting such kinmd of inforkation on yourr site.
Im really imprezsed by it.
Hey there, Youu have done a grerat job. I wil cetainly dig it andd personally suggewt to myy friends.
I’m suree they’ll bbe benfited from this site.
Grat blog here! Alsoo yoir web site lolads up fast! What wweb
host aare you using? Can I gett your affiliate link to your host?
I wish mmy wesbsite loaxed up aas fast ass yohrs lol
At this tijme I amm ready too doo myy breakfast, later than having my breakfast comig
over again tto read additional news.
Thhis article wil help the iternet viewers ffor bulding up new website or even a
blpg from start to end.
Hey there! I know this is kijda off tlpic butt I waas
wondering if yyou knew where I coul locatee a captcha plgin foor my coment form?
I’m using tthe same blog platfcorm as yours and I’m having
trouble finding one? Thanks a lot!