SlideShare a Scribd company logo
1 of 28
Download to read offline
PUN v2 開發經驗分享

Technical Evangelist

曾建評 Ryan Tseng

Copyright © 2018 GMO CLOUD K.K.

自我介紹- Ryan Tseng 曾建評

跨進遊戲開發產業之前是專精在軟體與系統整合領域, 並有涉獵雲
端與物聯網等議題研究. 



成為 Photon Technical Evangelist 之後, 期許能轉化自身的實務經
歷, 為 Photon Taiwan 做在地化的專業技術支援與服務.



2Copyright © 2018 GMO CLOUD K.K.

PUN v2 

Photon Unity Networking (PUN) 是專為 Unity 網路遊戲而開發的套
件, 強化了多人網路即時連線的功能, 並相容於原本的 Unity
Networking, 能配合在全球佈署的 Photon Cloud 做為遊戲的後端伺
服器, 應用上非常廣泛.

3Copyright © 2018 GMO CLOUD K.K.

多人網路即時連線遊戲開發

● 如何讓玩家們匯聚在一起: Lobby 階段

● 如何控制資料同步方式: Room 階段

○ 明確定義遊戲中有哪些物件, 事件需要同步?
○ 由誰發動同步? 對象是誰? 範圍? 同步頻率? 根據各事
件的特性決定要如何同步.
Copyright © 2018 GMO CLOUD K.K.
 4
PUN2 連線射擊遊戲

5Copyright © 2018 GMO CLOUD K.K.

6
PUN2 連線射擊遊戲

1. Lobby 階段

2. Room 階段

3. 玩家角色控制

4. 資訊與狀態同步

Copyright © 2018 GMO CLOUD K.K.
 7
PUN2 連線射擊遊戲- Lobby 階段

遊戲啟動, 處理與遊戲伺服器連線過程及進度. 

1. 匯入 PUN 2 - FREE 套件

2. 取得 AppId

Copyright © 2018 GMO CLOUD K.K.
 8
PUN2 連線射擊遊戲- Lobby 階段

3. Awake()

- 確保所有連線的玩家均載入相同的遊戲場景 (PhotonNetwork.AutomaticallySyncScene = true; )

4. Start() 

- 檢查是否與 Photon Cloud 連線. (PhotonNetwork.IsConnected )

若已連線, 則嚐試隨機加入一個遊戲室 (PhotonNetwork.JoinRandomRoom() )

若未連線, 則嚐試與 Photon Cloud 連線 (PhotonNetwork.ConnectUsingSettings() )

Copyright © 2018 GMO CLOUD K.K.
 9
PUN2 連線射擊遊戲- Lobby 階段

5. 處理連線與加入遊戲室的狀況

- OnConnectedToMaster() 

確認已連上 PhotonCloud, 嚐試隨機加入一個遊戲室

- OnDisconnected()

玩家自 PhotonCloud 斷線

- OnJoinedRoom()

成功進入遊戲室中

- OnJoinRandomFailed()

隨機加入遊戲室失敗, 自行創建一個新的遊戲室

Copyright © 2018 GMO CLOUD K.K.
 10
PUN2 連線射擊遊戲- Room 階段

遊戲室場景會隨同時在線人數擴大. 

1. 依在線玩家人數, 建立適當的遊戲場景與 Build Settings.

2. GameManager - 管理玩家在遊戲室的狀態

- OnLeftRoom()

當玩家離開遊戲室, 把他帶回到 Lobby. (SceneManager.LoadScene() )

- LoadArena()

依在線玩家人數載入對應的遊戲室場景 (PhotonNetwork.LoadLevel() )

- OnPlayerEnteredRoom()

當有玩家進入遊戲室, 讓 MasterClient 重新載入遊戲室場景 (LoadArena())

- OnPlayerLeftRoom()

當有玩家離開遊戲室, 讓 MasterClient 重新載入遊戲室場景 (LoadArena())



Copyright © 2018 GMO CLOUD K.K.
 11
PUN2 連線射擊遊戲- 玩家角色控制

1. 玩家角色的跑/跳/轉身控制與射擊.

2. 將遊戲角色的 Prefab 移到 Resources 資料夾底下.









Copyright © 2018 GMO CLOUD K.K.
 12
PUN2 連線射擊遊戲- 資訊與狀態同步

1. 透過 PhotonView 做角色位置等資訊同步.

- 為遊戲角色的 Prefab 添加 PhotonView, PhotonTransformView 

與 PhotonAnimatorView 元件.

- 設定 PhotonView 的 Observed Components 與同步方法和頻率.

2. 多人連線遊戲的用戶輸入管理.

- 藉由 photonView.IsMine 來判别事件或觸發動作是否屬於本機玩家 

3. 設定相機跟隨玩家的角色.







Copyright © 2018 GMO CLOUD K.K.
 13
PUN2 連線射擊遊戲- 資訊與狀態同步

4. 透過 PhotonView 做武器發射與血量等狀態同步.

- 在 OnPhotonSerializeView() 做狀態變數的數值更新.

5. 在 GameManager 動態生成玩家的角色.

- Start()

PhotonNetwork.Instantiate() - 動態生成玩家的角色.

- Awake()

DontDestroyOnLoad() - 標註玩家角色的 instance 不會在重載場景時被砍殺掉.

- OnLevelWasLoaded()

適當調整已在遊戲室的玩家角色們的位置.









Copyright © 2018 GMO CLOUD K.K.
 14
請參考部落格文章:
PUN 2 | 連線射擊遊戲
(https://bit.ly/2KM2Fwv)
有更詳細的圖文說明喔.
Unity Tanks!

15Copyright © 2018 GMO CLOUD K.K.

16
Unity Tanks!

- 單機版雙人對戰

- 設定場景

- 設定玩家角色 (坦克) / 動作控制 / 攝影機 / 血量

- 設定砲彈 / 發射控制 / 碰撞觸發

- Game Managers

- 安排坦克的位置
- 遊戲回合控制
- 其它 (音效)



Copyright © 2018 GMO CLOUD K.K.
 17
https://learn.unity.com/project/tanks-tutorial

Unity Tanks! + PUN v2

18Copyright © 2018 GMO CLOUD K.K.

19
Tanks! + PUN2 - Lobby | Room 階段

1. 匯入 PUN 2 - FREE 套件並取得 AppId

2. Awake()

- 確保所有連線的玩家均載入相同的遊戲場景 (PhotonNetwork.AutomaticallySyncScene = true; )

3. Start() 

- 檢查是否與 Photon Cloud 連線. (PhotonNetwork.IsConnected )

若已連線, 則嚐試隨機加入一個遊戲室 (PhotonNetwork.JoinRandomRoom() )

若未連線, 則嚐試與 Photon Cloud 連線 (PhotonNetwork.ConnectUsingSettings() )

Copyright © 2018 GMO CLOUD K.K.
 20
Tanks! + PUN2 - Lobby | Room 階段

4. 處理連線與加入遊戲室的狀況

- OnConnectedToMaster() 

確認已連上 PhotonCloud, 嚐試隨機加入一個遊戲室

- OnDisconnected()

玩家自 PhotonCloud 斷線

- OnJoinedRoom()

成功進入遊戲室中, 讓 MasterClient 直接載入坦克遊戲場景 (PhotonNetwork.LoadLevel() ).

- OnJoinRandomFailed()

隨機加入遊戲室失敗, 自行創建一個新的遊戲室

5. 調整 Build Settings

Copyright © 2018 GMO CLOUD K.K.
 21
Tanks! + PUN2 - 坦克資訊與狀態同步

1. 將原本的 Prefab- Tank 拉到 Resources 資料夾, 創建為新的
Prefab- Tank.

2. 再為新的 Prefab- Tank 添加 

PhotonView 與 PhotonTransformView 兩個元件,

並設定 Observed Components.







Copyright © 2018 GMO CLOUD K.K.
 22
Tanks! + PUN2 - 坦克資訊與狀態同步

3. GameManager

- Start()

讓 MasterClient 去動態生成第一台坦克.

讓第二位玩家去動態生成第二台坦克.













Copyright © 2018 GMO CLOUD K.K.
 23
4. 在 Prefab- Tank 添加 CameraWork

元件. 

- 在 TankMovement 的 Start() 判斷為本機玩家時, 

讓 Camera 跟隨玩家移動.















Copyright © 2018 GMO CLOUD K.K.
 24
Tanks! + PUN2 - 相機跟隨坦克移動

5. 調整 Inspector 裡面參考到

的 Tank 為 Resources 底下

的 Prefab- Tank 
















Copyright © 2018 GMO CLOUD K.K.
 25
Tanks! + PUN2 - 坦克資訊與狀態同步

Tanks! + PUN2 - 砲彈資訊與狀態同步

1. 將原本的 Prefab- Shell 拉到 Resources 資料夾, 創建為新的
Prefab- Shell.

2. 再為新的 Prefab- Shell 添加 

PhotonView 與 PhotonTransformView 兩個元件,

並設定 Observed Components.







Copyright © 2018 GMO CLOUD K.K.
 26
Tanks! + PUN2 - 砲彈發射狀態同步

3. TankShooting

- OnPhotonSerializeView()

同步砲彈發射狀態.

- 將 TankShooting 加到 Prefab- Tank

的 PhotonView 元件的 Observed Components.













Copyright © 2018 GMO CLOUD K.K.
 27
Thank you

時間咻一下就過去了, 覺得意猶未盡嗎? 



歡迎到我們的粉絲團一起來討論唷 ~

粉絲團 https://www.facebook.com/photoncloudtw

部落格 https://medium.com/photon-taiwan

28

More Related Content

Featured

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellSaba Software
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming LanguageSimplilearn
 

Featured (20)

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
 

PUN v2 開發經驗分享

  • 1. PUN v2 開發經驗分享
 Technical Evangelist
 曾建評 Ryan Tseng
 Copyright © 2018 GMO CLOUD K.K.

  • 2. 自我介紹- Ryan Tseng 曾建評
 跨進遊戲開發產業之前是專精在軟體與系統整合領域, 並有涉獵雲 端與物聯網等議題研究. 
 
 成為 Photon Technical Evangelist 之後, 期許能轉化自身的實務經 歷, 為 Photon Taiwan 做在地化的專業技術支援與服務.
 
 2Copyright © 2018 GMO CLOUD K.K.

  • 3. PUN v2 
 Photon Unity Networking (PUN) 是專為 Unity 網路遊戲而開發的套 件, 強化了多人網路即時連線的功能, 並相容於原本的 Unity Networking, 能配合在全球佈署的 Photon Cloud 做為遊戲的後端伺 服器, 應用上非常廣泛.
 3Copyright © 2018 GMO CLOUD K.K.

  • 4. 多人網路即時連線遊戲開發
 ● 如何讓玩家們匯聚在一起: Lobby 階段
 ● 如何控制資料同步方式: Room 階段
 ○ 明確定義遊戲中有哪些物件, 事件需要同步? ○ 由誰發動同步? 對象是誰? 範圍? 同步頻率? 根據各事 件的特性決定要如何同步. Copyright © 2018 GMO CLOUD K.K.
 4
  • 6. 6
  • 7. PUN2 連線射擊遊戲
 1. Lobby 階段
 2. Room 階段
 3. 玩家角色控制
 4. 資訊與狀態同步
 Copyright © 2018 GMO CLOUD K.K.
 7
  • 8. PUN2 連線射擊遊戲- Lobby 階段
 遊戲啟動, 處理與遊戲伺服器連線過程及進度. 
 1. 匯入 PUN 2 - FREE 套件
 2. 取得 AppId
 Copyright © 2018 GMO CLOUD K.K.
 8
  • 9. PUN2 連線射擊遊戲- Lobby 階段
 3. Awake()
 - 確保所有連線的玩家均載入相同的遊戲場景 (PhotonNetwork.AutomaticallySyncScene = true; )
 4. Start() 
 - 檢查是否與 Photon Cloud 連線. (PhotonNetwork.IsConnected )
 若已連線, 則嚐試隨機加入一個遊戲室 (PhotonNetwork.JoinRandomRoom() )
 若未連線, 則嚐試與 Photon Cloud 連線 (PhotonNetwork.ConnectUsingSettings() )
 Copyright © 2018 GMO CLOUD K.K.
 9
  • 10. PUN2 連線射擊遊戲- Lobby 階段
 5. 處理連線與加入遊戲室的狀況
 - OnConnectedToMaster() 
 確認已連上 PhotonCloud, 嚐試隨機加入一個遊戲室
 - OnDisconnected()
 玩家自 PhotonCloud 斷線
 - OnJoinedRoom()
 成功進入遊戲室中
 - OnJoinRandomFailed()
 隨機加入遊戲室失敗, 自行創建一個新的遊戲室
 Copyright © 2018 GMO CLOUD K.K.
 10
  • 11. PUN2 連線射擊遊戲- Room 階段
 遊戲室場景會隨同時在線人數擴大. 
 1. 依在線玩家人數, 建立適當的遊戲場景與 Build Settings.
 2. GameManager - 管理玩家在遊戲室的狀態
 - OnLeftRoom()
 當玩家離開遊戲室, 把他帶回到 Lobby. (SceneManager.LoadScene() )
 - LoadArena()
 依在線玩家人數載入對應的遊戲室場景 (PhotonNetwork.LoadLevel() )
 - OnPlayerEnteredRoom()
 當有玩家進入遊戲室, 讓 MasterClient 重新載入遊戲室場景 (LoadArena())
 - OnPlayerLeftRoom()
 當有玩家離開遊戲室, 讓 MasterClient 重新載入遊戲室場景 (LoadArena())
 
 Copyright © 2018 GMO CLOUD K.K.
 11
  • 12. PUN2 連線射擊遊戲- 玩家角色控制
 1. 玩家角色的跑/跳/轉身控制與射擊.
 2. 將遊戲角色的 Prefab 移到 Resources 資料夾底下.
 
 
 
 
 Copyright © 2018 GMO CLOUD K.K.
 12
  • 13. PUN2 連線射擊遊戲- 資訊與狀態同步
 1. 透過 PhotonView 做角色位置等資訊同步.
 - 為遊戲角色的 Prefab 添加 PhotonView, PhotonTransformView 
 與 PhotonAnimatorView 元件.
 - 設定 PhotonView 的 Observed Components 與同步方法和頻率.
 2. 多人連線遊戲的用戶輸入管理.
 - 藉由 photonView.IsMine 來判别事件或觸發動作是否屬於本機玩家 
 3. 設定相機跟隨玩家的角色.
 
 
 
 Copyright © 2018 GMO CLOUD K.K.
 13
  • 14. PUN2 連線射擊遊戲- 資訊與狀態同步
 4. 透過 PhotonView 做武器發射與血量等狀態同步.
 - 在 OnPhotonSerializeView() 做狀態變數的數值更新.
 5. 在 GameManager 動態生成玩家的角色.
 - Start()
 PhotonNetwork.Instantiate() - 動態生成玩家的角色.
 - Awake()
 DontDestroyOnLoad() - 標註玩家角色的 instance 不會在重載場景時被砍殺掉.
 - OnLevelWasLoaded()
 適當調整已在遊戲室的玩家角色們的位置.
 
 
 
 
 Copyright © 2018 GMO CLOUD K.K.
 14 請參考部落格文章: PUN 2 | 連線射擊遊戲 (https://bit.ly/2KM2Fwv) 有更詳細的圖文說明喔.
  • 15. Unity Tanks!
 15Copyright © 2018 GMO CLOUD K.K.

  • 16. 16
  • 17. Unity Tanks!
 - 單機版雙人對戰
 - 設定場景
 - 設定玩家角色 (坦克) / 動作控制 / 攝影機 / 血量
 - 設定砲彈 / 發射控制 / 碰撞觸發
 - Game Managers
 - 安排坦克的位置 - 遊戲回合控制 - 其它 (音效)
 
 Copyright © 2018 GMO CLOUD K.K.
 17 https://learn.unity.com/project/tanks-tutorial

  • 18. Unity Tanks! + PUN v2
 18Copyright © 2018 GMO CLOUD K.K.

  • 19. 19
  • 20. Tanks! + PUN2 - Lobby | Room 階段
 1. 匯入 PUN 2 - FREE 套件並取得 AppId
 2. Awake()
 - 確保所有連線的玩家均載入相同的遊戲場景 (PhotonNetwork.AutomaticallySyncScene = true; )
 3. Start() 
 - 檢查是否與 Photon Cloud 連線. (PhotonNetwork.IsConnected )
 若已連線, 則嚐試隨機加入一個遊戲室 (PhotonNetwork.JoinRandomRoom() )
 若未連線, 則嚐試與 Photon Cloud 連線 (PhotonNetwork.ConnectUsingSettings() )
 Copyright © 2018 GMO CLOUD K.K.
 20
  • 21. Tanks! + PUN2 - Lobby | Room 階段
 4. 處理連線與加入遊戲室的狀況
 - OnConnectedToMaster() 
 確認已連上 PhotonCloud, 嚐試隨機加入一個遊戲室
 - OnDisconnected()
 玩家自 PhotonCloud 斷線
 - OnJoinedRoom()
 成功進入遊戲室中, 讓 MasterClient 直接載入坦克遊戲場景 (PhotonNetwork.LoadLevel() ).
 - OnJoinRandomFailed()
 隨機加入遊戲室失敗, 自行創建一個新的遊戲室
 5. 調整 Build Settings
 Copyright © 2018 GMO CLOUD K.K.
 21
  • 22. Tanks! + PUN2 - 坦克資訊與狀態同步
 1. 將原本的 Prefab- Tank 拉到 Resources 資料夾, 創建為新的 Prefab- Tank.
 2. 再為新的 Prefab- Tank 添加 
 PhotonView 與 PhotonTransformView 兩個元件,
 並設定 Observed Components.
 
 
 
 Copyright © 2018 GMO CLOUD K.K.
 22
  • 23. Tanks! + PUN2 - 坦克資訊與狀態同步
 3. GameManager
 - Start()
 讓 MasterClient 去動態生成第一台坦克.
 讓第二位玩家去動態生成第二台坦克.
 
 
 
 
 
 
 Copyright © 2018 GMO CLOUD K.K.
 23
  • 24. 4. 在 Prefab- Tank 添加 CameraWork
 元件. 
 - 在 TankMovement 的 Start() 判斷為本機玩家時, 
 讓 Camera 跟隨玩家移動.
 
 
 
 
 
 
 
 Copyright © 2018 GMO CLOUD K.K.
 24 Tanks! + PUN2 - 相機跟隨坦克移動

  • 25. 5. 調整 Inspector 裡面參考到
 的 Tank 為 Resources 底下
 的 Prefab- Tank 
 
 
 
 
 
 
 
 
Copyright © 2018 GMO CLOUD K.K.
 25 Tanks! + PUN2 - 坦克資訊與狀態同步

  • 26. Tanks! + PUN2 - 砲彈資訊與狀態同步
 1. 將原本的 Prefab- Shell 拉到 Resources 資料夾, 創建為新的 Prefab- Shell.
 2. 再為新的 Prefab- Shell 添加 
 PhotonView 與 PhotonTransformView 兩個元件,
 並設定 Observed Components.
 
 
 
 Copyright © 2018 GMO CLOUD K.K.
 26
  • 27. Tanks! + PUN2 - 砲彈發射狀態同步
 3. TankShooting
 - OnPhotonSerializeView()
 同步砲彈發射狀態.
 - 將 TankShooting 加到 Prefab- Tank
 的 PhotonView 元件的 Observed Components.
 
 
 
 
 
 
 Copyright © 2018 GMO CLOUD K.K.
 27
  • 28. Thank you
 時間咻一下就過去了, 覺得意猶未盡嗎? 
 
 歡迎到我們的粉絲團一起來討論唷 ~
 粉絲團 https://www.facebook.com/photoncloudtw
 部落格 https://medium.com/photon-taiwan
 28