-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Group UI ports into a unified system, fix inventory and add pause men…
…u and in-game UI
- Loading branch information
Showing
6 changed files
with
239 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using HarmonyLib; | ||
using Landfall.Network; | ||
using TABGVR.Util; | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
|
||
namespace TABGVR.Patches.UI; | ||
|
||
[HarmonyPatch(typeof(InventoryUI), nameof(InventoryUI.Start))] | ||
public static class InventoryUIPatch | ||
{ | ||
/// <summary> | ||
/// Patches the inventory to make it visible in world space. | ||
/// </summary> | ||
public static bool Prefix(InventoryUI __instance) | ||
{ | ||
__instance.transform.SetParent( | ||
global::Player.localPlayer.m_cameraMovement.transform.Find("CameraRotationX")); | ||
|
||
__instance.transform.localPosition = Vector3.forward; | ||
__instance.transform.localRotation = Quaternion.identity; | ||
|
||
// *inventory* | ||
|
||
// shebang it | ||
UIPorter.Shebang(__instance.transform.Find("Inventory").gameObject); | ||
|
||
// fix header being weird af | ||
__instance.characterRT.transform.parent.Find("Header").GetComponent<RectTransform>().localPosition = | ||
new Vector3(0, 620, 0); | ||
|
||
// *game ui* | ||
__instance.gameUI.Start(); | ||
var gameUI = __instance.transform.Find("GameUI").gameObject; | ||
gameUI.AddComponent<RectMask2D>(); // hide stuff that's normally offscreen | ||
UIPorter.Shebang(gameUI); | ||
|
||
return true; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using UnityEngine.XR.Interaction.Toolkit; | ||
|
||
namespace TABGVR.Player; | ||
|
||
public class Floor : MonoBehaviour | ||
{ | ||
public void Update() | ||
{ | ||
transform.position = Camera.current.transform.position - Controllers.Head.transform.position; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
using System; | ||
using System.Linq; | ||
using JetBrains.Annotations; | ||
using TABGVR.Player; | ||
using UnityEngine; | ||
using UnityEngine.EventSystems; | ||
using UnityEngine.SceneManagement; | ||
using UnityEngine.XR; | ||
using UnityEngine.XR.Interaction.Toolkit; | ||
using UnityEngine.XR.Interaction.Toolkit.UI; | ||
|
||
namespace TABGVR.Util; | ||
|
||
internal static class UIPorter | ||
{ | ||
private static bool _eventSystemSetUp; | ||
|
||
internal static GameObject UILeftHand; | ||
internal static GameObject UIRightHand; | ||
|
||
[CanBeNull] private static XRInteractorLineVisual _uiLeftHandVisual; | ||
[CanBeNull] private static XRInteractorLineVisual _uiRightHandVisual; | ||
|
||
internal static bool InteractorVisuals | ||
{ | ||
get | ||
{ | ||
if (_uiLeftHandVisual is null || _uiRightHandVisual is null) return false; | ||
|
||
return _uiLeftHandVisual.enabled; | ||
} | ||
|
||
set | ||
{ | ||
if (_uiLeftHandVisual is null || _uiRightHandVisual is null) return; | ||
|
||
_uiLeftHandVisual.enabled = value; | ||
_uiRightHandVisual.enabled = value; | ||
} | ||
} | ||
|
||
internal static void SetupInteractors(XRNode node) | ||
{ | ||
if (UILeftHand && node == XRNode.LeftHand) return; | ||
if (UIRightHand && node == XRNode.RightHand) return; | ||
|
||
GameObject interactionController; | ||
|
||
switch (node) | ||
{ | ||
case XRNode.LeftHand: | ||
UILeftHand ??= new GameObject("TABGVR_UILeftHand"); | ||
interactionController = UILeftHand; | ||
break; | ||
case XRNode.RightHand: | ||
UIRightHand ??= new GameObject("TABGVR_UIRightHand"); | ||
interactionController = UIRightHand; | ||
break; | ||
default: | ||
throw new ArgumentOutOfRangeException(nameof(node), node, null); | ||
} | ||
|
||
var controller = interactionController.AddComponent<XRController>(); | ||
var interactor = interactionController.AddComponent<XRRayInteractor>(); | ||
var lineVisual = interactionController.AddComponent<XRInteractorLineVisual>(); | ||
var lineRenderer = interactionController.GetComponent<LineRenderer>(); | ||
|
||
switch (node) | ||
{ | ||
case XRNode.LeftHand: | ||
_uiLeftHandVisual = lineVisual; | ||
break; | ||
case XRNode.RightHand: | ||
_uiRightHandVisual = lineVisual; | ||
break; | ||
} | ||
|
||
interactor.rayOriginTransform.localEulerAngles = node switch | ||
{ | ||
XRNode.LeftHand => new Vector3(60, 347, 90), | ||
XRNode.RightHand => new Vector3(60, 347, 270), | ||
_ => throw new ArgumentOutOfRangeException(nameof(node), node, null) | ||
}; | ||
|
||
lineVisual.lineBendRatio = 1; | ||
lineVisual.invalidColorGradient = new Gradient() | ||
{ | ||
mode = GradientMode.Blend, | ||
alphaKeys = | ||
new[] { new GradientAlphaKey(0.1f, 0), new GradientAlphaKey(0.1f, 1) }, | ||
colorKeys = | ||
new[] | ||
{ | ||
new GradientColorKey(Color.white, 0), | ||
new GradientColorKey(Color.white, 1) | ||
} | ||
}; | ||
|
||
lineRenderer.material = new Material(Shader.Find("Sprites/Default")); | ||
|
||
controller.controllerNode = node; | ||
|
||
interactionController.transform.SetParent(Controllers.VRFloor.transform, false); | ||
// InteractorMover.Interactors.Add(interactor); | ||
} | ||
|
||
internal static void SetupEventSystem() | ||
{ | ||
if (_eventSystemSetUp) return; | ||
|
||
var eventSystem = SceneManager.GetActiveScene().GetRootGameObjects().First((o => o.name == "MapObjects")) | ||
.transform.Find("EventSystem").gameObject; | ||
|
||
eventSystem.AddComponent<XRUIInputModule>(); | ||
eventSystem.GetComponent<StandaloneInputModule>().enabled = false; | ||
|
||
_eventSystemSetUp = true; | ||
} | ||
|
||
internal static void SetupCanvas(GameObject canvas) | ||
{ | ||
var canvasComponent = canvas.GetComponent<Canvas>(); | ||
canvasComponent.renderMode = RenderMode.WorldSpace; | ||
canvasComponent.worldCamera = Camera.main; | ||
|
||
var rectTransform = canvas.GetComponent<RectTransform>(); | ||
rectTransform.localPosition = Vector3.zero; | ||
rectTransform.localRotation = Quaternion.identity; | ||
rectTransform.localScale = Vector3.one * 0.0008f; // i don't know why this specific number works, but it does ¯\_(ツ)_/¯ | ||
|
||
canvas.AddComponent<TrackedDeviceGraphicRaycaster>(); | ||
} | ||
|
||
internal static void Shebang(GameObject canvas) | ||
{ | ||
SetupEventSystem(); | ||
SetupInteractors(XRNode.LeftHand); | ||
SetupInteractors(XRNode.RightHand); | ||
SetupCanvas(canvas); | ||
} | ||
} |