218 lines
8.0 KiB
C#
218 lines
8.0 KiB
C#
#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<LocomotionTeleport>();
|
|
}
|
|
}
|
|
|
|
public void Start()
|
|
{
|
|
lc = Object.FindObjectOfType<LocomotionController>();
|
|
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<EventSystem>();
|
|
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<TCategory, TActivate>(GameObject target) where TCategory : MonoBehaviour where TActivate : MonoBehaviour
|
|
{
|
|
TCategory[] components = target.GetComponents<TCategory>();
|
|
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<TInput, TAim, TTarget, TOrientation, TTransition>() where TInput : TeleportInputHandler where TAim : TeleportAimHandler where TTarget : TeleportTargetHandler where TOrientation : TeleportOrientationHandler where TTransition : TeleportTransition
|
|
{
|
|
ActivateInput<TInput>();
|
|
ActivateAim<TAim>();
|
|
ActivateTarget<TTarget>();
|
|
ActivateOrientation<TOrientation>();
|
|
ActivateTransition<TTransition>();
|
|
}
|
|
|
|
protected void ActivateInput<TActivate>() where TActivate : TeleportInputHandler
|
|
{
|
|
ActivateCategory<TeleportInputHandler, TActivate>();
|
|
}
|
|
|
|
protected void ActivateAim<TActivate>() where TActivate : TeleportAimHandler
|
|
{
|
|
ActivateCategory<TeleportAimHandler, TActivate>();
|
|
}
|
|
|
|
protected void ActivateTarget<TActivate>() where TActivate : TeleportTargetHandler
|
|
{
|
|
ActivateCategory<TeleportTargetHandler, TActivate>();
|
|
}
|
|
|
|
protected void ActivateOrientation<TActivate>() where TActivate : TeleportOrientationHandler
|
|
{
|
|
ActivateCategory<TeleportOrientationHandler, TActivate>();
|
|
}
|
|
|
|
protected void ActivateTransition<TActivate>() where TActivate : TeleportTransition
|
|
{
|
|
ActivateCategory<TeleportTransition, TActivate>();
|
|
}
|
|
|
|
protected TActivate ActivateCategory<TCategory, TActivate>() where TCategory : MonoBehaviour where TActivate : MonoBehaviour
|
|
{
|
|
return ActivateCategory<TCategory, TActivate>(lc.gameObject);
|
|
}
|
|
|
|
protected void UpdateToggle(Toggle toggle, bool enabled)
|
|
{
|
|
if (enabled != toggle.isOn)
|
|
{
|
|
toggle.isOn = enabled;
|
|
}
|
|
}
|
|
|
|
private void SetupNonCap()
|
|
{
|
|
TeleportInputHandlerAvatarTouch component = TeleportController.GetComponent<TeleportInputHandlerAvatarTouch>();
|
|
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<TeleportInputHandlerAvatarTouch>();
|
|
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<TeleportInputHandlerHMD>();
|
|
component2.AimButton = OVRInput.RawButton.A;
|
|
component2.TeleportButton = OVRInput.RawButton.A;
|
|
TeleportOrientationHandlerThumbstick component3 = TeleportController.GetComponent<TeleportOrientationHandlerThumbstick>();
|
|
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, TeleportAimHandlerLaser, TeleportTargetHandlerNode, TeleportOrientationHandlerThumbstick, TeleportTransitionBlink>();
|
|
TeleportInputHandlerAvatarTouch component = TeleportController.GetComponent<TeleportInputHandlerAvatarTouch>();
|
|
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<TeleportInputHandlerAvatarTouch>();
|
|
component.InputMode = TeleportInputHandlerAvatarTouch.InputModes.ThumbstickTeleportForwardBackOnly;
|
|
component.AimingController = OVRInput.Controller.Touch;
|
|
ActivateHandlers<TeleportInputHandlerAvatarTouch, TeleportAimHandlerParabolic, TeleportTargetHandlerPhysical, TeleportOrientationHandlerThumbstick, TeleportTransitionBlink>();
|
|
TeleportOrientationHandlerThumbstick component2 = TeleportController.GetComponent<TeleportOrientationHandlerThumbstick>();
|
|
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<TeleportInputHandlerAvatarTouch>();
|
|
component.InputMode = TeleportInputHandlerAvatarTouch.InputModes.ThumbstickTeleportForwardBackOnly;
|
|
component.AimingController = OVRInput.Controller.RTouch;
|
|
ActivateHandlers<TeleportInputHandlerAvatarTouch, TeleportAimHandlerParabolic, TeleportTargetHandlerPhysical, TeleportOrientationHandlerThumbstick, TeleportTransitionBlink>();
|
|
TeleportOrientationHandlerThumbstick component2 = TeleportController.GetComponent<TeleportOrientationHandlerThumbstick>();
|
|
component2.Thumbstick = OVRInput.Controller.RTouch;
|
|
}
|
|
}
|