This commit is contained in:
zhangzheng
2026-02-27 18:35:40 +08:00
parent adef8b4cce
commit 1bb1fee5cc
265 changed files with 104076 additions and 92 deletions

View File

@@ -0,0 +1,21 @@
using UnityEngine;
namespace Unity.RenderStreaming.Samples
{
class FollowTransform : MonoBehaviour
{
[SerializeField] Transform target;
[SerializeField] Vector3 offset;
[SerializeField] bool followPosition;
[SerializeField] bool followRotation;
private void Update()
{
if (followPosition)
transform.localPosition = target.localPosition + offset;
if (followRotation)
transform.localRotation = target.localRotation;
}
}
}

View File

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

View File

@@ -0,0 +1,100 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &489449647258272010
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 489449647258272014}
- component: {fileID: 489449647258272009}
- component: {fileID: 2232263322929993776}
- component: {fileID: 6766063150928624591}
- component: {fileID: 1206473709398235252}
m_Layer: 0
m_Name: Guest
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &489449647258272014
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 489449647258272010}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
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!114 &489449647258272009
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 489449647258272010}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4ae253ffca93b1b44a471a07cde60141, type: 3}
m_Name:
m_EditorClassIdentifier:
streams:
- {fileID: 6766063150928624591}
- {fileID: 2232263322929993776}
- {fileID: 1206473709398235252}
--- !u!114 &2232263322929993776
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 489449647258272010}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4e6d9188eb6318c488077f3c88318a65, type: 3}
m_Name:
m_EditorClassIdentifier:
local: 1
label:
--- !u!114 &6766063150928624591
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 489449647258272010}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4872c2e12a0e07b498876d68f1e51143, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Codec:
m_MimeType:
m_SdpFmtpLine:
m_RenderMode: 1
m_TargetTexture: {fileID: 0}
--- !u!114 &1206473709398235252
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 489449647258272010}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 11af0c7644036f84bb5d375f2560b63f, type: 3}
m_Name:
m_EditorClassIdentifier:
local: 1
label:
OnChangeLabel:
m_PersistentCalls:
m_Calls: []

View File

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

View File

@@ -0,0 +1,46 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &1593075550384854350
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 343366018105980846}
- component: {fileID: 6663485387745853568}
m_Layer: 0
m_Name: Host
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &343366018105980846
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1593075550384854350}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
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!114 &6663485387745853568
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1593075550384854350}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6691f6e876a4bdc4c9027880cd9d7966, type: 3}
m_Name:
m_EditorClassIdentifier:
prefab: {fileID: 489449647258272010, guid: 091348b4c72dfb741927d9544fc7fbbd, type: 3}

View File

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

View File

@@ -0,0 +1,111 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace Unity.RenderStreaming.Samples
{
class Multiplay : SignalingHandlerBase,
IOfferHandler, IAddChannelHandler, IDisconnectHandler, IDeletedConnectionHandler
{
[SerializeField] GameObject prefab;
private List<string> connectionIds = new List<string>();
private List<Component> streams = new List<Component>();
private Dictionary<string, GameObject> dictObj = new Dictionary<string, GameObject>();
private RenderStreamingSettings settings;
void Awake()
{
settings = SampleManager.Instance.Settings;
}
public override IEnumerable<Component> Streams => streams;
public void OnDeletedConnection(SignalingEventData eventData)
{
Disconnect(eventData.connectionId);
}
public void OnDisconnect(SignalingEventData eventData)
{
Disconnect(eventData.connectionId);
}
private void Disconnect(string connectionId)
{
if (!connectionIds.Contains(connectionId))
return;
connectionIds.Remove(connectionId);
var obj = dictObj[connectionId];
var sender = obj.GetComponentInChildren<StreamSenderBase>();
var inputChannel = obj.GetComponentInChildren<InputReceiver>();
var multiplayChannel = obj.GetComponentInChildren<MultiplayChannel>();
dictObj.Remove(connectionId);
Object.Destroy(obj);
RemoveSender(connectionId, sender);
RemoveChannel(connectionId, inputChannel);
RemoveChannel(connectionId, multiplayChannel);
streams.Remove(sender);
streams.Remove(inputChannel);
streams.Remove(multiplayChannel);
if (ExistConnection(connectionId))
DeleteConnection(connectionId);
}
public void OnOffer(SignalingEventData data)
{
if (connectionIds.Contains(data.connectionId))
{
Debug.Log($"Already answered this connectionId : {data.connectionId}");
return;
}
connectionIds.Add(data.connectionId);
var initialPosition = new Vector3(0, 3, 0);
var newObj = Instantiate(prefab, initialPosition, Quaternion.identity);
dictObj.Add(data.connectionId, newObj);
var sender = newObj.GetComponentInChildren<StreamSenderBase>();
if (sender is VideoStreamSender videoStreamSender && settings != null)
{
videoStreamSender.width = (uint)settings.StreamSize.x;
videoStreamSender.height = (uint)settings.StreamSize.y;
videoStreamSender.SetCodec(settings.SenderVideoCodec);
}
var inputChannel = newObj.GetComponentInChildren<InputReceiver>();
var multiplayChannel = newObj.GetComponentInChildren<MultiplayChannel>();
var playerController = newObj.GetComponentInChildren<PlayerController>();
if (multiplayChannel.OnChangeLabel == null)
multiplayChannel.OnChangeLabel = new ChangeLabelEvent();
multiplayChannel.OnChangeLabel.AddListener(playerController.SetLabel);
streams.Add(sender);
streams.Add(inputChannel);
streams.Add(multiplayChannel);
AddSender(data.connectionId, sender);
AddChannel(data.connectionId, inputChannel);
AddChannel(data.connectionId, multiplayChannel);
SendAnswer(data.connectionId);
}
/// todo(kazuki)::
public void OnAddChannel(SignalingEventData data)
{
var obj = dictObj[data.connectionId];
var channels = obj.GetComponentsInChildren<IDataChannel>();
var channel = channels.FirstOrDefault(_ => !_.IsLocal && !_.IsConnected);
channel?.SetChannel(data);
}
}
}

View File

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

View File

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

View File

@@ -0,0 +1,54 @@
using System;
using UnityEngine;
using UnityEngine.Events;
namespace Unity.RenderStreaming.Samples
{
enum ActionType
{
ChangeLabel = 0,
}
[Serializable]
class Message
{
public ActionType type;
public string argument;
}
/// <summary>
///
/// </summary>
[Serializable]
class ChangeLabelEvent : UnityEvent<string> { };
/// <summary>
///
/// </summary>
class MultiplayChannel : DataChannelBase
{
public ChangeLabelEvent OnChangeLabel;
protected override void OnMessage(byte[] bytes)
{
string str = System.Text.Encoding.UTF8.GetString(bytes);
var message = JsonUtility.FromJson<Message>(str);
switch (message.type)
{
case ActionType.ChangeLabel:
OnChangeLabel?.Invoke(message.argument);
return;
}
}
public void ChangeLabel(string text)
{
var msg = new Message
{
type = ActionType.ChangeLabel,
argument = text
};
Send(JsonUtility.ToJson(msg));
}
}
}

View File

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

View File

@@ -0,0 +1,132 @@
using System;
using System.Collections;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
namespace Unity.RenderStreaming.Samples
{
class MultiplaySample : MonoBehaviour
{
[SerializeField] ToggleGroup toggleGroupRole;
[SerializeField] InputField inputFieldUsername;
[SerializeField] Button buttonStart;
[SerializeField] SignalingManager renderStreaming;
[SerializeField] GameObject prefabHost;
[SerializeField] GameObject prefabGuest;
[SerializeField] GameObject prefabPlayer;
[SerializeField] GameObject menuCamera;
[SerializeField] GameObject panel;
[SerializeField] RawImage videoImage;
[SerializeField] ShowStatsUI statsUI;
enum Role
{
Host = 0,
Guest = 1
}
private RenderStreamingSettings settings;
private void Awake()
{
settings = SampleManager.Instance.Settings;
}
void Start()
{
buttonStart.onClick.AddListener(OnClickButtonStart);
inputFieldUsername.text = UnityEngine.Random.Range(0, 99999).ToString("00000");
inputFieldUsername.onValueChanged.AddListener(OnValueChangedUserName);
}
void OnValueChangedUserName(string value)
{
bool hasNullValue =
string.IsNullOrEmpty(inputFieldUsername.text);
buttonStart.interactable = !hasNullValue;
}
void OnClickButtonStart()
{
var username = inputFieldUsername.text;
var connectionId = Guid.NewGuid().ToString();
var toggles = toggleGroupRole.GetComponentsInChildren<Toggle>();
var activeToggle = toggleGroupRole.ActiveToggles().First();
var indexRole = Array.FindIndex(toggles, _ => _ == activeToggle);
var role = (Role)indexRole;
panel.SetActive(false);
switch (role)
{
case Role.Host:
SetUpHost(username);
break;
case Role.Guest:
StartCoroutine(SetUpGuest(username, connectionId));
break;
}
}
void SetUpHost(string username)
{
menuCamera.SetActive(false);
var instance = GameObject.Instantiate(prefabHost);
var handler = instance.GetComponent<Multiplay>();
// host player
var hostPlayer = GameObject.Instantiate(prefabPlayer);
var playerController = hostPlayer.GetComponent<PlayerController>();
playerController.SetLabel(username);
var playerInput = hostPlayer.GetComponent<InputReceiver>();
playerInput.PerformPairingWithAllLocalDevices();
playerController.CheckPairedDevices();
statsUI.AddSignalingHandler(handler);
if (settings != null)
renderStreaming.useDefaultSettings = settings.UseDefaultSettings;
if (settings?.SignalingSettings != null)
renderStreaming.SetSignalingSettings(settings.SignalingSettings);
renderStreaming.Run(handlers: new SignalingHandlerBase[] { handler });
}
IEnumerator SetUpGuest(string username, string connectionId)
{
var guestPlayer = GameObject.Instantiate(prefabGuest);
var handler = guestPlayer.GetComponent<SingleConnection>();
statsUI.AddSignalingHandler(handler);
if (settings != null)
renderStreaming.useDefaultSettings = settings.UseDefaultSettings;
if (settings?.SignalingSettings != null)
renderStreaming.SetSignalingSettings(settings.SignalingSettings);
renderStreaming.Run(handlers: new SignalingHandlerBase[] { handler });
videoImage.gameObject.SetActive(true);
var receiveVideoViewer = guestPlayer.GetComponent<VideoStreamReceiver>();
receiveVideoViewer.OnUpdateReceiveTexture += texture => videoImage.texture = texture;
var channel = guestPlayer.GetComponent<MultiplayChannel>();
channel.OnStartedChannel += _ => { StartCoroutine(ChangeLabel(channel, username)); };
if (settings != null)
receiveVideoViewer.SetCodec(settings.ReceiverVideoCodec);
// todo(kazuki):
yield return new WaitForSeconds(1f);
handler.CreateConnection(connectionId);
yield return new WaitUntil(() => handler.IsConnected(connectionId));
}
IEnumerator ChangeLabel(MultiplayChannel channel, string username)
{
yield return new WaitUntil(() => channel.IsConnected);
channel.ChangeLabel(username);
}
}
}

View File

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

View File

@@ -0,0 +1,636 @@
{
"name": "Player",
"maps": [
{
"name": "Player Controls",
"id": "cb4067f3-a685-4c86-b9ea-46a6eabfada7",
"actions": [
{
"name": "Movement",
"type": "Value",
"id": "548e32fd-77d1-40e5-8197-32ca56b41bc0",
"expectedControlType": "Vector2",
"processors": "",
"interactions": ""
},
{
"name": "Look",
"type": "Value",
"id": "8ebbde1f-3044-41bc-bdac-430e0eae1a68",
"expectedControlType": "Vector2",
"processors": "",
"interactions": ""
},
{
"name": "Jump",
"type": "Button",
"id": "10fecf58-9483-40e0-ae20-15c8d01a4288",
"expectedControlType": "",
"processors": "",
"interactions": "Press"
},
{
"name": "TogglePause",
"type": "Button",
"id": "a70a208e-b491-4921-b460-a0144030ef2a",
"expectedControlType": "Button",
"processors": "",
"interactions": "Press"
}
],
"bindings": [
{
"name": "WASD",
"id": "99258992-afbc-4513-a4ee-24146566e341",
"path": "2DVector",
"interactions": "",
"processors": "",
"groups": "",
"action": "Movement",
"isComposite": true,
"isPartOfComposite": false
},
{
"name": "up",
"id": "d57e0987-ea9f-4b18-9042-239931d4c060",
"path": "<Keyboard>/w",
"interactions": "",
"processors": "",
"groups": "Keyboard And Mouse",
"action": "Movement",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "down",
"id": "75168890-922f-4122-9968-1ecac0f33c28",
"path": "<Keyboard>/s",
"interactions": "",
"processors": "",
"groups": "Keyboard And Mouse",
"action": "Movement",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "left",
"id": "54b99838-0c45-421e-af38-b1f25b3f6927",
"path": "<Keyboard>/a",
"interactions": "",
"processors": "",
"groups": "Keyboard And Mouse",
"action": "Movement",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "right",
"id": "77680fb0-0b9d-4a74-97de-9e3149ad6526",
"path": "<Keyboard>/d",
"interactions": "",
"processors": "",
"groups": "Keyboard And Mouse",
"action": "Movement",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "",
"id": "df04a4e1-fc36-4ebd-b050-536736220da7",
"path": "<Gamepad>/leftStick",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Movement",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "be6b2b51-d13a-4040-bb92-a825e7d4f764",
"path": "<Touchscreen>/primaryTouch/delta",
"interactions": "",
"processors": "ScaleVector2(x=0.3,y=0.3)",
"groups": "Touchscreen",
"action": "Movement",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "42716e15-291c-4c71-8ded-0d03279959df",
"path": "<Keyboard>/p",
"interactions": "",
"processors": "",
"groups": "Keyboard And Mouse",
"action": "TogglePause",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "7bc14fbd-1107-4761-aa6f-b3367d7705e6",
"path": "<Gamepad>/start",
"interactions": "",
"processors": "",
"groups": "",
"action": "TogglePause",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "b12426a0-38ab-4d90-95e0-6840fcd30db6",
"path": "<Keyboard>/space",
"interactions": "",
"processors": "",
"groups": "Keyboard And Mouse",
"action": "Jump",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "3e6d6425-a990-4434-b58d-57464db363d4",
"path": "<Gamepad>/buttonSouth",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Jump",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "faa12d77-e42c-4d9f-9871-56381a35ba8f",
"path": "<Touchscreen>/primaryTouch/tap",
"interactions": "",
"processors": "",
"groups": "Touchscreen",
"action": "Jump",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "43d1488b-4ff2-4456-b1bf-a368a70fb680",
"path": "<Mouse>/delta",
"interactions": "",
"processors": "",
"groups": "Keyboard And Mouse",
"action": "Look",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "d23f9eb5-e32b-417b-8edf-d10cd6bdc1d3",
"path": "<Gamepad>/rightStick",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Look",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "48bc601e-db29-4e46-8a0f-3698ec3025a4",
"path": "<Touchscreen>/touch1/delta",
"interactions": "",
"processors": "ScaleVector2(x=0.3,y=0.3)",
"groups": "Touchscreen",
"action": "Look",
"isComposite": false,
"isPartOfComposite": false
}
]
},
{
"name": "Menu Controls",
"id": "0914fb5b-51f6-4b26-9ed7-a3e72d065118",
"actions": [
{
"name": "Navigate",
"type": "PassThrough",
"id": "538ffe95-ba92-4acb-84f7-314f6ac8e0a5",
"expectedControlType": "Vector2",
"processors": "",
"interactions": ""
},
{
"name": "Left Click",
"type": "PassThrough",
"id": "96c8be88-a7bb-4861-b5e9-956b4208d043",
"expectedControlType": "Button",
"processors": "",
"interactions": ""
},
{
"name": "Point",
"type": "PassThrough",
"id": "d54e5ff5-4f35-4d2f-a745-95d14aef8c43",
"expectedControlType": "Vector2",
"processors": "",
"interactions": ""
},
{
"name": "Submit",
"type": "PassThrough",
"id": "5f571f6a-e9e7-4120-ae3c-79f846bdd202",
"expectedControlType": "Button",
"processors": "",
"interactions": ""
},
{
"name": "Cancel",
"type": "PassThrough",
"id": "146e681c-77dd-4ff0-9ad5-f4351fea14cc",
"expectedControlType": "Button",
"processors": "",
"interactions": ""
},
{
"name": "TogglePause",
"type": "Button",
"id": "e773b1f9-ce5b-4fa2-9c1f-d194202c43b7",
"expectedControlType": "",
"processors": "",
"interactions": "Press"
}
],
"bindings": [
{
"name": "Gamepad Right Stick",
"id": "c1491510-9d0f-47b0-868e-99575e46d097",
"path": "2DVector",
"interactions": "",
"processors": "",
"groups": "",
"action": "Navigate",
"isComposite": true,
"isPartOfComposite": false
},
{
"name": "up",
"id": "57fb7217-68c1-483e-a15b-0fd1e5ab3fc3",
"path": "<Gamepad>/leftStick/up",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "down",
"id": "0c09243f-be8c-44a1-87c4-a0d3ca3a27a5",
"path": "<Gamepad>/leftStick/down",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "left",
"id": "a16b4641-1591-4d94-9fd4-e1eafd539931",
"path": "<Gamepad>/leftStick/left",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "right",
"id": "341f36e1-889b-4d62-834f-622378da658d",
"path": "<Gamepad>/leftStick/right",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "Gamepad Left Stick",
"id": "c2c92ef2-a9d0-4393-86c7-4180acc16b6d",
"path": "2DVector",
"interactions": "",
"processors": "",
"groups": "",
"action": "Navigate",
"isComposite": true,
"isPartOfComposite": false
},
{
"name": "up",
"id": "bed70561-f1cc-4c56-9715-66475aa6437f",
"path": "<Gamepad>/leftStick/up",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "down",
"id": "0005d032-151a-4ee0-8127-110d55e5ed9d",
"path": "<Gamepad>/leftStick/down",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "left",
"id": "84fcadd5-5853-4142-b3f9-58a5ab2ad788",
"path": "<Gamepad>/leftStick/left",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "right",
"id": "233f731d-8d73-4761-8879-66c0e0da124d",
"path": "<Gamepad>/leftStick/right",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "",
"id": "d687f18d-7559-488c-8542-e3da3a3dd1f7",
"path": "<Gamepad>/dpad",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "WASD Keys",
"id": "c2a77ff0-1ce1-4c49-a4dd-94601087a2a2",
"path": "2DVector",
"interactions": "",
"processors": "",
"groups": "",
"action": "Navigate",
"isComposite": true,
"isPartOfComposite": false
},
{
"name": "up",
"id": "a67b96dc-9151-496b-9be2-b4d65a82f52a",
"path": "<Keyboard>/w",
"interactions": "",
"processors": "",
"groups": "Keyboard And Mouse",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "down",
"id": "4f8ac3a8-5653-4cf1-9687-259b7e6bfca4",
"path": "<Keyboard>/s",
"interactions": "",
"processors": "",
"groups": "Keyboard And Mouse",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "left",
"id": "a3da140b-c504-4aea-9824-ffd10d44e52a",
"path": "<Keyboard>/a",
"interactions": "",
"processors": "",
"groups": "Keyboard And Mouse",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "right",
"id": "d2cdc452-d127-4c2c-b57c-1f78e29cb425",
"path": "<Keyboard>/d",
"interactions": "",
"processors": "",
"groups": "Keyboard And Mouse",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "Arrow Keys",
"id": "c50ac654-ca86-486c-b427-057a0aacbb3b",
"path": "2DVector",
"interactions": "",
"processors": "",
"groups": "",
"action": "Navigate",
"isComposite": true,
"isPartOfComposite": false
},
{
"name": "up",
"id": "80a43030-09a8-4324-b825-39a685b9a975",
"path": "<Keyboard>/upArrow",
"interactions": "",
"processors": "",
"groups": "Keyboard And Mouse",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "down",
"id": "0284caff-9cfb-477f-901c-c6be4082785f",
"path": "<Keyboard>/downArrow",
"interactions": "",
"processors": "",
"groups": "Keyboard And Mouse",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "left",
"id": "359d5348-82b3-4e60-9536-8c817495d31a",
"path": "<Keyboard>/leftArrow",
"interactions": "",
"processors": "",
"groups": "Keyboard And Mouse",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "right",
"id": "b77717c3-b7e9-450f-8bc2-3aa284fac5cd",
"path": "<Keyboard>/rightArrow",
"interactions": "",
"processors": "",
"groups": "Keyboard And Mouse",
"action": "Navigate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "",
"id": "b5076a57-fe62-4632-8d6c-da0844960a14",
"path": "<Mouse>/position",
"interactions": "",
"processors": "",
"groups": "Keyboard And Mouse",
"action": "Point",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "e7658a78-a141-4f0c-beb5-0a6a3e393c7b",
"path": "<Touchscreen>/touch*/position",
"interactions": "",
"processors": "",
"groups": "Touchscreen",
"action": "Point",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "dfac3b8e-d348-4a7a-b60b-14745c641340",
"path": "<Keyboard>/p",
"interactions": "",
"processors": "",
"groups": "Keyboard And Mouse",
"action": "TogglePause",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "f509a7b5-e79a-485e-ba2f-da5431d6fe4c",
"path": "<Gamepad>/start",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "TogglePause",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "6fee8919-99e7-4770-abd4-da1b7d4e4cc4",
"path": "*/{Cancel}",
"interactions": "",
"processors": "",
"groups": "",
"action": "Cancel",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "14559c94-e8a7-426b-8687-fa5f1420a0c1",
"path": "<Mouse>/leftButton",
"interactions": "",
"processors": "",
"groups": "Keyboard And Mouse",
"action": "Left Click",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "b35f103a-716c-4078-ad8d-66c5fb7fbb45",
"path": "<Touchscreen>/touch*/press",
"interactions": "",
"processors": "",
"groups": "Touchscreen",
"action": "Left Click",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "40b14102-9017-4522-862f-97d92a0da5f6",
"path": "*/{Submit}",
"interactions": "",
"processors": "",
"groups": "",
"action": "Submit",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "c88534db-dffe-4245-85c8-f41ba53024a1",
"path": "<Gamepad>/buttonSouth",
"interactions": "",
"processors": "",
"groups": "",
"action": "Submit",
"isComposite": false,
"isPartOfComposite": false
}
]
}
],
"controlSchemes": [
{
"name": "Gamepad",
"bindingGroup": "Gamepad",
"devices": [
{
"devicePath": "<Gamepad>",
"isOptional": false,
"isOR": false
}
]
},
{
"name": "Keyboard And Mouse",
"bindingGroup": "Keyboard And Mouse",
"devices": [
{
"devicePath": "<Keyboard>",
"isOptional": false,
"isOR": false
},
{
"devicePath": "<Mouse>",
"isOptional": false,
"isOR": false
}
]
},
{
"name": "Touchscreen",
"bindingGroup": "Touchscreen",
"devices": [
{
"devicePath": "<Touchscreen>",
"isOptional": false,
"isOR": false
}
]
}
]
}

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

@@ -0,0 +1,133 @@
using System.Linq;
using UnityEngine;
using UnityEngine.InputSystem;
namespace Unity.RenderStreaming.Samples
{
class PlayerController : MonoBehaviour
{
[SerializeField] GameObject player;
[SerializeField] GameObject cameraPivot;
[SerializeField] InputReceiver playerInput;
[SerializeField] TextMesh label;
[SerializeField] GameObject captionForMobile;
[SerializeField] GameObject captionForDesktop;
[SerializeField] float moveSpeed = 100f;
[SerializeField] float rotateSpeed = 10f;
[SerializeField] float jumpSpeed = 500f;
const float CooldownJump = 1.2f; // second
Vector2 inputMovement;
Vector2 inputLook;
Vector3 initialPosition;
bool inputJump;
float cooldownJumpDelta = CooldownJump;
protected void Awake()
{
playerInput.onDeviceChange += OnDeviceChange;
initialPosition = transform.position;
}
void OnDeviceChange(InputDevice device, InputDeviceChange change)
{
switch (change)
{
case InputDeviceChange.Added:
{
playerInput.PerformPairingWithDevice(device);
CheckPairedDevices();
return;
}
case InputDeviceChange.Removed:
{
playerInput.UnpairDevices(device);
CheckPairedDevices();
return;
}
}
}
public void CheckPairedDevices()
{
if (!playerInput.user.valid)
return;
bool hasTouchscreenDevice =
playerInput.user.pairedDevices.Count(_ => _.path.Contains("Touchscreen")) > 0;
captionForMobile.SetActive(hasTouchscreenDevice);
captionForDesktop.SetActive(!hasTouchscreenDevice);
}
private void Update()
{
var forwardDirection = Quaternion.Euler(0, cameraPivot.transform.eulerAngles.y, 0);
var moveForward = forwardDirection * new Vector3(inputMovement.x, 0, inputMovement.y);
player.GetComponent<Rigidbody>().AddForce(moveForward * Time.deltaTime * moveSpeed);
var moveAngles = new Vector3(-inputLook.y, inputLook.x);
var newAngles = cameraPivot.transform.localEulerAngles + moveAngles * Time.deltaTime * rotateSpeed;
cameraPivot.transform.localEulerAngles = new Vector3(Mathf.Clamp(newAngles.x, 0, 45), newAngles.y, 0);
if (inputJump && cooldownJumpDelta <= 0.0f)
{
var jumpForward = forwardDirection * new Vector3(0, 1f, 0);
player.GetComponent<Rigidbody>().AddForce(jumpForward * jumpSpeed);
cooldownJumpDelta = CooldownJump;
}
// jump cooldown
if (cooldownJumpDelta >= 0.0f)
{
inputJump = false;
cooldownJumpDelta -= Time.deltaTime;
}
// reset if the ball fall down from the floor
if (player.transform.position.y < -5)
{
player.transform.position = initialPosition;
player.GetComponent<Rigidbody>().velocity = Vector3.zero;
}
}
public void SetLabel(string text)
{
label.text = text;
}
public void OnControlsChanged()
{
}
public void OnDeviceLost()
{
}
public void OnDeviceRegained()
{
}
public void OnMovement(InputAction.CallbackContext value)
{
inputMovement = value.ReadValue<Vector2>();
}
public void OnLook(InputAction.CallbackContext value)
{
inputLook = value.ReadValue<Vector2>();
}
public void OnJump(InputAction.CallbackContext value)
{
if (value.performed)
{
inputJump = true;
}
}
}
}

View File

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