18 using System.Collections.Generic;
35 [Tooltip(
"Show/Hide the Board Gizmo in the Editor.")]
38 [Tooltip(
"Show/Hide the Unit Grid on the Board Gizmo in the Editor.")]
48 [Tooltip(
"Sets the Alpha transparency of the Board Gizmo in the Editor.")]
56 [Obsolete(
"Please use Gameboard.TryGetGameboardType() instead.")]
59 #endregion Public Fields
62 #region Private Fields
69 private TableTopGizmo boardGizmo =
new TableTopGizmo();
84 private float currentContentScaleRatio;
89 private Vector3 currentScale;
91 private const float MIN_SCALE = 0.00001f;
95 private static Dictionary<PlayerIndex, GameboardType>
playerGameboards =
new Dictionary<PlayerIndex, GameboardType>();
97 #endregion Private Fields
143 #endregion Public Enums
146 #region Public Structs
148 [Obsolete(
"GameboardDimensions is obsolete, please use GameboardExtents instead.")]
218 internal const float BORDER_WIDTH_IN_METERS = 0.05f;
226 GAMEBOARD_SIZE_XE =
new T5_GameboardSize(0.35f, 0.35f, 0.61667f, 0.35f, 0.0f);
227 GAMEBOARD_SIZE_XE_RAISED =
new T5_GameboardSize(0.35f, 0.35f, 0.55944f, 0.35f, 0.20944f);
262 throw new System.ArgumentException(
"Cannot get corner positions for invalid Corner enum values.");
287 throw new System.ArgumentException(
"Cannot get edge center positions for invalid Edge enum values.");
306 #endregion Private Structs
309 #region Public Functions
326 if(!
Player.TryGetGlassesHandle(playerIndex, out var glassesHandle)
327 || !
playerGameboards.TryGetValue(playerIndex, out var currentGameboardType))
333 gameboardType = currentGameboardType;
343 [Obsolete(
"TryGetGameboardDimensions is obsolete. Please use TryGetGameboardExtents instead.")]
358 result =
NativePlugin.GetGameboardDimensions(gameboardType, ref gameboardSize);
390 result =
NativePlugin.GetGameboardDimensions(gameboardType, ref gameboardSize);
415 out Vector3 positionInWorldSpace, out Quaternion rotationToWorldSpace)
419 positionInWorldSpace = Vector3.zero;
420 rotationToWorldSpace = Quaternion.identity;
424 TransformPose(positionInGameboardSpace, rotationToGameboardSpace, playerSettings.scaleSettings,
425 out positionInWorldSpace, out rotationToWorldSpace);
443 poseInWorldSpace =
new Pose();
447 poseInWorldSpace =
TransformPose(poseInGameboardSpace, playerSettings.scaleSettings);
465 pointInWorldSpace = Vector3.zero;
469 pointInWorldSpace =
TransformPoint(pointInGameboardSpace, playerSettings.scaleSettings);
486 out Vector3 positionInGameboardSpace, out Quaternion rotationToGameboardSpace)
490 positionInGameboardSpace = Vector3.zero;
491 rotationToGameboardSpace = Quaternion.identity;
496 out positionInGameboardSpace, out rotationToGameboardSpace);
514 poseInGameboardSpace =
new Pose();
536 pointInGameboardSpace = Vector3.zero;
546 new public void Awake()
549 currentScale = transform.localScale;
555 public void DrawGizmo(ScaleSettings scaleSettings, GameBoardSettings gameBoardSettings)
564 var sceneViewRepaintNecessary = ScaleCompensate(scaleSettings);
565 sceneViewRepaintNecessary |= ContentScaleCompensate(scaleSettings);
567 if(sceneViewRepaintNecessary)
569 boardGizmo.ResetGrid(scaleSettings, gameBoardSettings);
570 UnityEditor.SceneView.lastActiveSceneView.Repaint();
579 public GameboardType GetDisplayedGameboardType(GameBoardSettings gameBoardSettings)
581 return GetDisplayedGameboardType(
PlayerIndex.One, gameBoardSettings);
591 var displayedGameboardType =
playerGameboards.TryGetValue(playerIndex, out var gameboardType)
595 displayedGameboardType = gameBoardSettings.gameboardTypeOverride !=
GameboardType.GameboardType_None
596 ? gameBoardSettings.gameboardTypeOverride
597 : displayedGameboardType;
599 return displayedGameboardType;
604 #endregion Public Functions
607 #region Internal Functions
619 internal static void SetGameboardType(GlassesHandle glassesHandle,
GameboardType gameboardType)
621 if (Player.TryGetPlayerIndex(glassesHandle, out var playerIndex))
623 SetGameboardType(playerIndex, gameboardType);
634 internal Pose
TransformPose(Pose poseInGameboardSpace, ScaleSettings scaleSettings)
636 TransformPose(poseInGameboardSpace.position, poseInGameboardSpace.rotation, scaleSettings,
637 out var posUWRLD, out var rotToUWRLD_OBJ);
638 return new Pose(posUWRLD, rotToUWRLD_OBJ);
650 internal void TransformPose(Vector3 positionInGameboardSpace, Quaternion rotationToGameboardSpace, ScaleSettings scaleSettings,
651 out Vector3 positionInWorldSpace, out Quaternion rotationToWorldSpace)
653 positionInWorldSpace =
TransformPoint(positionInGameboardSpace, scaleSettings);
656 var rotToUWRLD_UGBD = transform.rotation;
659 var rotToUGBD_OBJ = rotationToGameboardSpace;
662 var rotToUWRLD_OBJ = rotToUWRLD_UGBD * rotToUGBD_OBJ;
664 rotationToWorldSpace = rotToUWRLD_OBJ;
674 internal Vector3
TransformPoint(Vector3 pointInGameboardSpace, ScaleSettings scaleSettings)
676 var pos_UGBD = pointInGameboardSpace;
678 var scaleToUWRLD_UGBD = scaleSettings.GetScaleToUWRLD_UGBD(
localScale);
679 var rotToUWRLD_UGBD = transform.rotation;
680 var pos_UWRLD = rotToUWRLD_UGBD * (scaleToUWRLD_UGBD * pos_UGBD) + transform.position;
695 out var posUGBD, out var rotToUGBD_OBJ);
696 return new Pose(posUGBD, rotToUGBD_OBJ);
708 internal void InverseTransformPose(Vector3 positionInWorldSpace, Quaternion rotationToWorldSpace, ScaleSettings scaleSettings,
709 out Vector3 positionInGameboardSpace, out Quaternion rotationToGameboardSpace)
714 var rotToUWRLD_UGBD = transform.rotation;
717 var rotToUGBD_UWRLD = Quaternion.Inverse(rotToUWRLD_UGBD);
720 var rotToUWRLD_OBJ = rotationToWorldSpace;
723 var rotToUGBD_OBJ = rotToUGBD_UWRLD * rotToUWRLD_OBJ;
725 rotationToGameboardSpace = rotToUGBD_OBJ;
737 var pos_UWRLD = pointInWorldSpace;
739 var scaleToUGBD_UWRLD = 1f / scaleSettings.GetScaleToUWRLD_UGBD(
localScale);
740 var rotToUGBD_UWRLD = Quaternion.Inverse(transform.rotation);
741 var pos_UGBD = pos_UWRLD - transform.position;
742 pos_UGBD = rotToUGBD_UWRLD * pos_UGBD;
743 pos_UGBD *= scaleToUGBD_UWRLD;
751 #region Private Functions
761 private bool ScaleCompensate(ScaleSettings scaleSettings)
763 if(currentScale == transform.localScale) {
return false; }
766 if( transform.localScale.x < MIN_SCALE)
768 transform.localScale = Vector3.one * MIN_SCALE;
775 currentScale = transform.localScale;
782 private bool ContentScaleCompensate(ScaleSettings scaleSettings)
784 if(currentContentScaleRatio == scaleSettings.contentScaleRatio
785 && currentContentScaleUnit == scaleSettings.contentScaleUnit) {
return false; }
789 currentContentScaleUnit = scaleSettings.contentScaleUnit;
790 currentContentScaleRatio = scaleSettings.contentScaleRatio;
800 #endregion Private Functions
Represents the game board.
bool TransformPoint(Vector3 pointInGameboardSpace, PlayerIndex playerIndex, out Vector3 pointInWorldSpace)
Transforms the provided position from gameboard space to world space.
static bool TryGetGameboardExtents(GameboardType gameboardType, out GameboardExtents gameboardExtents)
Attempts to obtain the physical dimensions for a particular gameboard type.
static bool TryGetGameboardDimensions(GameboardType gameboardType, out GameboardDimensions gameboardDimensions)
Attempts to obtain the physical dimensions for a particular gameboard type.
Edge
Represents cardinal positions around the gameboard (i.e. the centers of the edges of the gameboard),...
bool ShowGizmo
Shows the game board gizmo in the editor.
static Dictionary< PlayerIndex, GameboardType > playerGameboards
static bool TryGetGameboardType(out GameboardType gameboardType)
Attempts to check the latest glasses pose for the current gameboard type, such as LE,...
bool InverseTransformPoint(Vector3 pointInWorldSpace, PlayerIndex playerIndex, out Vector3 pointInGameboardSpace)
Transforms the provided position from world space to gameboard space.
bool InverseTransformPose(Pose poseInWorldSpace, PlayerIndex playerIndex, out Pose poseInGameboardSpace)
Transforms the provided pose from world space to gameboard space.
static bool TryGetGameboardType(PlayerIndex playerIndex, out GameboardType gameboardType)
float GizmoOpacity
Sets the opacity of the game board gizmo in the editor.
bool TransformPose(Pose poseInGameboardSpace, PlayerIndex playerIndex, out Pose poseInWorldSpace)
Transforms the provided pose from gameboard space to world space.
Corner
Represents ordinal positions around the gameboard, relative to a user positioned at the near (default...
bool TransformPose(Vector3 positionInGameboardSpace, Quaternion rotationToGameboardSpace, PlayerIndex playerIndex, out Vector3 positionInWorldSpace, out Quaternion rotationToWorldSpace)
Transforms the provided pose from gameboard space to world space.
bool InverseTransformPose(Vector3 positionInWorldSpace, Quaternion rotationToWorldSpace, PlayerIndex playerIndex, out Vector3 positionInGameboardSpace, out Quaternion rotationToGameboardSpace)
Transforms the provided pose from world space to gameboard space.
GameboardType GameboardType
The gameboard configuration, such as LE, XE, or folded XE.
static void Error(string m, params object[] list)
ERROR logging function call.
Provides access to player settings and functionality.
static bool TryGetSettings(PlayerIndex playerIndex, out PlayerSettings playerSettings)
Obtains the PlayerSettings corresponding to the specified player.
@ Right
The wand held in the player's right hand.
@ Left
The wand held in the player's left hand.
GameboardType
The type of Gameboard being tracked by the glasses
PlayerIndex
The Player index (e.g. Player One, Player Two, etc)
GameboardDimensions(T5_GameboardSize gameboardSize)
Represents the distances from the gameboard tracking origin to the borders of the gameboard's viewabl...
Length ViewableSpanX
The distance in meters representing the side-to-side width of the viewable area of the gameboard;
Length ViewableExtentNegativeZ
The distance in meters from the gameboard origin to the edge of the viewable area in the negative Z d...
Vector3 GetCornerPositionInGameboardSpace(Corner corner)
Gets the coordinates of the specified corner in gameboard space.
Length ViewableExtentPositiveZ
The distance in meters from the gameboard origin to the edge of the viewable area in the positive Z d...
Length ViewableExtentPositiveY
The distance in meters above the gameboard origin that the viewable area extends in the positive Y di...
Length ViewableExtentNegativeX
The distance in meters from the gameboard origin to the edge of the viewable area in the negative X d...
Length ViewableSpanZ
The distance in meters representing the height of the viewable area of the gameboard;
GameboardExtents(T5_GameboardSize gameboardSize)
Vector3 GetEdgeCenterPositionInGameboardSpace(Edge edge)
Gets the coordinates of the center of the specified edge in gameboard space.
Length ViewableSpanY
The distance in meters representing the front-to-back length of the viewable area of the gameboard;
Length OriginOffsetZ
The distance from the tracking origin to the physical center of the gameboard.
Length ViewableExtentPositiveX
The distance in meters from the gameboard origin to the edge of the viewable area in the positive X d...
static GameboardExtents()
Vector3 GetPhysicalCenterPositionInGameboardSpace()
Gets the coordinates of the center of the gameboard in gameboard space.
float ToMeters
The Length, converted to meters.
Physical dimensions of a gameboard, in meters.
float ViewableExtentNegativeX
The distance in meters from the gameboard origin to the edge of the viewable area in the negative X d...
float ViewableExtentPositiveY
The distance in meters above the gameboard origin that the viewable area extends in the positive Y di...
float ViewableExtentPositiveX
The distance in meters from the gameboard origin to the edge of the viewable area in the positive X d...
float ViewableExtentPositiveZ
The distance in meters from the gameboard origin to the edge of the viewable area in the positive Z d...
float ViewableExtentNegativeZ
The distance in meters from the gameboard origin to the edge of the viewable area in the negative Z d...