Skip to content

Commit

Permalink
feat: More examples for Mirror Cloud Service (#2029)
Browse files Browse the repository at this point in the history
* fixing pong spawn points

* renaming files and asmdef

* More Cloud examples

* Moving pong example to cloud folder
* Moving shared code to GUI folder
* Adding readme for examples
* Adding tank example
  • Loading branch information
James-Frowen committed Jun 25, 2020
1 parent 54a69bb commit 7d0e907
Show file tree
Hide file tree
Showing 77 changed files with 987 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Mirror.CloudServices",
"name": "Mirror.Cloud",
"references": [
"Mirror"
],
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Mirror/Examples/Cloud/GUI.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Mirror/Examples/Cloud/GUI/Prefabs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Mirror/Examples/Cloud/GUI/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Cloud GUI

This folder contains an example of a List server canvas and scripts that can help set up a GUI.


## Other Examples

See `PongWithListServer` or `TanksWithListServer` for playable examples
7 changes: 7 additions & 0 deletions Assets/Mirror/Examples/Cloud/GUI/README.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Mirror/Examples/Cloud/GUI/Scripts.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@

namespace Mirror.CloudServices.Example
{
/// <summary>
/// This component should be put on the NetworkManager object
/// </summary>
public class ApiUpdater : MonoBehaviour
{
NetworkManagerListServerPong manager;
NetworkManagerListServer manager;
ApiConnector connector;

void Start()
{
manager = NetworkManager.singleton as NetworkManagerListServerPong;
manager = NetworkManager.singleton as NetworkManagerListServer;
connector = manager.GetComponent<ApiConnector>();

manager.onPlayerListChanged += onPlayerListChanged;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Mirror.CloudServices.Examples
{
/// <summary>
/// Instantiate a new NetworkManager if one does not already exist
/// </summary>
public class InstantiateNetworkManager : MonoBehaviour
{
public GameObject prefab;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"name": "Mirror.Examples.CloudService",
"name": "Mirror.Examples.Cloud.GUI",
"references": [
"Mirror",
"Mirror.Components",
"Mirror.CloudServices"
"Mirror.Cloud"
],
"optionalUnityReferences": [],
"includePlatforms": [],
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace Mirror.CloudServices.Example
{
public class NetworkManagerListServerPong : NetworkManager
/// <summary>
/// Network Manager with events that are used by the list server
/// </summary>
public class NetworkManagerListServer : NetworkManager
{
/// <summary>
/// Called when Server Starts
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace Mirror.Examples.Pong
{
public class QuitButton : MonoBehaviour
/// <summary>
/// Simular to NetworkManagerHUD but just quit buttons
/// </summary>
public class QuitButtonHUD : MonoBehaviour
{
void OnGUI()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

namespace Mirror.CloudServices.Example
{
/// <summary>
/// Uses the ApiConnector on NetworkManager to update the Server list
/// </summary>
public class ServerListManager : MonoBehaviour
{
[Header("UI")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace Mirror.CloudServices.Example
{
/// <summary>
/// Displays the list of servers
/// </summary>
public class ServerListUI : MonoBehaviour
{
[SerializeField] ServerListUIItem itemPrefab = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

namespace Mirror.CloudServices.Example
{
/// <summary>
/// Displays a server created by ServerListUI
/// </summary>
public class ServerListUIItem : MonoBehaviour
{
[SerializeField] Text nameText = null;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ GameObject:
- component: {fileID: 1442807832621757098}
- component: {fileID: 4798169800353248834}
m_Layer: 0
m_Name: NetworkManager
m_Name: NetworkManagerPong
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
Expand Down Expand Up @@ -51,7 +51,7 @@ MonoBehaviour:
_onServerListUpdated:
m_PersistentCalls:
m_Calls: []
m_TypeName: Mirror.CloudServices.ServerListEvent, Mirror.CloudServices, Version=0.0.0.0,
m_TypeName: Mirror.CloudServices.ServerListEvent, Mirror.Cloud, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
--- !u!114 &5399210850297115757
MonoBehaviour:
Expand Down Expand Up @@ -80,10 +80,10 @@ MonoBehaviour:
dontDestroyOnLoad: 1
runInBackground: 1
startOnHeadless: 1
showDebugMessages: 1
showDebugMessages: 0
serverTickRate: 30
offlineScene: Assets/Mirror/Examples/PongWithListServer/Scenes/ListServerLobbyScene.unity
onlineScene: Assets/Mirror/Examples/PongWithListServer/Scenes/PongGameScene.unity
offlineScene: Assets/Mirror/Examples/Cloud/PongWithListServer/Scenes/ListServerLobbyScenePong.unity
onlineScene: Assets/Mirror/Examples/Cloud/PongWithListServer/Scenes/PongGameScene.unity
transport: {fileID: 4798169800353248834}
networkAddress: localhost
maxConnections: 2
Expand Down
19 changes: 19 additions & 0 deletions Assets/Mirror/Examples/Cloud/PongWithListServer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Pong with Cloud List server

This is an example that uses the list server to find games of pong

## Setup

Add the following scenes to build settings
```
Mirror\Examples\Cloud\PongWithListServer\Scenes\ListServerLobbyScenePong.unity
Mirror\Examples\Cloud\PongWithListServer\Scenes\PongGameScene.unity
```
> Note: you can not connect to your own public ip address, to test out ServerOnly you will need a 2nd person (or a 2nd internet connection)
## Api Key

Api key on the NetworkManager is a demo key that should not be used in production.

Visit [Mirror Networking](https://mirror-networking.com/list-server/) to get an api key that you can use in your game.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "Mirror.Examples.Cloud.Pong",
"references": [
"Mirror",
"Mirror.Cloud",
"Mirror.Examples.Cloud.GUI"
],
"optionalUnityReferences": [],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using UnityEngine;

namespace Mirror.CloudServices.Example
{
public sealed class NetworkManagerListServerPong : NetworkManagerListServer
{
public override void OnServerAddPlayer(NetworkConnection conn)
{
Debug.Assert(startPositions.Count == 2, "Pong Scene should have 2 start Poitions");
// add player at correct spawn position
Transform startPos = numPlayers == 0 ? startPositions[0] : startPositions[1];

GameObject player = startPos != null
? Instantiate(playerPrefab, startPos.position, startPos.rotation)
: Instantiate(playerPrefab);

NetworkServer.AddPlayerForConnection(conn, player);
}
}
}
8 changes: 8 additions & 0 deletions Assets/Mirror/Examples/Cloud/TanksWithListServer.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Mirror/Examples/Cloud/TanksWithListServer/Prefabs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7d0e907

Please sign in to comment.