#define DEBUG_LOCOMOTION_PANEL using System.Diagnostics; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; public class LocomotionSampleSupport : MonoBehaviour { private LocomotionController lc; private bool inMenu; private LocomotionTeleport TeleportController { get { return lc.GetComponent(); } } public void Start() { lc = Object.FindObjectOfType(); DebugUIBuilder.instance.AddButton("Node Teleport w/ A", SetupNodeTeleport); DebugUIBuilder.instance.AddButton("Dual-stick teleport", SetupTwoStickTeleport); DebugUIBuilder.instance.AddButton("L Strafe R Teleport", SetupLeftStrafeRightTeleport); DebugUIBuilder.instance.AddButton("Walk Only", SetupWalkOnly); EventSystem eventSystem = Object.FindObjectOfType(); if (eventSystem == null) { UnityEngine.Debug.LogError("Need EventSystem"); } SetupTwoStickTeleport(); Physics.IgnoreLayerCollision(0, 4); } public void Update() { if (OVRInput.GetDown(OVRInput.Button.Two) || OVRInput.GetDown(OVRInput.Button.Start)) { if (inMenu) { DebugUIBuilder.instance.Hide(); } else { DebugUIBuilder.instance.Show(); } inMenu = !inMenu; } } [Conditional("DEBUG_LOCOMOTION_PANEL")] private static void Log(string msg) { UnityEngine.Debug.Log(msg); } public static TActivate ActivateCategory(GameObject target) where TCategory : MonoBehaviour where TActivate : MonoBehaviour { TCategory[] components = target.GetComponents(); Log(string.Concat("Activate ", typeof(TActivate), " derived from ", typeof(TCategory), "[", components.Length, "]")); TActivate result = (TActivate)null; foreach (MonoBehaviour monoBehaviour in components) { bool flag = monoBehaviour.GetType() == typeof(TActivate); Log(string.Concat(monoBehaviour.GetType(), " is ", typeof(TActivate), " = ", flag)); if (flag) { result = (TActivate)monoBehaviour; } if (monoBehaviour.enabled != flag) { monoBehaviour.enabled = flag; } } return result; } protected void ActivateHandlers() where TInput : TeleportInputHandler where TAim : TeleportAimHandler where TTarget : TeleportTargetHandler where TOrientation : TeleportOrientationHandler where TTransition : TeleportTransition { ActivateInput(); ActivateAim(); ActivateTarget(); ActivateOrientation(); ActivateTransition(); } protected void ActivateInput() where TActivate : TeleportInputHandler { ActivateCategory(); } protected void ActivateAim() where TActivate : TeleportAimHandler { ActivateCategory(); } protected void ActivateTarget() where TActivate : TeleportTargetHandler { ActivateCategory(); } protected void ActivateOrientation() where TActivate : TeleportOrientationHandler { ActivateCategory(); } protected void ActivateTransition() where TActivate : TeleportTransition { ActivateCategory(); } protected TActivate ActivateCategory() where TCategory : MonoBehaviour where TActivate : MonoBehaviour { return ActivateCategory(lc.gameObject); } protected void UpdateToggle(Toggle toggle, bool enabled) { if (enabled != toggle.isOn) { toggle.isOn = enabled; } } private void SetupNonCap() { TeleportInputHandlerAvatarTouch component = TeleportController.GetComponent(); component.InputMode = TeleportInputHandlerAvatarTouch.InputModes.SeparateButtonsForAimAndTeleport; component.AimButton = OVRInput.RawButton.A; component.TeleportButton = OVRInput.RawButton.A; } private void SetupTeleportDefaults() { TeleportController.enabled = true; lc.PlayerController.SnapRotation = true; lc.PlayerController.RotationEitherThumbstick = false; lc.PlayerController.FixedSpeedSteps = 0; TeleportController.EnableMovement(false, false, false, false); TeleportController.EnableRotation(false, false, false, false); TeleportInputHandlerAvatarTouch component = TeleportController.GetComponent(); component.InputMode = TeleportInputHandlerAvatarTouch.InputModes.CapacitiveButtonForAimAndTeleport; component.AimButton = OVRInput.RawButton.A; component.TeleportButton = OVRInput.RawButton.A; component.CapacitiveAimAndTeleportButton = TeleportInputHandlerAvatarTouch.AimCapTouchButtons.A; component.FastTeleport = false; TeleportInputHandlerHMD component2 = TeleportController.GetComponent(); component2.AimButton = OVRInput.RawButton.A; component2.TeleportButton = OVRInput.RawButton.A; TeleportOrientationHandlerThumbstick component3 = TeleportController.GetComponent(); component3.Thumbstick = OVRInput.Controller.LTouch; } protected GameObject AddInstance(GameObject template, string label) { GameObject gameObject = Object.Instantiate(template); gameObject.transform.SetParent(base.transform, false); gameObject.name = label; return gameObject; } private void SetupNodeTeleport() { SetupTeleportDefaults(); SetupNonCap(); lc.PlayerController.SnapRotation = true; lc.PlayerController.FixedSpeedSteps = 1; lc.PlayerController.RotationEitherThumbstick = true; TeleportController.EnableRotation(true, false, false, true); ActivateHandlers(); TeleportInputHandlerAvatarTouch component = TeleportController.GetComponent(); component.AimingController = OVRInput.Controller.RTouch; } private void SetupTwoStickTeleport() { SetupTeleportDefaults(); TeleportController.EnableRotation(true, false, false, true); TeleportController.EnableMovement(false, false, false, false); lc.PlayerController.SnapRotation = true; lc.PlayerController.RotationEitherThumbstick = true; lc.PlayerController.FixedSpeedSteps = 1; TeleportInputHandlerAvatarTouch component = TeleportController.GetComponent(); component.InputMode = TeleportInputHandlerAvatarTouch.InputModes.ThumbstickTeleportForwardBackOnly; component.AimingController = OVRInput.Controller.Touch; ActivateHandlers(); TeleportOrientationHandlerThumbstick component2 = TeleportController.GetComponent(); component2.Thumbstick = OVRInput.Controller.Touch; } private void SetupWalkOnly() { SetupTeleportDefaults(); TeleportController.enabled = false; lc.PlayerController.EnableLinearMovement = true; lc.PlayerController.SnapRotation = true; lc.PlayerController.RotationEitherThumbstick = false; lc.PlayerController.FixedSpeedSteps = 1; } private void SetupLeftStrafeRightTeleport() { SetupTeleportDefaults(); TeleportController.EnableRotation(true, false, false, true); TeleportController.EnableMovement(true, false, false, false); lc.PlayerController.SnapRotation = true; lc.PlayerController.FixedSpeedSteps = 1; TeleportInputHandlerAvatarTouch component = TeleportController.GetComponent(); component.InputMode = TeleportInputHandlerAvatarTouch.InputModes.ThumbstickTeleportForwardBackOnly; component.AimingController = OVRInput.Controller.RTouch; ActivateHandlers(); TeleportOrientationHandlerThumbstick component2 = TeleportController.GetComponent(); component2.Thumbstick = OVRInput.Controller.RTouch; } }