Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates ClientSim source to match Worlds SDK 3.6.0 #116

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,17 @@ private static ClientSimInputAxesSettings ReadProjectInputAxes()
public static bool IsUsingCorrectInputTypeSettings()
{
SerializedObject serializedObject = new SerializedObject(AssetDatabase.LoadAssetAtPath<Object>("ProjectSettings/ProjectSettings.asset"));
SerializedProperty newInputEnabledProp = serializedObject.FindProperty("enableNativePlatformBackendsForNewInputSystem");
SerializedProperty oldInputDisabledProp = serializedObject.FindProperty("disableOldInputManagerSupport");
SerializedProperty activeInputHandler = serializedObject.FindProperty("activeInputHandler");

return
newInputEnabledProp.boolValue
&& !oldInputDisabledProp.boolValue;
return activeInputHandler.intValue != 1;
}

public static void SetInputTypeSettings()
{
SerializedObject serializedObject = new SerializedObject(AssetDatabase.LoadAssetAtPath<Object>("ProjectSettings/ProjectSettings.asset"));
SerializedProperty newInputEnabledProp = serializedObject.FindProperty("enableNativePlatformBackendsForNewInputSystem");
SerializedProperty oldInputDisabledProp = serializedObject.FindProperty("disableOldInputManagerSupport");
SerializedProperty activeInputHandler = serializedObject.FindProperty("activeInputHandler");

newInputEnabledProp.boolValue = true;
oldInputDisabledProp.boolValue = false;
activeInputHandler.intValue = 1;

serializedObject.ApplyModifiedProperties();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ClientSimSettingsWindow : EditorWindow
private readonly GUIContent _showDesktopReticleGuiContent = new GUIContent("Show Desktop Reticle", "Show or hide the center Desktop reticle image.");
private readonly GUIContent _showTooltipsGuiContent = new GUIContent("Show Tooltips", "If enabled, hovering over an interactable object or pickup will display a tooltip above the object.");
private readonly GUIContent _invertMouseLookGuiContent = new GUIContent("Invert Mouse Look", "If enabled, moving the mouse up or down will invert the direction the player will look up and down.");
private readonly GUIContent _playerHeightGuiContent = new GUIContent("Player Height", "How tall should the player be in meters. Default height is 1.9. Note that the player's collision capsule is 1.6 and never changes.");
private readonly GUIContent _playerHeightGuiContent = new GUIContent("Initial Player Height", "How tall should the player be in meters at app start. Default height is 1.9. Note that the player's collision capsule is 1.6 and never changes.");
private readonly GUIContent _currentLanguageGuiContent = new GUIContent("Current Language", "The language the player is currently using. Available languages include English, French, German, Italian, Japanese, Korean, and Spanish.");
private int selectedLanguageIndex;

Expand All @@ -44,6 +44,7 @@ public class ClientSimSettingsWindow : EditorWindow

private static Texture2D _warningIcon;
private static ClientSimSettings _settings;
private static IClientSimPlayerHeightManager _heightManager;

private Vector2 _scrollPosition;
private GUIStyle _boxStyle;
Expand Down Expand Up @@ -79,7 +80,7 @@ private void OnEnable()
// Reuse VRChat's warning icon.
_warningIcon = Resources.Load<Texture2D>("2FAIcons/SDK_Warning_Triangle_icon");
}

_version = ClientSimResourceLoader.GetVersion();
}

Expand Down Expand Up @@ -382,10 +383,9 @@ private void DrawPlayerControllerSettings()
_settings.showDesktopReticle = EditorGUILayout.Toggle(_showDesktopReticleGuiContent, _settings.showDesktopReticle);
_settings.showTooltips = EditorGUILayout.Toggle(_showTooltipsGuiContent, _settings.showTooltips);
_settings.invertMouseLook = EditorGUILayout.Toggle(_invertMouseLookGuiContent, _settings.invertMouseLook);
_settings.playerHeight = EditorGUILayout.FloatField(_playerHeightGuiContent, _settings.playerHeight);
_settings.playerHeight = Mathf.Clamp(_settings.playerHeight, 0.2f, 80f); // TODO make consts for these.
selectedLanguageIndex = EditorGUILayout.Popup(_currentLanguageGuiContent, selectedLanguageIndex, _settings.availableLanguages);
_settings.currentLanguage = _settings.availableLanguages[selectedLanguageIndex];
_settings.playerStartHeight = EditorGUILayout.FloatField(_playerHeightGuiContent, _settings.playerStartHeight);
selectedLanguageIndex = EditorGUILayout.Popup(_currentLanguageGuiContent, selectedLanguageIndex, _settings.GetAvailableDisplayLanguages());
_settings.currentLanguage = _settings.GetLanguage(selectedLanguageIndex);

EditorGUI.EndDisabledGroup();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ private void DestroyCameraStack()

private void AddCamera(int index)
{
GameObject cameraObj = Instantiate(new GameObject(), _mainSceneCamera.transform);
var cameraObj = new GameObject();
cameraObj.transform.parent = _mainSceneCamera.transform;
Camera cam = cameraObj.AddComponent<Camera>();
XRDevice.DisableAutoXRCameraTracking(cam, true);

Expand Down
36 changes: 31 additions & 5 deletions Packages/com.vrchat.ClientSim/Runtime/ClientSimRuntimeLoader.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Collections.Generic;
using System.Collections.Generic;
using JetBrains.Annotations;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
using VRC.Core;

namespace VRC.SDK3.ClientSim
{
Expand All @@ -22,6 +24,13 @@ private static void OnBeforeSceneLoad()
StartClientSim(GetSettings(), GetEventDispatcher());
}

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
private static void OnAfterSceneLoad()
{
// Delete all editor only objects before creating ClientSim.
DestroyEditorOnly(GetSettings());
}

#endregion

#region Test Methods
Expand Down Expand Up @@ -70,7 +79,6 @@ private static bool IsClientSimEnabled(ClientSimSettings settings)
{
return
settings.enableClientSim &&
Object.FindObjectOfType<PipelineSaver>() == null &&
Application.isPlaying;
}

Expand All @@ -87,14 +95,32 @@ public static void StartClientSim(

// Delete all editor only objects before creating ClientSim.
DestroyEditorOnly(settings);

// Create ClientSim Instance

ClientSimMain.CreateInstance(settings, eventDispatcher);

// TODO: Below is disabled for now because the rest of the ClientSim initialization code doesn't work if it's called with a delay.
// Currently, not loading RemoteConfig will not cause any issues, but it may in the future, so this is left in as a reminder.

// Create ClientSim Instance later
/*void CreateClientSimInstance() => ClientSimMain.CreateInstance(settings, eventDispatcher);

// If the Remote Config is not initialized, attempt init before starting ClientSim
// Start ClientSim after attempt, regardless of success or failure
if (!ConfigManager.RemoteConfig.IsInitialized())
{
API.SetOnlineMode(true);
ConfigManager.RemoteConfig.Init(CreateClientSimInstance, CreateClientSimInstance);
}
// Otherwise, start ClientSim immediately
else
{
CreateClientSimInstance();
}*/
}

private static void DestroyEditorOnly(ClientSimSettings settings)
{
if (!settings.deleteEditorOnly)
if (!settings.enableClientSim || !settings.deleteEditorOnly)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class ClientSimOnPlayerExitedStationEvent : IClientSimEvent
public class ClientSimOnPlayerHeightUpdateEvent : IClientSimEvent
{
public float playerHeight;
public bool exceedsManualScalingMaximum;
public bool exceedsManualScalingMinimum;
}

public class ClientSimOnTrackingScaleUpdateEvent : IClientSimEvent
Expand All @@ -54,4 +56,9 @@ public class ClientSimOnNewMasterEvent : IClientSimEvent
public VRCPlayerApi oldMasterPlayer;
public VRCPlayerApi newMasterPlayer;
}

public class ClientSimOnToggleManualScalingEvent : IClientSimEvent
{
public bool manualScalingAllowed;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using VRC.SDK3.Platform;

namespace VRC.SDK3.ClientSim
{
public class ClientSimScreenUpdateEvent : IClientSimEvent
{
public ScreenUpdateData data;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace VRC.SDK3.ClientSim
{
public class IClientSimPlatformHelper
{

}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class ClientSimSpatialAudioHelper : ONSPAudioSource
private bool _useAudioSourceCurve;
private ONSPAudioSource _onsp;
private bool _forceUpdate = true;
private bool _updateONSPParams;

public static void InitializeAudio(VRC_SpatialAudioSource obj)
{
Expand Down Expand Up @@ -62,6 +63,7 @@ private void OnEnable()
{
// ONSP needs to reapply audio settings everytime the object is enabled.
_forceUpdate = true;
_updateONSPParams = true;
}

// Late update to help with testing
Expand Down Expand Up @@ -92,6 +94,7 @@ private void UpdateSettings()
_useAudioSourceCurve != _spatialAudioSource.UseAudioSourceVolumeCurve
) {
_forceUpdate = true;
_updateONSPParams = true;
}

_onsp.EnableSpatialization = _spatialAudioSource.EnableSpatialization;
Expand All @@ -100,8 +103,14 @@ private void UpdateSettings()
_onsp.Near = _spatialAudioSource.Near;
_onsp.Far = _spatialAudioSource.Far;
_onsp.VolumetricRadius = _spatialAudioSource.VolumetricRadius;

_onsp.SetParameters(ref _audioSource);

// In unity 2022 - updating ONSP params every frame can cause a logspam
// This is a workaround to only update when needed
if (_updateONSPParams)
{
_onsp.SetParameters(ref _audioSource);
_updateONSPParams = false;
}

if (!_onsp.EnableSpatialization)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using VRC.SDK3.Platform;

namespace VRC.SDK3.ClientSim
{
public interface IClientSimPlatformManager
{
void OnScreenUpdate(ScreenUpdateData data);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

#if ENABLE_INPUT_SYSTEM
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.InputSystem;
using VRC.SDKBase;
#endif

using VRC.Udon.Common;
Expand Down Expand Up @@ -54,8 +57,12 @@ when the Input System has not yet been imported or enabled.*/

#endregion

private InputActionAsset InputActions;

public ClientSimInputActionBased(InputActionAsset actionAsset, ClientSimSettings settings)
{
InputActions = actionAsset;

_settings = settings;

_lookHorizontal = actionAsset["LookHorizontal"];
Expand Down Expand Up @@ -119,6 +126,62 @@ public ClientSimInputActionBased(InputActionAsset actionAsset, ClientSimSettings
_toggleProne.canceled += HandleToggleProne;
_releaseMouse.performed += HandleReleaseMouse;
_releaseMouse.canceled += HandleReleaseMouse;

foreach (InputAction action in actionAsset)
{
action.performed += SetInputDevice;
}
}

private VRCInputMethod _lastInputMethod = VRCInputMethod.Count;

public VRCInputMethod LastInputMethod
{
get => _lastInputMethod;
set
{
// Only send events for changes
if(_lastInputMethod == value) return;

_lastInputMethod = value;
SendInputMethodChangedEvent(_lastInputMethod);
}
}

private const string MOUSE_LOOK_PATTERN = @"Player/Look.*Mouse/delta";
bool isTouchActive = false;
private void SetInputDevice(InputAction.CallbackContext ctx)
{
if(Regex.IsMatch(ctx.action.ToString(), MOUSE_LOOK_PATTERN)) return; // This is to avoid changing the tooltip icon when looking with a mouse
isTouchActive = (ctx.control.device.description.empty || Touchscreen.current != null && ctx.control.device.GetType().Equals(Touchscreen.current.GetType())); // On screen controls
if (!isTouchActive)
{
if (Keyboard.current != null && ctx.control.device.GetType().Equals(Keyboard.current.GetType()))
{
#if VRC_MOBILE && UNITY_ANDROID
//This prevents the android back button from switching to keyboard and disabling touch UI
if (ctx.control.device.description.interfaceName == "Android")
return;
#endif
LastInputMethod = VRCInputMethod.Keyboard;
return;
}
if (Mouse.current != null && ctx.control.device.GetType().Equals(Mouse.current.GetType()))
{
LastInputMethod = VRCInputMethod.Mouse;
return;
}

if (Gamepad.current != null && ctx.control.device.GetType().Equals(Gamepad.current.GetType()))
{
LastInputMethod = VRCInputMethod.Controller;
return;
}
}
else
{
LastInputMethod = VRCInputMethod.Touch;
}
}

public override void Dispose()
Expand Down
19 changes: 19 additions & 0 deletions Packages/com.vrchat.ClientSim/Runtime/Input/ClientSimInputBase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon.Common;

namespace VRC.SDK3.ClientSim
Expand All @@ -20,6 +21,8 @@ public abstract class ClientSimInputBase : IClientSimInput, IDisposable
private Action<bool> _toggleCrouchEvent;
private Action<bool> _toggleProneEvent;
private Action<bool> _releaseMouseEvent;

private Action<VRCInputMethod> _inputMethodChangedEvent;

public virtual void Dispose()
{
Expand All @@ -29,6 +32,7 @@ public virtual void Dispose()
_grabEvent = null;
_dropEvent = null;
_toggleMenuEvent = null;
_inputMethodChangedEvent = null;

_runEvent = null;
_toggleCrouchEvent = null;
Expand Down Expand Up @@ -135,6 +139,16 @@ public void UnsubscribeReleaseMouse(Action<bool> handler)
{
_releaseMouseEvent -= handler;
}

public void SubscribeInputChangedEvent(Action<VRCInputMethod> handler)
{
_inputMethodChangedEvent += handler;
}

public void UnsubscribeInputChangedEvent(Action<VRCInputMethod> handler)
{
_inputMethodChangedEvent -= handler;
}

#endregion

Expand Down Expand Up @@ -219,5 +233,10 @@ public void SendReleaseMouseEvent(bool value)
{
_releaseMouseEvent?.Invoke(value);
}

public void SendInputMethodChangedEvent(VRCInputMethod value)
{
_inputMethodChangedEvent?.Invoke(value);
}
}
}
Loading
Loading