This commit is contained in:
2025-01-17 13:10:42 +01:00
commit 4536213c91
15115 changed files with 1442174 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
{
"displayName": "Simple Multiplayer",
"description": "Demonstrates how to set up a simple local multiplayer scenario."
}

View File

@@ -0,0 +1,127 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &5062027600983921548
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5062027600983921537}
- component: {fileID: 5062027600983921550}
- component: {fileID: 3984910858365239293}
- component: {fileID: -4472597160913118672}
m_Layer: 0
m_Name: Player
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &5062027600983921537
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5062027600983921548}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!20 &5062027600983921550
Camera:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5062027600983921548}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0}
m_FocalLength: 50
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 0
orthographic size: 5
m_Depth: -1
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 1
m_AllowMSAA: 1
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
--- !u!114 &3984910858365239293
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5062027600983921548}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 62899f850307741f2a39c98a8b639597, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Actions: {fileID: -944628639613478452, guid: 9547001c61582724894ebf550c5b4921,
type: 3}
m_NotificationBehavior: 0
m_UIInputModule: {fileID: 0}
m_DeviceLostEvent:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.InputSystem.PlayerInput+DeviceLostEvent, Unity.InputSystem,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_DeviceRegainedEvent:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.InputSystem.PlayerInput+DeviceRegainedEvent, Unity.InputSystem,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_ControlsChangedEvent:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.InputSystem.PlayerInput+ControlsChangedEvent, Unity.InputSystem,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_ActionEvents: []
m_NeverAutoSwitchControlSchemes: 0
m_DefaultControlScheme:
m_DefaultActionMap: Player
m_SplitScreenIndex: -1
m_Camera: {fileID: 5062027600983921550}
--- !u!114 &-4472597160913118672
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5062027600983921548}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4674e99101c1ae941b6a293e43c2af7a, type: 3}
m_Name:
m_EditorClassIdentifier:

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: e9f16d7642431df438e3f16792e6d57a
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,11 @@
# Simple Multiplayer Demo
This demo shows a simple local multiplayer setup. Players can join by pressing buttons on the supported devices. As players join, the screen is subdivided in split-screen fashion.
Joining is handled by the `PlayerManager` GameObject in the scene which has the `PlayerInputManager` component added to it. The component references [`Player.prefab`](./Player.prefab) which is instantiated for each player that joins the game.
The prefab contains a GameObject that has a `PlayerInput` component added to it. The component references the [actions](./SimpleMultiplayerControls.inputactions) available to each player which, by means of the control schemes defined in the asset, also determine the devices (and combinations of devices) supported by the game.
The actions available to each player are intentionally kept simple for this demonstration in order to not add irrelevant details. The only action available to players is `Teleport` which players can trigger through a button on their device. When trigger, they will be teleported to a random position within the game area. This serves to demonstrate that player inputs are indeed separate.
Note that each `PlayerInput` also references a `Camera` which is specific to each player. This is used by `PlayerInputManager` to configure the split-screen setup.

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 0c177fd59a9e5994981fe4ebd15bf72a
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,138 @@
{
"name": "SimpleMultiplayerControls",
"maps": [
{
"name": "Player",
"id": "fb8d6404-ed77-4dcb-9196-b47c736924a7",
"actions": [
{
"name": "Teleport",
"type": "Button",
"id": "da5efce7-0b41-45bb-9a3c-2c57823845bf",
"expectedControlType": "Button",
"processors": "",
"interactions": ""
}
],
"bindings": [
{
"name": "",
"id": "143bb1cd-cc10-4eca-a2f0-a3664166fe91",
"path": "<Gamepad>/rightTrigger",
"interactions": "",
"processors": "",
"groups": ";Gamepad",
"action": "Teleport",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "05f6913d-c316-48b2-a6bb-e225f14c7960",
"path": "<Mouse>/leftButton",
"interactions": "",
"processors": "",
"groups": ";Keyboard&Mouse",
"action": "Teleport",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "886e731e-7071-4ae4-95c0-e61739dad6fd",
"path": "<Touchscreen>/primaryTouch/tap",
"interactions": "",
"processors": "",
"groups": ";Touch",
"action": "Teleport",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "ee3d0cd2-254e-47a7-a8cb-bc94d9658c54",
"path": "<Joystick>/trigger",
"interactions": "",
"processors": "",
"groups": "Joystick",
"action": "Teleport",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "8255d333-5683-4943-a58a-ccb207ff1dce",
"path": "<XRController>/{PrimaryAction}",
"interactions": "",
"processors": "",
"groups": "XR",
"action": "Teleport",
"isComposite": false,
"isPartOfComposite": false
}
]
}
],
"controlSchemes": [
{
"name": "Keyboard&Mouse",
"bindingGroup": "Keyboard&Mouse",
"devices": [
{
"devicePath": "<Keyboard>",
"isOptional": false,
"isOR": false
},
{
"devicePath": "<Mouse>",
"isOptional": false,
"isOR": false
}
]
},
{
"name": "Gamepad",
"bindingGroup": "Gamepad",
"devices": [
{
"devicePath": "<Gamepad>",
"isOptional": false,
"isOR": false
}
]
},
{
"name": "Touch",
"bindingGroup": "Touch",
"devices": [
{
"devicePath": "<Touchscreen>",
"isOptional": false,
"isOR": false
}
]
},
{
"name": "Joystick",
"bindingGroup": "Joystick",
"devices": [
{
"devicePath": "<Joystick>",
"isOptional": false,
"isOR": false
}
]
},
{
"name": "XR",
"bindingGroup": "XR",
"devices": [
{
"devicePath": "<XRController>",
"isOptional": false,
"isOR": false
}
]
}
]
}

View File

@@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: 9547001c61582724894ebf550c5b4921
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3}
generateWrapperCode: 0
wrapperCodePath:
wrapperClassName:
wrapperCodeNamespace:

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: e3190afb97dc30d43aecffa09683a317
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,11 @@
using UnityEngine;
public class SimpleMultiplayerPlayer : MonoBehaviour
{
// Just add *some* kind of movement. The specifics here are not of interest. Serves just to
// demonstrate that the inputs are indeed separate.
public void OnTeleport()
{
transform.position = new Vector3(Random.Range(-75, 75), 0.5f, Random.Range(-75, 75));
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4674e99101c1ae941b6a293e43c2af7a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: