Added Unity project files

This commit is contained in:
2026-06-07 16:58:24 +01:00
parent 3cc05d260b
commit 23bbcab156
3942 changed files with 453676 additions and 0 deletions

View File

@ -0,0 +1,169 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.Serialization;
namespace VRC.SDK3.ClientSim
{
public class ClientSimInputAxesSettings : ScriptableObject, IEquatable<ClientSimInputAxesSettings>
{
// Name copying Unity's Input settings
public List<ClientSimInputAxis> m_Axes = new List<ClientSimInputAxis>();
public void LoadFromSerializedObject(SerializedObject serializedObject)
{
m_Axes.Clear();
SerializedProperty axesProp = serializedObject.FindProperty(nameof(m_Axes));
for (int curAxis = 0; curAxis < axesProp.arraySize; ++curAxis)
{
SerializedProperty inputAxisProperty = axesProp.GetArrayElementAtIndex(curAxis);
m_Axes.Add(new ClientSimInputAxis(inputAxisProperty));
}
}
public bool Equals(ClientSimInputAxesSettings other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
if (m_Axes.Count != other.m_Axes.Count)
{
return false;
}
for (int cur = 0; cur < m_Axes.Count; ++cur)
{
if (!m_Axes[cur].Equals(other.m_Axes[cur]))
{
return false;
}
}
return true;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((ClientSimInputAxesSettings) obj);
}
public override int GetHashCode()
{
return (m_Axes != null ? m_Axes.GetHashCode() : 0);
}
[Serializable]
public class ClientSimInputAxis : IEquatable<ClientSimInputAxis>
{
[FormerlySerializedAs("name")]
public string m_Name;
public string descriptiveName;
public string descriptiveNegativeName;
public string negativeButton;
public string positiveButton;
public string altNegativeButton;
public string altPositiveButton;
public float gravity;
public float dead;
public float sensitivity;
public bool snap;
public bool invert;
public int type;
public int axis;
public int joyNum;
public ClientSimInputAxis() { }
public ClientSimInputAxis(SerializedProperty inputAxisProperty)
{
SerializedProperty nameProp = inputAxisProperty.FindPropertyRelative(nameof(m_Name));
SerializedProperty descriptiveNameProp = inputAxisProperty.FindPropertyRelative(nameof(descriptiveName));
SerializedProperty descriptiveNegativeNameProp = inputAxisProperty.FindPropertyRelative(nameof(descriptiveNegativeName));
SerializedProperty negativeButtonProp = inputAxisProperty.FindPropertyRelative(nameof(negativeButton));
SerializedProperty positiveButtonProp = inputAxisProperty.FindPropertyRelative(nameof(positiveButton));
SerializedProperty altNegativeButtonProp = inputAxisProperty.FindPropertyRelative(nameof(altNegativeButton));
SerializedProperty altPositiveButtonProp = inputAxisProperty.FindPropertyRelative(nameof(altPositiveButton));
SerializedProperty gravityProp = inputAxisProperty.FindPropertyRelative(nameof(gravity));
SerializedProperty deadProp = inputAxisProperty.FindPropertyRelative(nameof(dead));
SerializedProperty sensitivityProp = inputAxisProperty.FindPropertyRelative(nameof(sensitivity));
SerializedProperty snapProp = inputAxisProperty.FindPropertyRelative(nameof(snap));
SerializedProperty invertProp = inputAxisProperty.FindPropertyRelative(nameof(invert));
SerializedProperty typeProp = inputAxisProperty.FindPropertyRelative(nameof(type));
SerializedProperty axisProp = inputAxisProperty.FindPropertyRelative(nameof(axis));
SerializedProperty joyNumProp = inputAxisProperty.FindPropertyRelative(nameof(joyNum));
m_Name = nameProp.stringValue;
descriptiveName = descriptiveNameProp.stringValue;
descriptiveNegativeName = descriptiveNegativeNameProp.stringValue;
negativeButton = negativeButtonProp.stringValue;
positiveButton = positiveButtonProp.stringValue;
altNegativeButton = altNegativeButtonProp.stringValue;
altPositiveButton = altPositiveButtonProp.stringValue;
gravity = gravityProp.floatValue;
dead = deadProp.floatValue;
sensitivity = sensitivityProp.floatValue;
snap = snapProp.boolValue;
invert = invertProp.boolValue;
type = typeProp.intValue;
axis = axisProp.intValue;
joyNum = joyNumProp.intValue;
}
public bool Equals(ClientSimInputAxis other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return m_Name == other.m_Name
&& descriptiveName == other.descriptiveName
&& descriptiveNegativeName == other.descriptiveNegativeName
&& negativeButton == other.negativeButton
&& positiveButton == other.positiveButton
&& altNegativeButton == other.altNegativeButton
&& altPositiveButton == other.altPositiveButton
&& Mathf.Approximately(gravity, other.gravity)
&& Mathf.Approximately(dead, other.dead)
&& Mathf.Approximately(sensitivity, other.sensitivity)
&& snap == other.snap
&& invert == other.invert
&& type == other.type
&& axis == other.axis
&& joyNum == other.joyNum;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((ClientSimInputAxis) obj);
}
public override int GetHashCode()
{
unchecked
{
var hashCode = (m_Name != null ? m_Name.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (descriptiveName != null ? descriptiveName.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (descriptiveNegativeName != null ? descriptiveNegativeName.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (negativeButton != null ? negativeButton.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (positiveButton != null ? positiveButton.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (altNegativeButton != null ? altNegativeButton.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (altPositiveButton != null ? altPositiveButton.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ gravity.GetHashCode();
hashCode = (hashCode * 397) ^ dead.GetHashCode();
hashCode = (hashCode * 397) ^ sensitivity.GetHashCode();
hashCode = (hashCode * 397) ^ snap.GetHashCode();
hashCode = (hashCode * 397) ^ invert.GetHashCode();
hashCode = (hashCode * 397) ^ type;
hashCode = (hashCode * 397) ^ axis;
hashCode = (hashCode * 397) ^ joyNum;
return hashCode;
}
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7b749a2c3c49f074cbaac7ef4353ac9f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,133 @@
using System.IO;
using UnityEditor;
using UnityEngine;
namespace VRC.SDK3.ClientSim.Editor
{
/// <summary>
/// Class used to verify current project settings and to apply required ClientSim Settings.
/// Currently only has the ability to set Audio Spatializer, Input Axes, and Input Type project settings.
/// </summary>
public static class ClientSimProjectSettingsSetup
{
public static bool IsUsingCorrectSettings()
{
return
IsUsingCorrectInputAxesSettings()
&& IsUsingCorrectInputTypeSettings()
&& IsUsingCorrectAudioSettings()
&& (UpdateLayers.AreLayersSetup() && UpdateLayers.IsCollisionLayerMatrixSetup());
}
#region InputAxes
private const string INPUT_AXES_NAME = "ClientSimInputManager";
private const string INPUT_AXES_RAW_NAME = ".ClientSimInputManagerRaw.asset";
private static readonly string _projectInputManagerPath = Path.Combine("ProjectSettings", "InputManager.asset");
private static readonly string _inputAxesRawPath = Path.Combine("Editor", "Resources", INPUT_AXES_RAW_NAME);
private static ClientSimInputAxesSettings _inputAxes;
public static bool IsUsingCorrectInputAxesSettings()
{
ClientSimInputAxesSettings clientSimAxes = ReadClientSimInputAxes();
ClientSimInputAxesSettings projectAxes = ReadProjectInputAxes();
// TODO verify axes on an individual level rather than verifying the entire axis list. Users may want other
// axes for personal reasons but this prevents that.
return clientSimAxes.Equals(projectAxes);
}
public static void ApplyClientSimInputAxes()
{
string packagePath = ClientSimResourceLoader.GetResolvePath();
string clientSimAxesPath = Path.Combine(packagePath, _inputAxesRawPath);
// User may have installed ClientSim in a non package way. The file is expected to be in the same directory
// as the input settings file. Use that to determine the proper location.
if (string.IsNullOrEmpty(packagePath))
{
ReadClientSimInputAxes();
string directory = Path.GetDirectoryName(AssetDatabase.GetAssetPath(_inputAxes));
clientSimAxesPath = Path.Combine(directory, INPUT_AXES_RAW_NAME);
}
string projectAxesPath = Path.Combine(Application.dataPath, "..", _projectInputManagerPath);
File.Copy(clientSimAxesPath, projectAxesPath, true);
AssetDatabase.Refresh();
}
private static ClientSimInputAxesSettings ReadClientSimInputAxes()
{
if (_inputAxes == null)
{
_inputAxes = Resources.Load<ClientSimInputAxesSettings>(INPUT_AXES_NAME);
}
return _inputAxes;
}
private static ClientSimInputAxesSettings ReadProjectInputAxes()
{
Object inputManager = AssetDatabase.LoadAssetAtPath<Object>(_projectInputManagerPath);
ClientSimInputAxesSettings inputObject = ScriptableObject.CreateInstance<ClientSimInputAxesSettings>();
inputObject.LoadFromSerializedObject(new SerializedObject(inputManager));
return inputObject;
}
#endregion
#region Input Manager
// Verify input is set to use both old and new input types.
public static bool IsUsingCorrectInputTypeSettings()
{
SerializedObject serializedObject = new SerializedObject(AssetDatabase.LoadAssetAtPath<Object>("ProjectSettings/ProjectSettings.asset"));
SerializedProperty activeInputHandler = serializedObject.FindProperty("activeInputHandler");
return activeInputHandler.intValue != 1;
}
public static void SetInputTypeSettings()
{
SerializedObject serializedObject = new SerializedObject(AssetDatabase.LoadAssetAtPath<Object>("ProjectSettings/ProjectSettings.asset"));
SerializedProperty activeInputHandler = serializedObject.FindProperty("activeInputHandler");
activeInputHandler.intValue = 1;
serializedObject.ApplyModifiedProperties();
}
#endregion
#region Audio Spatializer
public static bool IsUsingCorrectAudioSettings()
{
SerializedObject serializedObject = new SerializedObject(AssetDatabase.LoadAssetAtPath<Object>("ProjectSettings/AudioManager.asset"));
SerializedProperty spatializerPluginProp = serializedObject.FindProperty("m_SpatializerPlugin");
SerializedProperty ambisonicDecoderPluginProp = serializedObject.FindProperty("m_AmbisonicDecoderPlugin");
return
spatializerPluginProp.stringValue == "OculusSpatializer"
&& ambisonicDecoderPluginProp.stringValue == "OculusSpatializer";
}
public static void SetAudioSettings()
{
SerializedObject serializedObject = new SerializedObject(AssetDatabase.LoadAssetAtPath<Object>("ProjectSettings/AudioManager.asset"));
SerializedProperty spatializerPluginProp = serializedObject.FindProperty("m_SpatializerPlugin");
SerializedProperty ambisonicDecoderPluginProp = serializedObject.FindProperty("m_AmbisonicDecoderPlugin");
spatializerPluginProp.stringValue = "OculusSpatializer";
ambisonicDecoderPluginProp.stringValue = "OculusSpatializer";
serializedObject.ApplyModifiedProperties();
}
#endregion
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: bac8caddcef14fa9a80bf167d612dbaf
timeCreated: 1638973572