16using System.Collections.Generic;
19#if UNITY_2019_1_OR_NEWER && INPUTSYSTEM_AVAILABLE
20using UnityEngine.InputSystem;
32 [DisallowMultipleComponent]
33#if !UNITY_2019_1_OR_NEWER || !INPUTSYSTEM_AVAILABLE
36 [DefaultExecutionOrder(-500)]
42 [DefaultExecutionOrder(500)]
124 public EditorSettings2 editorSettings =
new EditorSettings2();
125 public PlayerIndex selectedPlayer => editorSettings.selectedPlayer;
127 private HashSet<GameBoard> renderedGameboards =
new HashSet<GameBoard>();
148 Log.
Warn(
"Failed to send application info to the T5 Control Panel.");
156 if(currentPlayerSettings ==
null)
164#if UNITY_2019_1_OR_NEWER && INPUTSYSTEM_AVAILABLE
168 private void OnBeforeUpdate()
171 if (UnityEditor.EditorApplication.isPaused)
176 if (
Player.scanningForPlayers)
182 Player.ScanForNewPlayers();
183 Wand.GetLatestInputs();
188 if (UnityEngine.InputSystem.LowLevel.InputState.currentUpdateType != UnityEngine.InputSystem.LowLevel.InputUpdateType.BeforeRender)
200#if !UNITY_2019_1_OR_NEWER || !INPUTSYSTEM_AVAILABLE
202 Player.ScanForNewPlayers();
203 Wand.GetLatestInputs();
210 if (playerSettings !=
null)
220 spectatedPlayerPose.position,
221 spectatedPlayerPose.rotation);
238 if (playerSettings !=
null)
269 Log.
Warn(
"Incompatible Tilt Five service. Please update driver package.");
280 catch (System.DllNotFoundException e)
283 "Could not connect to Tilt Five plugin for compatibility check: {0}",
287 catch (System.Exception e)
309 catch (System.DllNotFoundException e)
312 "Could not connect to Tilt Five plugin for setting max glasses: {0}",
315 catch (System.Exception e)
324 if (currentPlayerSettings ==
null)
335 if (playerSettings !=
null)
341#if UNITY_2019_1_OR_NEWER && INPUTSYSTEM_AVAILABLE
342 InputSystem.onBeforeUpdate += OnBeforeUpdate;
348#if UNITY_2019_1_OR_NEWER && INPUTSYSTEM_AVAILABLE
349 InputSystem.onBeforeUpdate -= OnBeforeUpdate;
376 catch (System.DllNotFoundException)
380 catch (System.Exception e)
386 [RuntimeInitializeOnLoadMethod]
389 Application.quitting +=
Quit;
398 Log.
Warn(
"No spectator camera detected in TiltFiveManager2's spectator settings. A spectator camera is required.");
405 Log.
Warn($
"Invalid spectatorSettings.spectatedPlayer [{spectatorSettings.spectatedPlayer}]. TiltFiveManager2 currently only supports up to Player {highestSupportedPlayer}.");
406 spectatorSettings.spectatedPlayer = highestSupportedPlayer;
428 playerThreeSettings.PlayerIndex =
PlayerIndex.Three;
432 if (Application.isEditor && !Application.isPlaying)
439 if (playerSettings !=
null)
441 Player.Validate(playerSettings);
458 renderedGameboards.Clear();
463 if (playerSettings !=
null)
466 if (!renderedGameboards.Contains(currentGameboard))
468 renderedGameboards.Add(currentGameboard);
469 Player.DrawGizmos(playerSettings);
475 public static void CreateFromTiltFiveManager(
TiltFiveManager tiltFiveManager)
477 var parentGameObject = tiltFiveManager.gameObject;
483 var isTiltFiveManager2AlreadyPresent = parentGameObject.TryGetComponent<
TiltFiveManager2>(out var existingTiltFiveManager2);
484 var confirmationDialogTitle =
"Existing TiltFiveManager2 detected";
485 var confirmationDialogText = $
"The GameObject \"{parentGameObject.name}\" already has a TiltFiveManager2 component." +
486 System.Environment.NewLine + System.Environment.NewLine +
487 "Overwrite the existing TiltFiveManager2 component values?" +
488 System.Environment.NewLine + System.Environment.NewLine +
489 "Warning: This cannot be undone via Edit > Undo (Ctrl+Z)";
490 var confirmButtonLabel =
"Overwrite";
491 var cancelButtonLabel =
"Cancel";
492 var overwriteExistingTiltFiveManager2 = isTiltFiveManager2AlreadyPresent
493 && UnityEditor.EditorUtility.DisplayDialog(confirmationDialogTitle, confirmationDialogText, confirmButtonLabel, cancelButtonLabel);
495 if(isTiltFiveManager2AlreadyPresent && !overwriteExistingTiltFiveManager2)
497 Debug.Log($
"Aborted attempt to upgrade TiltFiveManager.");
504 ? existingTiltFiveManager2
508 tiltFiveManager.enabled =
false;
511 tiltFiveManager2.supportedPlayerCount = 1;
514 tiltFiveManager2.playerOneSettings.glassesSettings = tiltFiveManager.
glassesSettings.Copy();
516 tiltFiveManager2.playerOneSettings.scaleSettings = tiltFiveManager.
scaleSettings.Copy();
518 tiltFiveManager2.playerOneSettings.gameboardSettings = tiltFiveManager.
gameBoardSettings.Copy();
520 tiltFiveManager2.playerOneSettings.leftWandSettings = tiltFiveManager.
leftWandSettings.Copy();
521 tiltFiveManager2.playerOneSettings.rightWandSettings = tiltFiveManager.
rightWandSettings.Copy();
530 tiltFiveManager2.logSettings = tiltFiveManager.
logSettings.Copy();
534 var resultText = overwriteExistingTiltFiveManager2
535 ? $
"Successfully overwrote component values on the existing TiltFiveManager2 component attached to \"{parentGameObject.name}\" using the old TiltFiveManager component values."
536 : $
"Successfully attached a new TiltFiveManager2 component to \"{parentGameObject.name}\" and imported the old TiltFiveManager component values.";
537 Debug.Log($
"{resultText}{System.Environment.NewLine}The old TiltFiveManager has been disabled - it can safely be removed.");
542 #region ISceneInfo Implementation
566 return isActiveAndEnabled;
569 #endregion ISceneInfo Implementation
static bool SetApplicationInfo()
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)
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...
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
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 void UnloadWorkaround()
static ServiceCompatibility GetServiceCompatibility()
static void SetMaxDesiredGlasses(byte maxCount)
Provides access to player settings and functionality.
ScaleSettings scaleSettings
GameBoardSettings gameboardSettings
static uint MAX_SUPPORTED_PLAYERS
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.
PlayerSettings playerFourSettings
The fourth player's runtime configuration data.
PlayerSettings playerOneSettings
The first player's runtime configuration data.
uint GetSupportedPlayerCount()
void RefreshSpectatorSettings()
uint supportedPlayerCount
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)