111
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f47df8540d2ee994196abbd7365855f2
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,287 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.InputSystem.Layouts;
|
||||
using UnityEngine.InputSystem.XR;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Unity.RenderStreaming.Samples
|
||||
{
|
||||
using InputSystem = UnityEngine.InputSystem.InputSystem;
|
||||
|
||||
static class InputReceiverExtension
|
||||
{
|
||||
public static void CalculateInputRegion(this InputReceiver reveiver, Vector2Int size)
|
||||
{
|
||||
reveiver.CalculateInputRegion(size, new Rect(0, 0, Screen.width, Screen.height));
|
||||
}
|
||||
}
|
||||
|
||||
static class InputActionExtension
|
||||
{
|
||||
public static void AddListener(this InputAction action, Action<InputAction.CallbackContext> callback)
|
||||
{
|
||||
action.started += callback;
|
||||
action.performed += callback;
|
||||
action.canceled += callback;
|
||||
}
|
||||
}
|
||||
|
||||
class BroadcastSample : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private SignalingManager renderStreaming;
|
||||
[SerializeField] private InputReceiver inputReceiver;
|
||||
[SerializeField] private SimpleCameraControllerV2 cameraController;
|
||||
[SerializeField] private UIControllerV2 uiController;
|
||||
[SerializeField] private VideoStreamSender videoStreamSender;
|
||||
[SerializeField] private Dropdown videoSourceTypeSelector;
|
||||
[SerializeField] private Dropdown bandwidthSelector;
|
||||
[SerializeField] private Dropdown scaleResolutionDownSelector;
|
||||
[SerializeField] private Dropdown framerateSelector;
|
||||
[SerializeField] private Dropdown resolutionSelector;
|
||||
|
||||
private Dictionary<string, VideoStreamSource> videoSourceTypeOptions = new Dictionary<string, VideoStreamSource>
|
||||
{
|
||||
{"Screen", VideoStreamSource.Screen },
|
||||
{"Camera", VideoStreamSource.Camera },
|
||||
{"Texture", VideoStreamSource.Texture },
|
||||
{"WebCam", VideoStreamSource.WebCamera }
|
||||
};
|
||||
|
||||
private Dictionary<string, uint> bandwidthOptions =
|
||||
new Dictionary<string, uint>()
|
||||
{
|
||||
{ "10000", 10000 },
|
||||
{ "2000", 2000 },
|
||||
{ "1000", 1000 },
|
||||
{ "500", 500 },
|
||||
{ "250", 250 },
|
||||
{ "125", 125 },
|
||||
};
|
||||
|
||||
private Dictionary<string, float> scaleResolutionDownOptions =
|
||||
new Dictionary<string, float>()
|
||||
{
|
||||
{ "Not scaling", 1.0f },
|
||||
{ "Down scale by 2.0", 2.0f },
|
||||
{ "Down scale by 4.0", 4.0f },
|
||||
{ "Down scale by 8.0", 8.0f },
|
||||
{ "Down scale by 16.0", 16.0f }
|
||||
};
|
||||
|
||||
private Dictionary<string, float> framerateOptions =
|
||||
new Dictionary<string, float>
|
||||
{
|
||||
{ "90", 90f },
|
||||
{ "60", 60f },
|
||||
{ "30", 30f },
|
||||
{ "20", 20f },
|
||||
{ "10", 10f },
|
||||
{ "5", 5f },
|
||||
};
|
||||
|
||||
private Dictionary<string, Vector2Int> resolutionOptions =
|
||||
new Dictionary<string, Vector2Int>
|
||||
{
|
||||
{ "640x480", new Vector2Int(640, 480) },
|
||||
{ "1280x720", new Vector2Int(1280, 720) },
|
||||
{ "1600x1200", new Vector2Int(1600, 1200) },
|
||||
{ "1920x1200", new Vector2Int(1920, 1200) },
|
||||
{ "2560x1440", new Vector2Int(2560, 1440) },
|
||||
};
|
||||
|
||||
private RenderStreamingSettings settings;
|
||||
private int lastWidth;
|
||||
private int lastHeight;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
#if URS_USE_AR_FOUNDATION
|
||||
InputSystem.RegisterLayout<UnityEngine.XR.ARSubsystems.HandheldARInputDevice>(
|
||||
matches: new InputDeviceMatcher()
|
||||
.WithInterface(XRUtilities.InterfaceMatchAnyVersion)
|
||||
);
|
||||
#endif
|
||||
settings = SampleManager.Instance.Settings;
|
||||
if (settings != null)
|
||||
{
|
||||
if (videoStreamSender.source != VideoStreamSource.Texture)
|
||||
{
|
||||
videoStreamSender.width = (uint)settings.StreamSize.x;
|
||||
videoStreamSender.height = (uint)settings.StreamSize.y;
|
||||
}
|
||||
videoStreamSender.SetCodec(settings.SenderVideoCodec);
|
||||
}
|
||||
videoSourceTypeSelector.options = videoSourceTypeOptions
|
||||
.Select(pair => new Dropdown.OptionData { text = pair.Key })
|
||||
.ToList();
|
||||
videoSourceTypeSelector.onValueChanged.AddListener(ChangeVideoSourceType);
|
||||
|
||||
bandwidthSelector.options = bandwidthOptions
|
||||
.Select(pair => new Dropdown.OptionData { text = pair.Key })
|
||||
.ToList();
|
||||
bandwidthSelector.options.Add(new Dropdown.OptionData { text = "Custom" });
|
||||
bandwidthSelector.onValueChanged.AddListener(ChangeBandwidth);
|
||||
|
||||
scaleResolutionDownSelector.options = scaleResolutionDownOptions
|
||||
.Select(pair => new Dropdown.OptionData { text = pair.Key })
|
||||
.ToList();
|
||||
scaleResolutionDownSelector.options.Add(new Dropdown.OptionData { text = "Custom" });
|
||||
scaleResolutionDownSelector.onValueChanged.AddListener(ChangeScaleResolutionDown);
|
||||
|
||||
framerateSelector.options = framerateOptions
|
||||
.Select(pair => new Dropdown.OptionData { text = pair.Key })
|
||||
.ToList();
|
||||
framerateSelector.options.Add(new Dropdown.OptionData { text = "Custom" });
|
||||
framerateSelector.onValueChanged.AddListener(ChangeFramerate);
|
||||
|
||||
resolutionSelector.options = resolutionOptions
|
||||
.Select(pair => new Dropdown.OptionData { text = pair.Key })
|
||||
.ToList();
|
||||
resolutionSelector.options.Add(new Dropdown.OptionData { text = "Custom" });
|
||||
resolutionSelector.onValueChanged.AddListener(ChangeResolution);
|
||||
}
|
||||
|
||||
private void ChangeVideoSourceType(int index)
|
||||
{
|
||||
var source = videoSourceTypeOptions.Values.ElementAt(index);
|
||||
videoStreamSender.source = source;
|
||||
}
|
||||
|
||||
private void ChangeBandwidth(int index)
|
||||
{
|
||||
var bitrate = bandwidthOptions.Values.ElementAt(index);
|
||||
videoStreamSender.SetBitrate(bitrate, bitrate);
|
||||
}
|
||||
|
||||
private void ChangeScaleResolutionDown(int index)
|
||||
{
|
||||
var scale = scaleResolutionDownOptions.Values.ElementAt(index);
|
||||
videoStreamSender.SetScaleResolutionDown(scale);
|
||||
CalculateInputRegion();
|
||||
}
|
||||
|
||||
private void ChangeFramerate(int index)
|
||||
{
|
||||
var framerate = framerateOptions.Values.ElementAt(index);
|
||||
videoStreamSender.SetFrameRate(framerate);
|
||||
}
|
||||
|
||||
private void ChangeResolution(int index)
|
||||
{
|
||||
var resolution = resolutionOptions.Values.ElementAt(index);
|
||||
|
||||
videoStreamSender.SetTextureSize(resolution);
|
||||
CalculateInputRegion();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
SyncDisplayVideoSenderParameters();
|
||||
|
||||
if (renderStreaming.runOnAwake)
|
||||
return;
|
||||
if (settings != null)
|
||||
renderStreaming.useDefaultSettings = settings.UseDefaultSettings;
|
||||
if (settings?.SignalingSettings != null)
|
||||
renderStreaming.SetSignalingSettings(settings.SignalingSettings);
|
||||
renderStreaming.Run();
|
||||
|
||||
inputReceiver.OnStartedChannel += OnStartedChannel;
|
||||
var map = inputReceiver.currentActionMap;
|
||||
map["Movement"].AddListener(cameraController.OnMovement);
|
||||
map["Look"].AddListener(cameraController.OnLook);
|
||||
map["ResetCamera"].AddListener(cameraController.OnResetCamera);
|
||||
map["Rotate"].AddListener(cameraController.OnRotate);
|
||||
map["Position"].AddListener(cameraController.OnPosition);
|
||||
map["Point"].AddListener(uiController.OnPoint);
|
||||
map["Press"].AddListener(uiController.OnPress);
|
||||
map["PressAnyKey"].AddListener(uiController.OnPressAnyKey);
|
||||
}
|
||||
|
||||
private void OnStartedChannel(string connectionId)
|
||||
{
|
||||
CalculateInputRegion();
|
||||
}
|
||||
|
||||
// Parameters can be changed from the Unity Editor inspector when in Play Mode,
|
||||
// So this method monitors the parameters every frame and updates scene UI.
|
||||
private void Update()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
SyncDisplayVideoSenderParameters();
|
||||
#endif
|
||||
// Call SetInputChange if window size is changed.
|
||||
var width = Screen.width;
|
||||
var height = Screen.height;
|
||||
if (lastWidth == width && lastHeight == height)
|
||||
return;
|
||||
lastWidth = width;
|
||||
lastHeight = height;
|
||||
|
||||
CalculateInputRegion();
|
||||
}
|
||||
|
||||
private void CalculateInputRegion()
|
||||
{
|
||||
if (!inputReceiver.IsConnected)
|
||||
return;
|
||||
var width = (int)(videoStreamSender.width / videoStreamSender.scaleResolutionDown);
|
||||
var height = (int)(videoStreamSender.height / videoStreamSender.scaleResolutionDown);
|
||||
inputReceiver.CalculateInputRegion(new Vector2Int(width, height));
|
||||
inputReceiver.SetEnableInputPositionCorrection(true);
|
||||
}
|
||||
|
||||
private void SyncDisplayVideoSenderParameters()
|
||||
{
|
||||
if (videoStreamSender == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var bandwidthIndex = Array.IndexOf(bandwidthOptions.Values.ToArray(), videoStreamSender.maxBitrate);
|
||||
if (bandwidthIndex < 0)
|
||||
{
|
||||
bandwidthSelector.SetValueWithoutNotify(bandwidthSelector.options.Count - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
bandwidthSelector.SetValueWithoutNotify(bandwidthIndex);
|
||||
}
|
||||
|
||||
var scaleDownIndex = Array.IndexOf(scaleResolutionDownOptions.Values.ToArray(), videoStreamSender.scaleResolutionDown);
|
||||
if (scaleDownIndex < 0)
|
||||
{
|
||||
scaleResolutionDownSelector.SetValueWithoutNotify(bandwidthSelector.options.Count - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
scaleResolutionDownSelector.SetValueWithoutNotify(scaleDownIndex);
|
||||
}
|
||||
|
||||
var framerateIndex = Array.IndexOf(framerateOptions.Values.ToArray(), videoStreamSender.frameRate);
|
||||
if (framerateIndex < 0)
|
||||
{
|
||||
framerateSelector.SetValueWithoutNotify(framerateSelector.options.Count - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
framerateSelector.SetValueWithoutNotify(framerateIndex);
|
||||
}
|
||||
|
||||
var target = new Vector2Int((int)videoStreamSender.width, (int)videoStreamSender.height);
|
||||
var resolutionIndex = Array.IndexOf(resolutionOptions.Values.ToArray(), target);
|
||||
if (resolutionIndex < 0)
|
||||
{
|
||||
resolutionSelector.SetValueWithoutNotify(resolutionSelector.options.Count - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
resolutionSelector.SetValueWithoutNotify(resolutionIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d207eb28d60cb5941a6a8f93a10ec652
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,770 @@
|
||||
{
|
||||
"name": "CameraControl",
|
||||
"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": "",
|
||||
"initialStateCheck": true
|
||||
},
|
||||
{
|
||||
"name": "Look",
|
||||
"type": "Value",
|
||||
"id": "8ebbde1f-3044-41bc-bdac-430e0eae1a68",
|
||||
"expectedControlType": "Vector2",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": true
|
||||
},
|
||||
{
|
||||
"name": "ResetCamera",
|
||||
"type": "Button",
|
||||
"id": "7f36745c-6b3f-404f-9df5-42688580b961",
|
||||
"expectedControlType": "Button",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
},
|
||||
{
|
||||
"name": "Rotate",
|
||||
"type": "Value",
|
||||
"id": "524fee92-4ef1-4fd9-9cb1-97fb72ae1195",
|
||||
"expectedControlType": "Quaternion",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": true
|
||||
},
|
||||
{
|
||||
"name": "Position",
|
||||
"type": "Value",
|
||||
"id": "50305201-a606-4afe-954c-0666ccaf6c53",
|
||||
"expectedControlType": "Vector3",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": true
|
||||
},
|
||||
{
|
||||
"name": "Point",
|
||||
"type": "Value",
|
||||
"id": "60e72b30-ed9b-46db-80b9-f3660fa002ba",
|
||||
"expectedControlType": "Vector2",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": true
|
||||
},
|
||||
{
|
||||
"name": "Press",
|
||||
"type": "Button",
|
||||
"id": "245d7ad4-63bc-43e3-8d43-432ba35a43f0",
|
||||
"expectedControlType": "Button",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
},
|
||||
{
|
||||
"name": "PressAnyKey",
|
||||
"type": "Value",
|
||||
"id": "02ca192d-af9c-45fe-85c1-c9c38dd9cd48",
|
||||
"expectedControlType": "Key",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": true
|
||||
}
|
||||
],
|
||||
"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.1,y=0.1)",
|
||||
"groups": "Touchscreen",
|
||||
"action": "Movement",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "Delta With Button [Mouse]",
|
||||
"id": "5b4d4ebb-ae12-4d2b-9afd-775a415b6f22",
|
||||
"path": "DeltaWithButton",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Look",
|
||||
"isComposite": true,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "delta",
|
||||
"id": "86663e78-4aa9-4457-b52b-c329d0a127da",
|
||||
"path": "<Mouse>/delta",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "Keyboard And Mouse",
|
||||
"action": "Look",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "button",
|
||||
"id": "2e315c32-dc6c-405f-a97b-10a1de00cb80",
|
||||
"path": "<Mouse>/press",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "Keyboard And Mouse",
|
||||
"action": "Look",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"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.1,y=0.1)",
|
||||
"groups": "Touchscreen",
|
||||
"action": "Look",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "2D Vector",
|
||||
"id": "e1df4888-ab33-4662-9a26-1427bb69166d",
|
||||
"path": "2DVector(mode=2)",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Look",
|
||||
"isComposite": true,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "down",
|
||||
"id": "9e7a94a7-e078-4cb0-9129-d4201b3cc5af",
|
||||
"path": "<Gyroscope>/angularVelocity/y",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Look",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "left",
|
||||
"id": "1f55665d-2075-44a5-a2ee-7ce59d934d2c",
|
||||
"path": "<Gyroscope>/angularVelocity/x",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Look",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "afb2c858-f0b0-4573-9bd7-3530d86fc6c1",
|
||||
"path": "<Keyboard>/u",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "Keyboard And Mouse",
|
||||
"action": "ResetCamera",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "84140e5b-f829-4c16-b3c2-c07c437cba6b",
|
||||
"path": "<HandheldARInputDevice>/deviceRotation",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Rotate",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "2b77688f-4e80-407c-8334-8ea75bfb47e6",
|
||||
"path": "<HandheldARInputDevice>/devicePosition",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Position",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "ba5cd7db-5c11-4519-b30c-5f2b5bf291ab",
|
||||
"path": "<Mouse>/position",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "Keyboard And Mouse",
|
||||
"action": "Point",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "d9fcd8cb-28b5-4414-b98d-f48b3e6a0e79",
|
||||
"path": "<Touchscreen>/touch0/position",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "Touchscreen",
|
||||
"action": "Point",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "c15d3af8-9943-4dd5-af94-9aa5a5167c95",
|
||||
"path": "<Mouse>/leftButton",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "Keyboard And Mouse",
|
||||
"action": "Press",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "2d7822b8-e6e2-4aff-9e3e-733fcfa5dc6b",
|
||||
"path": "<Touchscreen>/touch*/Press",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "Touchscreen",
|
||||
"action": "Press",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "b38c6b49-abda-4492-8ceb-d54d14b65e2f",
|
||||
"path": "<Keyboard>/anyKey",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "PressAnyKey",
|
||||
"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": "",
|
||||
"initialStateCheck": false
|
||||
},
|
||||
{
|
||||
"name": "Left Click",
|
||||
"type": "PassThrough",
|
||||
"id": "96c8be88-a7bb-4861-b5e9-956b4208d043",
|
||||
"expectedControlType": "Button",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
},
|
||||
{
|
||||
"name": "Point",
|
||||
"type": "PassThrough",
|
||||
"id": "d54e5ff5-4f35-4d2f-a745-95d14aef8c43",
|
||||
"expectedControlType": "Vector2",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
},
|
||||
{
|
||||
"name": "Submit",
|
||||
"type": "PassThrough",
|
||||
"id": "5f571f6a-e9e7-4120-ae3c-79f846bdd202",
|
||||
"expectedControlType": "Button",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
},
|
||||
{
|
||||
"name": "Cancel",
|
||||
"type": "PassThrough",
|
||||
"id": "146e681c-77dd-4ff0-9ad5-f4351fea14cc",
|
||||
"expectedControlType": "Button",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
},
|
||||
{
|
||||
"name": "TogglePause",
|
||||
"type": "Button",
|
||||
"id": "e773b1f9-ce5b-4fa2-9c1f-d194202c43b7",
|
||||
"expectedControlType": "",
|
||||
"processors": "",
|
||||
"interactions": "Press",
|
||||
"initialStateCheck": false
|
||||
}
|
||||
],
|
||||
"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
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73fc86559d71147b18ea5f2623204ede
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3}
|
||||
generateWrapperCode: 0
|
||||
wrapperCodePath:
|
||||
wrapperClassName:
|
||||
wrapperCodeNamespace:
|
||||
@@ -0,0 +1,40 @@
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.InputSystem.LowLevel;
|
||||
|
||||
namespace Unity.RenderStreaming.Samples
|
||||
{
|
||||
using InputSystem = UnityEngine.InputSystem.InputSystem;
|
||||
|
||||
class CustomEventSystem : EventSystem
|
||||
{
|
||||
#if !INPUTSYSTEM_1_1_OR_NEWER
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
unsafe
|
||||
{
|
||||
InputSystem.onDeviceCommand += InputSystemOnDeviceCommand;
|
||||
}
|
||||
}
|
||||
|
||||
private static unsafe long? InputSystemOnDeviceCommand(InputDevice device, InputDeviceCommand* command)
|
||||
{
|
||||
if (command->type != QueryCanRunInBackground.Type)
|
||||
{
|
||||
// return null is skip this evaluation
|
||||
return null;
|
||||
}
|
||||
|
||||
((QueryCanRunInBackground*)command)->canRunInBackground = true;
|
||||
return InputDeviceCommand.GenericSuccess;
|
||||
}
|
||||
|
||||
protected override void OnApplicationFocus(bool hasFocus)
|
||||
{
|
||||
//Do not change focus flag on eventsystem
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e5e9d986523743f2b5dd640a79541d4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,47 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.InputSystem.Layouts;
|
||||
using UnityEngine.InputSystem.Utilities;
|
||||
using UnityEngine.Scripting;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace Unity.RenderStreaming.Samples
|
||||
{
|
||||
using InputSystem = UnityEngine.InputSystem.InputSystem;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[InitializeOnLoad]
|
||||
#endif
|
||||
[Preserve]
|
||||
[DisplayStringFormat("{button}+{delta}")]
|
||||
class DeltaWithButton : InputBindingComposite<Vector2>
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
static DeltaWithButton()
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
#endif
|
||||
|
||||
[RuntimeInitializeOnLoadMethod]
|
||||
static void Initialize()
|
||||
{
|
||||
InputSystem.RegisterBindingComposite<DeltaWithButton>();
|
||||
}
|
||||
|
||||
[InputControl(layout = "Button")] public int delta;
|
||||
[InputControl(layout = "Button")] public int button;
|
||||
|
||||
public override Vector2 ReadValue(ref InputBindingCompositeContext context)
|
||||
{
|
||||
return context.ReadValueAsButton(button) ? context.ReadValue<Vector2, Vector2MagnitudeComparer>(delta) : default;
|
||||
}
|
||||
|
||||
public override float EvaluateMagnitude(ref InputBindingCompositeContext context)
|
||||
{
|
||||
return ReadValue(ref context).magnitude;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d0a0edcb6a384bcbbb60b5f93133bbc0
|
||||
timeCreated: 1635751612
|
||||
@@ -0,0 +1,208 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.InputSystem.EnhancedTouch;
|
||||
|
||||
namespace Unity.RenderStreaming.Samples
|
||||
{
|
||||
class SimpleCameraControllerV2 : MonoBehaviour
|
||||
{
|
||||
class CameraState
|
||||
{
|
||||
public float yaw;
|
||||
public float pitch;
|
||||
public float roll;
|
||||
public float x;
|
||||
public float y;
|
||||
public float z;
|
||||
|
||||
public void SetFromTransform(Transform t)
|
||||
{
|
||||
pitch = t.eulerAngles.x;
|
||||
yaw = t.eulerAngles.y;
|
||||
roll = t.eulerAngles.z;
|
||||
x = t.position.x;
|
||||
y = t.position.y;
|
||||
z = t.position.z;
|
||||
}
|
||||
|
||||
public void Translate(Vector3 translation)
|
||||
{
|
||||
Vector3 rotatedTranslation = Quaternion.Euler(pitch, yaw, roll) * translation;
|
||||
|
||||
x += rotatedTranslation.x;
|
||||
y += rotatedTranslation.y;
|
||||
z += rotatedTranslation.z;
|
||||
}
|
||||
|
||||
public void LerpTowards(CameraState target, float positionLerpPct, float rotationLerpPct)
|
||||
{
|
||||
yaw = Mathf.Lerp(yaw, target.yaw, rotationLerpPct);
|
||||
pitch = Mathf.Lerp(pitch, target.pitch, rotationLerpPct);
|
||||
roll = Mathf.Lerp(roll, target.roll, rotationLerpPct);
|
||||
|
||||
x = Mathf.Lerp(x, target.x, positionLerpPct);
|
||||
y = Mathf.Lerp(y, target.y, positionLerpPct);
|
||||
z = Mathf.Lerp(z, target.z, positionLerpPct);
|
||||
}
|
||||
|
||||
public void UpdateTransform(Transform t)
|
||||
{
|
||||
t.eulerAngles = new Vector3(pitch, yaw, roll);
|
||||
t.position = new Vector3(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
[Header("Movement Settings"), Tooltip("Movement Sensitivity Factor."), Range(0.001f, 1f), SerializeField]
|
||||
private float movementSensitivityFactor = 0.1f;
|
||||
|
||||
[Tooltip("Exponential boost factor on translation, controllable by mouse wheel."), SerializeField]
|
||||
private float boost = 3.5f;
|
||||
|
||||
[Tooltip("Time it takes to interpolate camera position 99% of the way to the target."), Range(0.001f, 1f),
|
||||
SerializeField]
|
||||
private float positionLerpTime = 0.2f;
|
||||
|
||||
[Header("Rotation Settings"),
|
||||
Tooltip("X = Change in mouse position.\nY = Multiplicative factor for camera rotation."), SerializeField]
|
||||
private AnimationCurve mouseSensitivityCurve =
|
||||
new AnimationCurve(new Keyframe(0f, 0.5f, 0f, 5f), new Keyframe(1f, 2.5f, 0f, 0f));
|
||||
|
||||
[Tooltip("Time it takes to interpolate camera rotation 99% of the way to the target."), Range(0.001f, 1f),
|
||||
SerializeField]
|
||||
private float rotationLerpTime = 0.01f;
|
||||
|
||||
[Tooltip("Whether or not to invert our Y axis for mouse input to rotation."), SerializeField]
|
||||
private bool invertY;
|
||||
|
||||
[SerializeField] InputReceiver playerInput;
|
||||
|
||||
private readonly CameraState m_TargetCameraState = new CameraState();
|
||||
private readonly CameraState m_InterpolatingCameraState = new CameraState();
|
||||
private readonly CameraState m_InitialCameraState = new CameraState();
|
||||
|
||||
Vector2 inputMovement;
|
||||
Vector2 inputLook;
|
||||
|
||||
Vector3? inputPosition;
|
||||
Quaternion? inputRotation;
|
||||
|
||||
protected void Awake()
|
||||
{
|
||||
playerInput.onDeviceChange += OnDeviceChange;
|
||||
m_InitialCameraState.SetFromTransform(transform);
|
||||
|
||||
// Need to set enable the flag to receive touch screen event from mobile devices.
|
||||
EnhancedTouchSupport.Enable();
|
||||
}
|
||||
|
||||
void OnDeviceChange(InputDevice device, InputDeviceChange change)
|
||||
{
|
||||
switch (change)
|
||||
{
|
||||
case InputDeviceChange.Added:
|
||||
{
|
||||
playerInput.PerformPairingWithDevice(device);
|
||||
return;
|
||||
}
|
||||
case InputDeviceChange.Removed:
|
||||
{
|
||||
playerInput.UnpairDevices(device);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
m_TargetCameraState.SetFromTransform(transform);
|
||||
m_InterpolatingCameraState.SetFromTransform(transform);
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
// Tracked Device
|
||||
if (inputPosition.HasValue && inputRotation.HasValue)
|
||||
{
|
||||
transform.position = inputPosition.Value;
|
||||
transform.rotation = inputRotation.Value;
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateTargetCameraStateDirection(inputMovement);
|
||||
UpdateTargetCameraStateFromInput(inputLook);
|
||||
|
||||
// Framerate-independent interpolation
|
||||
// Calculate the lerp amount, such that we get 99% of the way to our target in the specified time
|
||||
var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime);
|
||||
var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime);
|
||||
m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, positionLerpPct, rotationLerpPct);
|
||||
m_InterpolatingCameraState.UpdateTransform(transform);
|
||||
}
|
||||
|
||||
|
||||
private void UpdateTargetCameraStateDirection(Vector2 input)
|
||||
{
|
||||
if (!invertY)
|
||||
{
|
||||
input.y *= -1;
|
||||
}
|
||||
|
||||
var translation = Vector3.right * input.x * movementSensitivityFactor;
|
||||
translation += Vector3.back * input.y * movementSensitivityFactor;
|
||||
translation *= Mathf.Pow(2.0f, boost);
|
||||
m_TargetCameraState.Translate(translation);
|
||||
}
|
||||
|
||||
private void UpdateTargetCameraStateFromInput(Vector2 input)
|
||||
{
|
||||
if (!invertY)
|
||||
{
|
||||
input.y *= -1;
|
||||
}
|
||||
|
||||
float mouseSensitivityFactor = mouseSensitivityCurve.Evaluate(input.magnitude);
|
||||
|
||||
m_TargetCameraState.yaw += input.x * mouseSensitivityFactor;
|
||||
m_TargetCameraState.pitch += input.y * mouseSensitivityFactor;
|
||||
}
|
||||
|
||||
public void OnControlsChanged()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnDeviceLost()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnDeviceRegained()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnMovement(InputAction.CallbackContext context)
|
||||
{
|
||||
inputMovement = context.ReadValue<Vector2>();
|
||||
}
|
||||
|
||||
public void OnLook(InputAction.CallbackContext context)
|
||||
{
|
||||
inputLook = context.ReadValue<Vector2>();
|
||||
}
|
||||
|
||||
public void OnResetCamera(InputAction.CallbackContext context)
|
||||
{
|
||||
m_InitialCameraState.UpdateTransform(transform);
|
||||
m_TargetCameraState.SetFromTransform(transform);
|
||||
m_InterpolatingCameraState.SetFromTransform(transform);
|
||||
}
|
||||
|
||||
public void OnPosition(InputAction.CallbackContext context)
|
||||
{
|
||||
inputPosition = context.ReadValue<Vector3>();
|
||||
}
|
||||
|
||||
public void OnRotate(InputAction.CallbackContext context)
|
||||
{
|
||||
inputRotation = context.ReadValue<Quaternion>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 03310012c553840bc870f3fef5e88cd6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,79 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Unity.RenderStreaming.Samples
|
||||
{
|
||||
[RequireComponent(typeof(RectTransform))]
|
||||
class UIControllerV2 : MonoBehaviour
|
||||
{
|
||||
[SerializeField] Text text;
|
||||
[SerializeField] CanvasGroup canvasGroup;
|
||||
[SerializeField] Image pointer;
|
||||
[SerializeField] GameObject noticeTouchControl;
|
||||
[SerializeField]
|
||||
private AnimationCurve transitionCurve =
|
||||
new AnimationCurve(
|
||||
new Keyframe(0.75f, 1f, 0f, 0f),
|
||||
new Keyframe(1f, 0f, 0f, 0f));
|
||||
|
||||
private float timeTransition = 0f;
|
||||
private RectTransform m_rectTransform = null;
|
||||
private bool isSubscribing = false;
|
||||
|
||||
|
||||
public void SetDevice(InputDevice device, bool add = false)
|
||||
{
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
m_rectTransform = GetComponent<RectTransform>();
|
||||
canvasGroup.alpha = 0;
|
||||
text.text = string.Empty;
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (!Mathf.Approximately(canvasGroup.alpha, 0f))
|
||||
{
|
||||
timeTransition += Time.deltaTime;
|
||||
canvasGroup.alpha = transitionCurve.Evaluate(timeTransition);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPressAnyKey(InputAction.CallbackContext context)
|
||||
{
|
||||
var keyboard = context.control.device as Keyboard;
|
||||
|
||||
if (!isSubscribing)
|
||||
{
|
||||
keyboard.onTextInput += OnTextInput;
|
||||
isSubscribing = true;
|
||||
}
|
||||
}
|
||||
|
||||
void OnTextInput(char c)
|
||||
{
|
||||
canvasGroup.alpha = 1f;
|
||||
text.text = c.ToString();
|
||||
timeTransition = 0;
|
||||
}
|
||||
|
||||
public void OnPoint(InputAction.CallbackContext context)
|
||||
{
|
||||
if (m_rectTransform == null)
|
||||
return;
|
||||
var position = context.ReadValue<Vector2>();
|
||||
var screenSize = new Vector2Int(Screen.width, Screen.height);
|
||||
position = position / screenSize * new Vector2(m_rectTransform.rect.width, m_rectTransform.rect.height);
|
||||
pointer.rectTransform.anchoredPosition = position;
|
||||
}
|
||||
|
||||
public void OnPress(InputAction.CallbackContext context)
|
||||
{
|
||||
var button = context.ReadValueAsButton();
|
||||
pointer.color = button ? Color.red : Color.clear;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0cf609b6c80ea492288c74dd8f26ae97
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user