16 using System.Collections.Generic;
19 #if UNITY_2019_1_OR_NEWER && INPUTSYSTEM_AVAILABLE
20 using UnityEngine.InputSystem;
21 using UnityEngine.InputSystem.Users;
33 [DisallowMultipleComponent]
34 #if !UNITY_2019_1_OR_NEWER || !INPUTSYSTEM_AVAILABLE
37 [DefaultExecutionOrder(-500)]
43 [DefaultExecutionOrder(500)]
130 public EditorSettings2 editorSettings =
new EditorSettings2();
131 public PlayerIndex selectedPlayer => editorSettings.selectedPlayer;
133 private HashSet<GameBoard> renderedGameboards =
new HashSet<GameBoard>();
141 #if UNITY_2019_1_OR_NEWER && INPUTSYSTEM_AVAILABLE
147 private int[] playerIndexMapping = {0,1,2,3};
167 Log.
Warn(
"Failed to set application context.");
173 Log.
Warn(
"Failed to send application info to the T5 Service.");
181 if(currentPlayerSettings ==
null)
189 #if UNITY_2019_1_OR_NEWER && INPUTSYSTEM_AVAILABLE
193 private void OnBeforeUpdate()
196 if (UnityEditor.EditorApplication.isPaused)
201 if (
Player.scanningForPlayers)
207 Player.ScanForNewPlayers();
208 Wand.GetLatestInputs();
213 if (UnityEngine.InputSystem.LowLevel.InputState.currentUpdateType != UnityEngine.InputSystem.LowLevel.InputUpdateType.BeforeRender)
225 #if !UNITY_2019_1_OR_NEWER || !INPUTSYSTEM_AVAILABLE
227 Player.ScanForNewPlayers();
228 Wand.GetLatestInputs();
236 if (playerSettings !=
null)
246 spectatedPlayerPose.position,
247 spectatedPlayerPose.rotation);
250 #if UNITY_2019_1_OR_NEWER && INPUTSYSTEM_AVAILABLE
251 var devices = InputUser.GetUnpairedInputDevices();
252 if (devices.Count > 0)
254 foreach (InputDevice dev
in devices)
256 if (dev is WandDevice)
260 if (headPoseRoot !=
null)
262 var playerInput = headPoseRoot.GetComponentInChildren<PlayerInput>();
264 if (playerInput !=
null && playerInput.user.valid)
266 Log.
Warn($
"Unpaired Wand Device [{((WandDevice)dev).ControllerIndex}] found and paired to Player [{((WandDevice)dev).playerIndex}].");
267 InputUser.PerformPairingWithDevice(dev, playerInput.user);
268 playerInput.user.ActivateControlScheme(
"XR");
290 if (playerSettings !=
null)
321 Log.
Warn(
"Incompatible Tilt Five service. Please update driver package.");
332 catch (System.DllNotFoundException e)
335 "Could not connect to Tilt Five plugin for compatibility check: {0}",
339 catch (System.Exception e)
374 playerSettings =
null;
379 #if UNITY_2019_1_OR_NEWER && INPUTSYSTEM_AVAILABLE
380 internal void RefreshInputDevicePairings()
382 foreach (WandDevice wand
in Input.wandDevices)
384 PlayerInput playerInput =
null;
387 playerInput = PlayerInput.GetPlayerByIndex(playerIndexMapping[(
int)wand.playerIndex - 1]);
388 if (playerInput !=
null)
390 InputUser.PerformPairingWithDevice(wand, playerInput.user);
394 foreach (GlassesDevice glasses
in Input.glassesDevices)
396 PlayerInput playerInput =
null;
399 playerInput = PlayerInput.GetPlayerByIndex(playerIndexMapping[(
int)glasses.PlayerIndex - 1]);
400 if (playerInput !=
null)
402 InputUser.PerformPairingWithDevice(glasses, playerInput.user);
408 internal void ReassignPlayerIndexMapping(
int[] mapping)
410 if(mapping.Length != 4)
412 throw new System.ArgumentException(
"Invalid player index mapping argument - mapping should be 4 values long");
414 for (var i = 0; i < mapping.Length; i++)
418 throw new System.ArgumentException(
"Invalid player index mapping argument - mapping should contain positive values only");
420 for (var j = 0; j < i; j++)
422 if (mapping[i] == mapping[j])
424 throw new System.ArgumentException(
"Invalid player index mapping argument - mapping should contain no duplicates");
428 playerIndexMapping = mapping;
429 RefreshInputDevicePairings();
445 catch (System.DllNotFoundException e)
448 "Could not connect to Tilt Five plugin for setting max glasses: {0}",
451 catch (System.Exception e)
460 if (currentPlayerSettings ==
null)
469 if (playerSettings !=
null)
475 #if UNITY_2019_1_OR_NEWER && INPUTSYSTEM_AVAILABLE
476 InputSystem.onBeforeUpdate += OnBeforeUpdate;
482 #if UNITY_2019_1_OR_NEWER && INPUTSYSTEM_AVAILABLE
483 InputSystem.onBeforeUpdate -= OnBeforeUpdate;
510 catch (System.DllNotFoundException)
514 catch (System.Exception e)
520 [RuntimeInitializeOnLoadMethod]
523 Application.quitting +=
Quit;
532 Log.
Warn(
"No spectator camera detected in TiltFiveManager2's spectator settings. A spectator camera is required.");
539 Log.
Warn($
"Invalid spectatorSettings.spectatedPlayer [{spectatorSettings.spectatedPlayer}]. TiltFiveManager2 currently only supports up to Player {highestSupportedPlayer}.");
570 if (playerSettings !=
null)
572 Player.Validate(playerSettings);
589 renderedGameboards.Clear();
594 if (playerSettings !=
null)
597 if (!renderedGameboards.Contains(currentGameboard))
599 renderedGameboards.Add(currentGameboard);
600 Player.DrawGizmos(playerSettings);
606 public static void CreateFromTiltFiveManager(
TiltFiveManager tiltFiveManager)
608 var parentGameObject = tiltFiveManager.gameObject;
614 var isTiltFiveManager2AlreadyPresent = parentGameObject.TryGetComponent<
TiltFiveManager2>(out var existingTiltFiveManager2);
615 var confirmationDialogTitle =
"Existing TiltFiveManager2 detected";
616 var confirmationDialogText = $
"The GameObject \"{parentGameObject.name}\" already has a TiltFiveManager2 component." +
617 System.Environment.NewLine + System.Environment.NewLine +
618 "Overwrite the existing TiltFiveManager2 component values?" +
619 System.Environment.NewLine + System.Environment.NewLine +
620 "Warning: This cannot be undone via Edit > Undo (Ctrl+Z)";
621 var confirmButtonLabel =
"Overwrite";
622 var cancelButtonLabel =
"Cancel";
623 var overwriteExistingTiltFiveManager2 = isTiltFiveManager2AlreadyPresent
624 && UnityEditor.EditorUtility.DisplayDialog(confirmationDialogTitle, confirmationDialogText, confirmButtonLabel, cancelButtonLabel);
626 if(isTiltFiveManager2AlreadyPresent && !overwriteExistingTiltFiveManager2)
628 Debug.Log($
"Aborted attempt to upgrade TiltFiveManager.");
635 ? existingTiltFiveManager2
639 tiltFiveManager.enabled =
false;
665 var resultText = overwriteExistingTiltFiveManager2
666 ? $
"Successfully overwrote component values on the existing TiltFiveManager2 component attached to \"{parentGameObject.name}\" using the old TiltFiveManager component values."
667 : $
"Successfully attached a new TiltFiveManager2 component to \"{parentGameObject.name}\" and imported the old TiltFiveManager component values.";
668 Debug.Log($
"{resultText}{System.Environment.NewLine}The old TiltFiveManager has been disabled - it can safely be removed.");
673 #region ISceneInfo Implementation
697 return isActiveAndEnabled;
700 #endregion ISceneInfo Implementation
Vector3 gameBoardRotation
The game board rotation or focal rotational offset.
Vector3 gameBoardCenter
The game board position or focal position offset.
GameBoard currentGameBoard
The game board is the window into the game world, as well as the origin about which the glasses/wand ...
float gameBoardScale
The game board's scale multiplies the perceived size of objects in the scene.
The Glasses API and runtime.
static Camera GetLeftEye(PlayerIndex playerIndex)
Gets the left eye camera for the specified player's glasses.
static bool TryGetPreviewPose(PlayerIndex playerIndex, out Pose pose)
Attempts to get the position and orientation of the specified player's glasses, smoothed for on-scree...
static GameObject GetPoseRoot(PlayerIndex playerIndex)
Gets the pose root GameObject for the specified player.
GlassesSettings encapsulates all configuration data used by the Glasses' tracking runtime to compute ...
Camera cameraTemplate
The camera used as a template for creating the eye cameras at runtime.
GlassesMirrorMode glassesMirrorMode
GraphicsSettings encapsulates configuration data related to the project's graphics settings,...
static void Warn(string m, params object[] list)
WARN logging function call.
static void Info(string m, params object[] list)
INFO logging function call.
static void Error(string m, params object[] list)
ERROR logging function call.
static int LogLevel
Gets or sets the logging level.
static string TAG
Gets or sets the logging tag.
Provides access to player settings and functionality.
ScaleSettings scaleSettings
GameBoardSettings gameboardSettings
static uint MAX_SUPPORTED_PLAYERS
WandSettings leftWandSettings
GlassesSettings glassesSettings
WandSettings rightWandSettings
float GetScaleToUWRLD_UGBD(float gameboardScale)
PlayerIndex spectatedPlayer
The player that will have their perspective mirrored on screen.
GlassesMirrorMode glassesMirrorMode
The spectator camera will display content on screen depending on the mirroring mode....
Camera spectatorCamera
The camera used for rendering the onscreen preview
LogSettings logSettings
The log settings.
PlayerSettings[] allPlayerSettings
bool NeedsDriverUpdate()
Check if a driver update is needed.
bool IsActiveAndEnabled()
SpectatorSettings spectatorSettings
The spectator camera's runtime configuration data.
void OnEnable()
Called when the GameObject is enabled.
override void Awake()
Awake this instance.
void Update()
Update this instance.
GraphicsSettings graphicsSettings
Project-wide graphics settings related to Tilt Five.
PlayerSettings playerFourSettings
The fourth player's runtime configuration data.
PlayerSettings playerOneSettings
The first player's runtime configuration data.
uint GetSupportedPlayerCount()
void RefreshSpectatorSettings()
uint supportedPlayerCount
bool TryGetPlayerSettings(PlayerIndex playerIndex, out PlayerSettings playerSettings)
Gets the player settings for the specified player.
float GetScaleToUWRLD_UGBD()
void LateUpdate()
Update this instance after all components have finished executing their Update() functions.
static bool upgradeInProgress
bool needsDriverUpdateNotifiedOnce
PlayerSettings playerTwoSettings
The second player's runtime configuration data.
bool needsDriverUpdateErroredOnce
PlayerSettings playerThreeSettings
The third player's runtime configuration data.
LogSettings logSettings
The log settings.
GameBoardSettings gameBoardSettings
The game board runtime configuration data.
WandSettings rightWandSettings
The wand runtime configuration data for the right hand wand.
ScaleSettings scaleSettings
The scale conversion runtime configuration data.
GlassesSettings glassesSettings
The glasses runtime configuration data.
WandSettings leftWandSettings
The wand runtime configuration data for the left hand wand.
The Wand API and runtime.
ServiceCompatibility
Whether the running service is compatible.
PlayerIndex
The Player index (e.g. Player One, Player Two, etc)