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,108 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
using VRC.SDK3.ClientSim.Editor.VisualElements.EncodeDecodeEditors;
using VRC.SDK3.ClientSim.Interfaces;
using VRC.SDK3.Components;
using VRC.SDK3.Data;
using VRC.Udon;
namespace VRC.SDK3.ClientSim.Editor.VisualElements
{
#if VRC_ENABLE_PLAYER_PERSISTENCE
public class ClientSimNetworkHolderInstanceElement : VisualElement
{
private GameObject _gameObject;
private string _componentName;
private string _componentType;
private MonoBehaviour _component;
private Foldout foldout;
private IClientSimNetworkSerializer networkView;
internal static Dictionary<string,IClientSimEncodeDecoderEditor> encodeDecoders = new Dictionary<string,IClientSimEncodeDecoderEditor>
{
{ typeof(VRCObjectSync).FullName, new ClientSimObjectSyncEncodeDecodeEditor() },
{ typeof(UdonBehaviour).FullName, new ClientSimUdonEncodeDecodeEditor() },
{ typeof(VRCObjectPool).FullName, new ClientSimObjectPoolEncodeDecodeEditor()}
};
private VisualElement _dataElements;
public ClientSimNetworkHolderInstanceElement()
{
foldout = new Foldout();
Button selectButton = new Button(() =>
{
Selection.activeObject = _gameObject;
});
selectButton.text = ">";
foldout.Q<Toggle>().Add(selectButton);
this.Add(foldout);
}
private void GetDataFromComponent(int index)
{
_component = networkView.GetNetworkComponents()[index];
_gameObject = _component.gameObject;
_componentType = _component.GetType().FullName;
if (_component is UdonBehaviour)
{
_componentName = ((UdonBehaviour) _component).programSource.name;
}
else
{
_componentName = _component.GetType().Name;
}
}
private void GenerateDataElements(int index)
{
if (encodeDecoders.TryGetValue(_componentType, out var encodeDecoder))
{
_dataElements = encodeDecoder.GenerateFields(_component, networkView.GetData()[index].DataDictionary);
}
}
public void UpdateData(ClientSimPlayerObjectWindow.PlayerObjectData data)
{
if (data.NetworkView != networkView)
{
foldout.Clear();
networkView = data.NetworkView;
GetDataFromComponent(data.index);
this.name = $"{_componentName}({_gameObject.name})";
foldout.text = $"{_componentName}({_gameObject.name})";
GenerateDataElements(data.index);
foldout.Add(_dataElements);
}
if (encodeDecoders.TryGetValue(_componentType, out var encodeDecoder))
{
if (_dataElements == null)
{
GenerateDataElements(data.index);
foldout.Clear();
foldout.Add(_dataElements);
}
else
{
encodeDecoder.UpdateFields(_component, _dataElements, networkView.GetData()[data.index].DataDictionary);
}
}
style.display = networkView.GetData().Count > 0 ? DisplayStyle.Flex : DisplayStyle.None;
}
}
#endif
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4f3e1ce223c6460aa9a05edbecf50b31
timeCreated: 1715614752

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5715f6d9033043f6a25678681d632679
timeCreated: 1716478398

View File

@ -0,0 +1,33 @@
using Newtonsoft.Json.Linq;
using UnityEngine;
using UnityEngine.UIElements;
using VRC.SDK3.ClientSim.Editor.VisualElements.Fields;
using VRC.SDK3.Data;
namespace VRC.SDK3.ClientSim.Editor.VisualElements.EncodeDecodeEditors
{
public class ClientSimObjectPoolEncodeDecodeEditor : IClientSimEncodeDecoderEditor
{
public VisualElement GenerateFields(MonoBehaviour component, DataDictionary data)
{
VisualElement container = new VisualElement();
DataList values = (DataList) data["Values"];
for(int i = 0; i < (int)data["Length"].Double; i++)
{
container.Add(FieldFactory.GenerateField("Object " + i , values[i].Boolean));
}
return container;
}
public void UpdateFields(MonoBehaviour component, VisualElement dataElement, DataDictionary data)
{
DataList values = (DataList) data["Values"];
for(int i = 0; i < (int)data["Length"].Double; i++)
{
FieldFactory.UpdateField(dataElement[i], values[i].Boolean);
}
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9861710bbbed4136b87f8ecfb5500488
timeCreated: 1716478455

View File

@ -0,0 +1,140 @@
using Newtonsoft.Json.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
using VRC.SDK3.ClientSim.Editor.VisualElements.Fields;
using VRC.SDK3.Data;
namespace VRC.SDK3.ClientSim.Editor.VisualElements.EncodeDecodeEditors
{
public class ClientSimObjectSyncEncodeDecodeEditor : IClientSimEncodeDecoderEditor
{
private const string Discontinuitycounter = "DiscontinuityCounter";
private const string Discontinuity = "Discontinuity";
private const string Heldinhand = "HeldInHand";
private const string Time = "Time";
private const string Wassleeping = "WasSleeping";
private const string Usegravity = "UseGravity";
private const string Iskinematic = "IsKinematic";
private const string Velocity = "Velocity";
private const string Rotation = "Rotation";
private const string FieldName = "Position";
private const string NotAvailable = "not available";
public VisualElement GenerateFields(MonoBehaviour component, DataDictionary data)
{
VisualElement dataElement = new VisualElement();
if (data.TryGetValue(FieldName, out DataToken positionToken))
{
dataElement.Add(FieldFactory.GenerateField(FieldName, positionToken.GetVector3()));
}
if (data.TryGetValue(Rotation, out DataToken rotationToken))
{
dataElement.Add(FieldFactory.GenerateField("Rotation: " , rotationToken.GetQuaternion()));
}
if (data.TryGetValue(Velocity, out DataToken velocityToken))
{
if(velocityToken.TokenType != TokenType.DataDictionary)
dataElement.Add(FieldFactory.GenerateField("Velocity: " , NotAvailable));
else
dataElement.Add(FieldFactory.GenerateField("Velocity: " , velocityToken.GetVector3()));
}
if (data.TryGetValue(Iskinematic, out DataToken isKinematicToken))
{
dataElement.Add(FieldFactory.GenerateField("Is Kinematic: " , isKinematicToken.Boolean));
}
if (data.TryGetValue(Usegravity, out DataToken useGravityToken))
{
dataElement.Add(FieldFactory.GenerateField("Use Gravity: " , useGravityToken.Boolean));
}
if (data.TryGetValue(Wassleeping, out DataToken wasSleepingToken))
{
dataElement.Add(FieldFactory.GenerateField("Was Sleeping: " , wasSleepingToken.Boolean));
}
if (data.TryGetValue(Time, out DataToken timeToken))
{
dataElement.Add(FieldFactory.GenerateField("Time: " , (float)timeToken.Double));
}
if (data.TryGetValue(Heldinhand, out DataToken heldInHandToken))
{
dataElement.Add(FieldFactory.GenerateField("Held In Hand: " , heldInHandToken.String));
}
if (data.TryGetValue(Discontinuity, out DataToken discontinuityToken))
{
dataElement.Add(FieldFactory.GenerateField("Discontinuity: " , discontinuityToken.String));
}
if (data.TryGetValue(Discontinuitycounter, out DataToken discontinuityCounterToken))
{
dataElement.Add(FieldFactory.GenerateField("Discontinuity Counter: " , discontinuityCounterToken.String));
}
return dataElement;
}
public void UpdateFields(MonoBehaviour component, VisualElement dataElement, DataDictionary data)
{
if (data.TryGetValue(FieldName, out DataToken positionToken))
{
FieldFactory.UpdateField(dataElement[0], positionToken.GetVector3());
}
if (data.TryGetValue(Rotation, out DataToken rotationToken))
{
FieldFactory.UpdateField(dataElement[1], rotationToken.GetQuaternion());
}
if (data.TryGetValue(Velocity, out DataToken velocityToken))
{
if(velocityToken.TokenType != TokenType.DataDictionary)
FieldFactory.UpdateField(dataElement[2], NotAvailable);
else
FieldFactory.UpdateField(dataElement[2], velocityToken.GetVector3());
}
if (data.TryGetValue(Iskinematic, out DataToken isKinematicToken))
{
FieldFactory.UpdateField(dataElement[3], isKinematicToken.Boolean);
}
if (data.TryGetValue(Usegravity, out DataToken useGravityToken))
{
FieldFactory.UpdateField(dataElement[4], useGravityToken.Boolean);
}
if (data.TryGetValue(Wassleeping, out DataToken wasSleepingToken))
{
FieldFactory.UpdateField(dataElement[5], wasSleepingToken.Boolean);
}
if (data.TryGetValue(Time, out DataToken timeToken))
{
FieldFactory.UpdateField(dataElement[6], (float)timeToken.Double);
}
if (data.TryGetValue(Heldinhand, out DataToken heldInHandToken))
{
FieldFactory.UpdateField(dataElement[7], heldInHandToken.String);
}
if (data.TryGetValue(Discontinuity, out DataToken discontinuityToken))
{
FieldFactory.UpdateField(dataElement[8] , discontinuityToken.String);
}
if (data.TryGetValue(Discontinuitycounter, out DataToken discontinuityCounterToken))
{
FieldFactory.UpdateField(dataElement[9], discontinuityCounterToken.String);
}
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 77215cffe9bd4a6fa08514c2722c218a
timeCreated: 1716478863

View File

@ -0,0 +1,121 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Newtonsoft.Json.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
using VRC.SDK3.ClientSim.Editor.VisualElements.Fields;
using VRC.SDK3.Data;
using VRC.SDKBase;
using VRC.Udon;
using VRC.Udon.Common.Interfaces;
using VRC.Udon.Editor.ProgramSources.UdonGraphProgram.UI;
using VRC.Udon.Editor.ProgramSources.UdonGraphProgram.UI.GraphView;
namespace VRC.SDK3.ClientSim.Editor.VisualElements.EncodeDecodeEditors
{
public class ClientSimUdonEncodeDecodeEditor : IClientSimEncodeDecoderEditor
{
public VisualElement GenerateFields(MonoBehaviour component,DataDictionary data)
{
UdonBehaviour udonBehaviour = component as UdonBehaviour;
IEnumerable<IUdonSyncMetadata> SyncMetadatas = udonBehaviour.SyncMetadataTable.GetAllSyncMetadata();
VisualElement dataElement = new VisualElement();
foreach (IUdonSyncMetadata syncMetadata in SyncMetadatas)
{
if (data.ContainsKey(syncMetadata.Name))
{
VisualElement field = FieldFactory.GenerateField(syncMetadata.Name, GetCorrectTypeFromDataToken(data[syncMetadata.Name]));
field.name = syncMetadata.Name;
dataElement.Add(field);
}
}
return dataElement;
}
public void UpdateFields(MonoBehaviour component, VisualElement dataElement, DataDictionary data)
{
UdonBehaviour udonBehaviour = component as UdonBehaviour;
IEnumerable<IUdonSyncMetadata> SyncMetadatas = udonBehaviour.SyncMetadataTable.GetAllSyncMetadata();
int index = 0;
foreach (IUdonSyncMetadata syncMetadata in SyncMetadatas)
{
if (data.ContainsKey(syncMetadata.Name))
{
FieldFactory.UpdateField(dataElement[index], GetCorrectTypeFromDataToken(data[syncMetadata.Name]));
index++;
}
}
}
private object GetCorrectTypeFromDataToken(DataToken token)
{
switch (token.TokenType)
{
case TokenType.Boolean:
return token.Boolean;
case TokenType.SByte:
return token.SByte;
case TokenType.Byte:
return token.Byte;
case TokenType.Short:
return token.Short;
case TokenType.UShort:
return token.UShort;
case TokenType.Int:
return token.Int;
case TokenType.UInt:
return token.UInt;
case TokenType.Long:
return token.Long;
case TokenType.ULong:
return token.ULong;
case TokenType.Float:
return token.Float;
case TokenType.Double:
return token.Double;
case TokenType.String:
return token.String;
case TokenType.Reference:
return token.Reference;
case TokenType.DataList:
DataList dataList = token.DataList;
object[] list = new object[dataList.Count];
for(int i =0; i < dataList.Count; i++)
{
list[i] = GetCorrectTypeFromDataToken(dataList[i]);
}
return list;
case TokenType.DataDictionary:
DataDictionary dataDictionary = token.DataDictionary;
if(!dataDictionary.ContainsKey("T")) return null;
string type = dataDictionary["T"].String;
switch (type)
{
case "V2":
return token.GetVector2();
case "V3":
return token.GetVector3();
case "V4":
return token.GetVector4();
case "Q":
return token.GetQuaternion();
case "C":
return token.GetColor();
case "C32":
return token.GetColor32();
default:
return null;
}
default:
return null;
}
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1d6751e9563f4c939b96aaf7bbc7cb0f
timeCreated: 1716481521

View File

@ -0,0 +1,13 @@
using Newtonsoft.Json.Linq;
using UnityEngine;
using UnityEngine.UIElements;
using VRC.SDK3.Data;
namespace VRC.SDK3.ClientSim.Editor.VisualElements.EncodeDecodeEditors
{
public interface IClientSimEncodeDecoderEditor
{
public VisualElement GenerateFields(MonoBehaviour component, DataDictionary data);
public void UpdateFields(MonoBehaviour component, VisualElement dataElement, DataDictionary data);
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ccf6036bf1854d7f800ce01e60ab4d1c
timeCreated: 1716478565

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f0ace7b221a14ff8af6b1c0262de9da0
timeCreated: 1716411089

View File

@ -0,0 +1,150 @@
using System;
using System.Globalization;
using UnityEngine;
using UnityEngine.UIElements;
namespace VRC.SDK3.ClientSim.Editor.VisualElements.Fields
{
public class ByteField : TextValueField<byte>
{
/// <summary>
/// <para>
/// USS class name of elements of this type.
/// </para>
/// </summary>
public new static readonly string ussClassName = "vrc-byte-field";
/// <summary>
/// <para>
/// USS class name of labels in elements of this type.
/// </para>
/// </summary>
public new static readonly string labelUssClassName = ByteField.ussClassName + "__label";
/// <summary>
/// <para>
/// USS class name of input elements in elements of this type.
/// </para>
/// </summary>
public new static readonly string inputUssClassName = ByteField.ussClassName + "__input";
private ByteField.ByteInput byteInput => (ByteField.ByteInput) this.textInputBase;
/// <summary>
/// <para>
/// Converts the given integer to a string.
/// </para>
/// </summary>
/// <param name="v">The integer to be converted to string.</param>
/// <returns>
/// <para>The integer as string.</para>
/// </returns>
protected override string ValueToString(byte v) => v.ToString(this.formatString, (IFormatProvider) CultureInfo.InvariantCulture.NumberFormat);
/// <summary>
/// <para>
/// Converts a string to an integer.
/// </para>
/// </summary>
/// <param name="str">The string to convert.</param>
/// <returns>
/// <para>The integer parsed from the string.</para>
/// </returns>
protected override byte StringToValue(string str)
{
byte num;
return ClientSimUINumericFieldsUtils.TryConvertStringToByte(str, this.textInputBase.text, out num) ? num : this.rawValue;
}
/// <summary>
/// <para>
/// Constructor.
/// </para>
/// </summary>
public ByteField()
: this((string) null)
{
}
/// <summary>
/// <para>
/// Constructor.
/// </para>
/// </summary>
/// <param name="maxLength">Maximum number of characters the field can take.</param>
public ByteField(int maxLength)
: this((string) null, maxLength)
{
}
/// <summary>
/// <para>
/// Constructor.
/// </para>
/// </summary>
/// <param name="maxLength">Maximum number of characters the field can take.</param>
/// <param name="label"></param>
public ByteField(string label, int maxLength = -1)
: base(label, maxLength, (TextValueField<byte>.TextValueInput) new ByteField.ByteInput())
{
this.AddToClassList(ByteField.ussClassName);
this.labelElement.AddToClassList(ByteField.labelUssClassName);
this.AddLabelDragger<byte>();
}
/// <summary>
/// <para>
/// Applies the values of a 3D delta and a speed from an input device.
/// </para>
/// </summary>
/// <param name="delta">A vector used to compute the value change.</param>
/// <param name="speed">A multiplier for the value change.</param>
/// <param name="startValue">The start value.</param>
public override void ApplyInputDeviceDelta(Vector3 delta, DeltaSpeed speed, byte startValue) => this.byteInput.ApplyInputDeviceDelta(delta, speed, startValue);
/// <summary>
/// <para>
/// Instantiates an IntegerField using the data read from a UXML file.
/// </para>
/// </summary>
public new class UxmlFactory : UnityEngine.UIElements.UxmlFactory<ByteField, ByteField.UxmlTraits>
{
}
/// <summary>
/// <para>
/// Defines UxmlTraits for the IntegerField.
/// </para>
/// </summary>
public new class UxmlTraits : TextValueFieldTraits<int, UxmlIntAttributeDescription>
{
}
private class ByteInput : TextValueField<byte>.TextValueInput
{
private ByteField parentByteField => (ByteField) this.parent;
internal ByteInput() => this.formatString = ClientSimUINumericFieldsUtils.k_ByteFieldFormatString;
protected override string allowedCharacters => ClientSimUINumericFieldsUtils.k_AllowedCharactersForByte;
public override void ApplyInputDeviceDelta(Vector3 delta, DeltaSpeed speed, byte startValue)
{
double intDragSensitivity = (double) ClientSimNumericFieldDraggerUtility.CalculateIntDragSensitivity((long) startValue);
float acceleration = ClientSimNumericFieldDraggerUtility.Acceleration(speed == DeltaSpeed.Fast, speed == DeltaSpeed.Slow);
long num = (long) this.StringToValue(this.text) + (long) Math.Round((double) ClientSimNumericFieldDraggerUtility.NiceDelta((Vector2) delta, acceleration) * intDragSensitivity);
if (this.parentByteField.isDelayed)
this.text = this.ValueToString((byte)Mathf.Clamp(num,0,255));
else
this.parentByteField.value = (byte)Mathf.Clamp(num,0,255);
}
protected override string ValueToString(byte v) => v.ToString(this.formatString);
protected override byte StringToValue(string str)
{
byte num;
ClientSimUINumericFieldsUtils.TryConvertStringToByte(str, this.text, out num);
return num;
}
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 00039a4bded043e386c649a36454b746
timeCreated: 1716566750

View File

@ -0,0 +1,40 @@
using System;
using UnityEngine;
namespace VRC.SDK3.ClientSim.Editor.VisualElements.Fields
{
public class ClientSimNumericFieldDraggerUtility
{
private static bool s_UseYSign;
private const double kDragSensitivity = 0.029999999329447746;
private const double kYSignThreshold = 0.10000000149011612;
internal static float Acceleration(bool shiftPressed, bool altPressed) => (float) ((shiftPressed ? 4.0 : 1.0) * (altPressed ? 0.25 : 1.0));
internal static float NiceDelta(Vector2 deviceDelta, float acceleration)
{
deviceDelta.y = -deviceDelta.y;
if ((double) Mathf.Abs(Mathf.Abs(deviceDelta.x) - Mathf.Abs(deviceDelta.y)) / (double) Mathf.Max(Mathf.Abs(deviceDelta.x), Mathf.Abs(deviceDelta.y)) > kYSignThreshold)
ClientSimNumericFieldDraggerUtility.s_UseYSign = (double) Mathf.Abs(deviceDelta.x) <= (double) Mathf.Abs(deviceDelta.y);
return ClientSimNumericFieldDraggerUtility.s_UseYSign ? Mathf.Sign(deviceDelta.y) * deviceDelta.magnitude * acceleration : Mathf.Sign(deviceDelta.x) * deviceDelta.magnitude * acceleration;
}
internal static double CalculateFloatDragSensitivity(double value) => double.IsInfinity(value) || double.IsNaN(value) ? 0.0 : Math.Max(1.0, Math.Pow(Math.Abs(value), 0.5)) * kDragSensitivity;
internal static double CalculateFloatDragSensitivity(
double value,
double minValue,
double maxValue)
{
return double.IsInfinity(value) || double.IsNaN(value) ? 0.0 : Math.Abs(maxValue - minValue) / 100.0 * kDragSensitivity;
}
internal static long CalculateIntDragSensitivity(long value) => (long) ClientSimNumericFieldDraggerUtility.CalculateIntDragSensitivity((double) value);
internal static ulong CalculateIntDragSensitivity(ulong value) => (ulong) ClientSimNumericFieldDraggerUtility.CalculateIntDragSensitivity((double) value);
private static double CalculateIntDragSensitivity(double value) => Math.Max(1.0, Math.Pow(Math.Abs(value), 0.5) * kDragSensitivity);
internal static long CalculateIntDragSensitivity(long value, long minValue, long maxValue) => Math.Max(1L, (long) (kDragSensitivity * (double) Math.Abs(maxValue - minValue) / 100.0));
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 47c8de80824e4de98b823afd757d760c
timeCreated: 1716567169

View File

@ -0,0 +1,110 @@
using UnityEngine;
namespace VRC.SDK3.ClientSim.Editor.VisualElements.Fields
{
public class ClientSimUINumericFieldsUtils
{
public static readonly string k_AllowedCharactersForFloat = "inftynaeINFTYNAE0123456789.,-*/+%^()cosqrludxvRL=pP#";
public static readonly string k_AllowedCharactersForByte = "0123456789-*/+%^()cosintaqrtelfundxvRL,=pPI#";
public static readonly string k_DoubleFieldFormatString = "R";
public static readonly string k_FloatFieldFormatString = "g7";
public static readonly string k_ByteFieldFormatString = "###0";
public static bool TryConvertStringToLong(
string str,
out long value)
{
return ExpressionEvaluator.Evaluate<long>(str, out value);
}
public static bool TryConvertStringToULong(
string str,
out ulong value)
{
return ExpressionEvaluator.Evaluate<ulong>(str, out value);
}
public static bool TryConvertStringToLong(
string str,
string initialValueAsString,
out long value)
{
bool flag = TryConvertStringToLong(str, out value);
long num;
if (!flag && !string.IsNullOrEmpty(initialValueAsString) && TryConvertStringToLong(initialValueAsString, out num))
{
value = num;
}
return flag;
}
public static bool TryConvertStringToByte(
string str,
string initialValueAsString,
out byte value)
{
long num;
bool flag = TryConvertStringToLong(str, initialValueAsString, out num);
value = (byte)Mathf.Clamp((int)num, (int)byte.MinValue, (int)byte.MaxValue);
return flag;
}
public static bool TryConvertStringToSbyte(
string str,
string initialValueAsString,
out sbyte value)
{
long num;
bool flag = TryConvertStringToLong(str, initialValueAsString, out num);
value = (sbyte)Mathf.Clamp((int)num, (int)sbyte.MinValue, (int)sbyte.MaxValue);
return flag;
}
public static bool TryConvertStringToUInt(
string str,
string initialValueAsString,
out uint value)
{
long num;
bool flag = TryConvertStringToLong(str, initialValueAsString, out num);
value = num < uint.MinValue ? uint.MinValue: num > uint.MaxValue ? uint.MaxValue : (uint)num;
return flag;
}
public static bool TryConvertStringToULong(
string str,
string initialValueAsString,
out ulong value)
{
bool flag = TryConvertStringToULong(str, out value);
if (!flag && !string.IsNullOrEmpty(initialValueAsString) && TryConvertStringToULong(initialValueAsString, out ulong num))
{
value = num;
}
return flag;
}
public static bool TryConvertStringToShort(
string str,
string initialValueAsString,
out short value)
{
long num;
bool flag = TryConvertStringToLong(str, initialValueAsString, out num);
value = num < short.MinValue ? short.MinValue: num > short.MaxValue ? short.MaxValue : (short)num;
return flag;
}
public static bool TryConvertStringToUShort(
string str,
string initialValueAsString,
out ushort value)
{
long num;
bool flag = TryConvertStringToLong(str, initialValueAsString, out num);
value = num < ushort.MinValue ? ushort.MinValue: num > ushort.MaxValue ? ushort.MaxValue : (ushort)num;
return flag;
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 19c8c6acc9b1415c9b2efaadd21e3916
timeCreated: 1716567113

View File

@ -0,0 +1,177 @@
using System;
using System.Collections.Generic;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
namespace VRC.SDK3.ClientSim.Editor.VisualElements.Fields
{
public class FieldFactory
{
private static Dictionary<Type, (Func<string, VisualElement>, Action<VisualElement,object>)> _types =
new Dictionary<Type, (Func<string, VisualElement>, Action<VisualElement,object>)>()
{
{ typeof(byte), ((name) => new ByteField(name),
(element, o) => ((ByteField)element).SetValueWithoutNotify((byte)o)) },
{ typeof(sbyte), ((name) => new SbyteField(name),
(element, o) => ((SbyteField)element).SetValueWithoutNotify((sbyte)o)) },
{ typeof(double), ((name) => new DoubleField(name),
(element, o) => ((DoubleField)element).SetValueWithoutNotify((double)o)) },
{ typeof(float), ((name) => new FloatField(name),
(element, o) => ((FloatField)element).SetValueWithoutNotify((float)o)) },
{ typeof(int), ((name) => new IntegerField(name),
(element, o) => ((IntegerField)element).SetValueWithoutNotify((int)o)) },
{ typeof(uint), ((name) => new UIntField(name),
(element, o) => ((UIntField)element).SetValueWithoutNotify((uint)o)) },
{ typeof(long), ((name => new LongField(name),
(element, o) => ((LongField)element).SetValueWithoutNotify((long)o))) },
{ typeof(ulong), ((name) => new ULongField(name),
(element, o) => ((ULongField)element).SetValueWithoutNotify((ulong)o)) },
{ typeof(short), ((name) => new ShortField(name),
(element, o) => ((ShortField)element).SetValueWithoutNotify((short)o)) },
{ typeof(ushort), ((name) => new UShortField(name),
(element, o) => ((UShortField)element).SetValueWithoutNotify((ushort)o)) },
{ typeof(string), ((name) => new TextField(name),
(element, o) => ((TextField)element).SetValueWithoutNotify((string)o)) },
{ typeof(char), ((name) => new TextField(name) { maxLength = 1 },
(element, o) => ((TextField)element).SetValueWithoutNotify(o.ToString())) },
{ typeof(bool), ((name) => new Toggle(name),
(element, o) => ((Toggle)element).SetValueWithoutNotify((bool)o)) },
{ typeof(Vector2), ((name) => new Vector2Field(name),
(element, o) => ((Vector2Field)element).SetValueWithoutNotify((Vector2)o))},
{ typeof(Vector3), ((name) => new Vector3Field(name),
(element, o) => ((Vector3Field)element).SetValueWithoutNotify((Vector3)o))},
{ typeof(Vector4), ((name) => new Vector4Field(name),
(element, o) => ((Vector4Field)element).SetValueWithoutNotify((Vector4)o))},
{ typeof(Quaternion), ((name) => new Vector3Field(name),
(element, o) => ((Vector3Field)element).SetValueWithoutNotify(((Quaternion)o).eulerAngles))},
{ typeof(Color), ((name) => new ColorField(name),
(element, o) => ((ColorField)element).SetValueWithoutNotify((Color)o))},
{ typeof(Color32), ((name) => new ColorField(name),
(element, o) => ((ColorField)element).SetValueWithoutNotify((Color32)o))},
};
private static Dictionary<Type,Type> _FieldType = new Dictionary<Type, Type>()
{
{ typeof(byte), typeof(ByteField) },
{ typeof(sbyte), typeof(SbyteField) },
{ typeof(double), typeof(DoubleField) },
{ typeof(float), typeof(FloatField) },
{ typeof(int), typeof(IntegerField) },
{ typeof(uint), typeof(UIntField) },
{ typeof(long), typeof(LongField) },
{ typeof(ulong), typeof(ULongField) },
{ typeof(short), typeof(ShortField) },
{ typeof(ushort), typeof(UShortField) },
{ typeof(string), typeof(TextField) },
{ typeof(char), typeof(TextField) },
{ typeof(bool), typeof(Toggle) },
{ typeof(Vector2), typeof(Vector2Field) },
{ typeof(Vector3), typeof(Vector3Field) },
{ typeof(Vector4), typeof(Vector4Field) },
{ typeof(Quaternion), typeof(Vector3Field) },
{ typeof(Color), typeof(ColorField) },
{ typeof(Color32), typeof(ColorField) },
};
public static VisualElement GenerateField<T>(string fieldName, T data)
{
Type type = data.GetType();
if (type.IsArray)
{
Foldout Array = new Foldout();
Array.text = fieldName;
for (int i = 0; i < ((Array)(object)data).Length; i++)
{
VisualElement field = GenerateField(i.ToString(), ((Array)(object)data).GetValue(i));
field.name = i.ToString();
Array.Add(field);
}
return Array;
}
if (_types.ContainsKey(type))
{
VisualElement field = _types[type].Item1(fieldName);
field.name = fieldName;
return field;
}
else
{
Label label = new Label(fieldName +" ("+type.Name+ "): " + data.ToString());
label.name = fieldName;
return label;
}
}
public static bool UpdateField<T>(VisualElement field, T data)
{
Type type = data.GetType();
bool visible = true;
if (type.IsArray)
{
visible = false;
int length = Math.Min(((Array)(object)data).Length,field.childCount);
for (int i = 0; i < length; i++)
{
visible |= UpdateField(field[i], ((Array)(object)data).GetValue(i));
}
if(length < field.childCount)
{
for (int i = length; i < field.childCount; i++)
{
field[i].style.display = DisplayStyle.None;
}
}
else if(length > field.childCount)
{
for (int i = field.childCount; i < length; i++)
{
VisualElement newField = GenerateField(i.ToString(), ((Array)(object)data).GetValue(i));
newField.name = i.ToString();
field.Add(newField);
}
}
return visible;
}
if (!_types.ContainsKey(type))
{
((Label)field).text = field.name + "("+type.Name+ "): " + data.ToString();
return visible;
}
// If the field is not the correct type, replace it with the correct type
// Can happen because json deserialization deserializes int, float, double, etc as double
if(_FieldType.ContainsKey(type))
{
if (field.GetType() != _FieldType[type])
{
VisualElement newField = GenerateField(field.name, data);
field.parent.Add(newField);
newField.PlaceInFront(field);
field.RemoveFromHierarchy();
return true;
}
}
else
{
Label label = new Label(field.name +" ("+type.Name+ "): " + data.ToString());
label.name = field.name;
field.parent.Add(label);
field.RemoveFromHierarchy();
return true;
}
_types[type].Item2(field, data);
return visible;
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b4807fe039954aa0b1c03bf75d5c6bdb
timeCreated: 1716411106

View File

@ -0,0 +1,150 @@
using System;
using System.Globalization;
using UnityEngine;
using UnityEngine.UIElements;
namespace VRC.SDK3.ClientSim.Editor.VisualElements.Fields
{
public class SbyteField : TextValueField<sbyte>
{
/// <summary>
/// <para>
/// USS class name of elements of this type.
/// </para>
/// </summary>
public new static readonly string ussClassName = "vrc-sbyte-field";
/// <summary>
/// <para>
/// USS class name of labels in elements of this type.
/// </para>
/// </summary>
public new static readonly string labelUssClassName = SbyteField.ussClassName + "__label";
/// <summary>
/// <para>
/// USS class name of input elements in elements of this type.
/// </para>
/// </summary>
public new static readonly string inputUssClassName = SbyteField.ussClassName + "__input";
private SbyteField.SbyteInput sbyteInput => (SbyteField.SbyteInput) this.textInputBase;
/// <summary>
/// <para>
/// Converts the given integer to a string.
/// </para>
/// </summary>
/// <param name="v">The integer to be converted to string.</param>
/// <returns>
/// <para>The integer as string.</para>
/// </returns>
protected override string ValueToString(sbyte v) => v.ToString(this.formatString, (IFormatProvider) CultureInfo.InvariantCulture.NumberFormat);
/// <summary>
/// <para>
/// Converts a string to an integer.
/// </para>
/// </summary>
/// <param name="str">The string to convert.</param>
/// <returns>
/// <para>The integer parsed from the string.</para>
/// </returns>
protected override sbyte StringToValue(string str)
{
sbyte num;
return ClientSimUINumericFieldsUtils.TryConvertStringToSbyte(str, this.textInputBase.text, out num) ? num : this.rawValue;
}
/// <summary>
/// <para>
/// Constructor.
/// </para>
/// </summary>
public SbyteField()
: this((string) null)
{
}
/// <summary>
/// <para>
/// Constructor.
/// </para>
/// </summary>
/// <param name="maxLength">Maximum number of characters the field can take.</param>
public SbyteField(int maxLength)
: this((string) null, maxLength)
{
}
/// <summary>
/// <para>
/// Constructor.
/// </para>
/// </summary>
/// <param name="maxLength">Maximum number of characters the field can take.</param>
/// <param name="label"></param>
public SbyteField(string label, int maxLength = -1)
: base(label, maxLength, (TextValueField<sbyte>.TextValueInput) new SbyteField.SbyteInput())
{
this.AddToClassList(SbyteField.ussClassName);
this.labelElement.AddToClassList(SbyteField.labelUssClassName);
this.AddLabelDragger<sbyte>();
}
/// <summary>
/// <para>
/// Applies the values of a 3D delta and a speed from an input device.
/// </para>
/// </summary>
/// <param name="delta">A vector used to compute the value change.</param>
/// <param name="speed">A multiplier for the value change.</param>
/// <param name="startValue">The start value.</param>
public override void ApplyInputDeviceDelta(Vector3 delta, DeltaSpeed speed, sbyte startValue) => this.sbyteInput.ApplyInputDeviceDelta(delta, speed, startValue);
/// <summary>
/// <para>
/// Instantiates an IntegerField using the data read from a UXML file.
/// </para>
/// </summary>
public new class UxmlFactory : UnityEngine.UIElements.UxmlFactory<SbyteField, SbyteField.UxmlTraits>
{
}
/// <summary>
/// <para>
/// Defines UxmlTraits for the IntegerField.
/// </para>
/// </summary>
public new class UxmlTraits : TextValueFieldTraits<int, UxmlIntAttributeDescription>
{
}
private class SbyteInput : TextValueField<sbyte>.TextValueInput
{
private SbyteField parentSByteField => (SbyteField) this.parent;
internal SbyteInput() => this.formatString = ClientSimUINumericFieldsUtils.k_ByteFieldFormatString;
protected override string allowedCharacters => ClientSimUINumericFieldsUtils.k_AllowedCharactersForByte;
public override void ApplyInputDeviceDelta(Vector3 delta, DeltaSpeed speed, sbyte startValue)
{
double intDragSensitivity = (double) ClientSimNumericFieldDraggerUtility.CalculateIntDragSensitivity((long) startValue);
float acceleration = ClientSimNumericFieldDraggerUtility.Acceleration(speed == DeltaSpeed.Fast, speed == DeltaSpeed.Slow);
long num = (long) this.StringToValue(this.text) + (long) Math.Round((double) ClientSimNumericFieldDraggerUtility.NiceDelta((Vector2) delta, acceleration) * intDragSensitivity);
if (this.parentSByteField.isDelayed)
this.text = this.ValueToString((sbyte)Mathf.Clamp(num,sbyte.MinValue,sbyte.MaxValue));
else
this.parentSByteField.value = (sbyte)Mathf.Clamp(num,sbyte.MinValue,sbyte.MaxValue);
}
protected override string ValueToString(sbyte v) => v.ToString(this.formatString);
protected override sbyte StringToValue(string str)
{
sbyte num;
ClientSimUINumericFieldsUtils.TryConvertStringToSbyte(str, this.text, out num);
return num;
}
}
}
}

View File

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

View File

@ -0,0 +1,150 @@
using System;
using System.Globalization;
using UnityEngine;
using UnityEngine.UIElements;
namespace VRC.SDK3.ClientSim.Editor.VisualElements.Fields
{
public class ShortField : TextValueField<short>
{
/// <summary>
/// <para>
/// USS class name of elements of this type.
/// </para>
/// </summary>
public new static readonly string ussClassName = "vrc-short-field";
/// <summary>
/// <para>
/// USS class name of labels in elements of this type.
/// </para>
/// </summary>
public new static readonly string labelUssClassName = ShortField.ussClassName + "__label";
/// <summary>
/// <para>
/// USS class name of input elements in elements of this type.
/// </para>
/// </summary>
public new static readonly string inputUssClassName = ShortField.ussClassName + "__input";
private ShortField.ShortInput shortInput => (ShortField.ShortInput) this.textInputBase;
/// <summary>
/// <para>
/// Converts the given integer to a string.
/// </para>
/// </summary>
/// <param name="v">The integer to be converted to string.</param>
/// <returns>
/// <para>The integer as string.</para>
/// </returns>
protected override string ValueToString(short v) => v.ToString(this.formatString, (IFormatProvider) CultureInfo.InvariantCulture.NumberFormat);
/// <summary>
/// <para>
/// Converts a string to an integer.
/// </para>
/// </summary>
/// <param name="str">The string to convert.</param>
/// <returns>
/// <para>The integer parsed from the string.</para>
/// </returns>
protected override short StringToValue(string str)
{
short num;
return ClientSimUINumericFieldsUtils.TryConvertStringToShort(str, this.textInputBase.text, out num) ? num : this.rawValue;
}
/// <summary>
/// <para>
/// Constructor.
/// </para>
/// </summary>
public ShortField()
: this((string) null)
{
}
/// <summary>
/// <para>
/// Constructor.
/// </para>
/// </summary>
/// <param name="maxLength">Maximum number of characters the field can take.</param>
public ShortField(int maxLength)
: this((string) null, maxLength)
{
}
/// <summary>
/// <para>
/// Constructor.
/// </para>
/// </summary>
/// <param name="maxLength">Maximum number of characters the field can take.</param>
/// <param name="label"></param>
public ShortField(string label, int maxLength = -1)
: base(label, maxLength, (TextValueField<short>.TextValueInput) new ShortField.ShortInput())
{
this.AddToClassList(ShortField.ussClassName);
this.labelElement.AddToClassList(ShortField.labelUssClassName);
this.AddLabelDragger<short>();
}
/// <summary>
/// <para>
/// Applies the values of a 3D delta and a speed from an input device.
/// </para>
/// </summary>
/// <param name="delta">A vector used to compute the value change.</param>
/// <param name="speed">A multiplier for the value change.</param>
/// <param name="startValue">The start value.</param>
public override void ApplyInputDeviceDelta(Vector3 delta, DeltaSpeed speed, short startValue) => this.shortInput.ApplyInputDeviceDelta(delta, speed, startValue);
/// <summary>
/// <para>
/// Instantiates an IntegerField using the data read from a UXML file.
/// </para>
/// </summary>
public new class UxmlFactory : UnityEngine.UIElements.UxmlFactory<ShortField, ShortField.UxmlTraits>
{
}
/// <summary>
/// <para>
/// Defines UxmlTraits for the IntegerField.
/// </para>
/// </summary>
public new class UxmlTraits : TextValueFieldTraits<int, UxmlIntAttributeDescription>
{
}
private class ShortInput : TextValueField<short>.TextValueInput
{
private ShortField parentByteField => (ShortField) this.parent;
internal ShortInput() => this.formatString = ClientSimUINumericFieldsUtils.k_ByteFieldFormatString;
protected override string allowedCharacters => ClientSimUINumericFieldsUtils.k_AllowedCharactersForByte;
public override void ApplyInputDeviceDelta(Vector3 delta, DeltaSpeed speed, short startValue)
{
double intDragSensitivity = (double) ClientSimNumericFieldDraggerUtility.CalculateIntDragSensitivity((long) startValue);
float acceleration = ClientSimNumericFieldDraggerUtility.Acceleration(speed == DeltaSpeed.Fast, speed == DeltaSpeed.Slow);
long num = (long) this.StringToValue(this.text) + (long) Math.Round((double) ClientSimNumericFieldDraggerUtility.NiceDelta((Vector2) delta, acceleration) * intDragSensitivity);
if (this.parentByteField.isDelayed)
this.text = this.ValueToString((short)Mathf.Clamp(num,0,255));
else
this.parentByteField.value = (short)Mathf.Clamp(num,0,255);
}
protected override string ValueToString(short v) => v.ToString(this.formatString);
protected override short StringToValue(string str)
{
short num;
ClientSimUINumericFieldsUtils.TryConvertStringToShort(str, this.text, out num);
return num;
}
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ef408243da1c4500b4542b7f7cc933ce
timeCreated: 1717421533

View File

@ -0,0 +1,150 @@
using System;
using System.Globalization;
using UnityEngine;
using UnityEngine.UIElements;
namespace VRC.SDK3.ClientSim.Editor.VisualElements.Fields
{
public class UIntField : TextValueField<uint>
{
/// <summary>
/// <para>
/// USS class name of elements of this type.
/// </para>
/// </summary>
public new static readonly string ussClassName = "vrc-UInt-field";
/// <summary>
/// <para>
/// USS class name of labels in elements of this type.
/// </para>
/// </summary>
public new static readonly string labelUssClassName = UIntField.ussClassName + "__label";
/// <summary>
/// <para>
/// USS class name of input elements in elements of this type.
/// </para>
/// </summary>
public new static readonly string inputUssClassName = UIntField.ussClassName + "__input";
private UIntField.UIntInput sbyteInput => (UIntField.UIntInput) this.textInputBase;
/// <summary>
/// <para>
/// Converts the given integer to a string.
/// </para>
/// </summary>
/// <param name="v">The integer to be converted to string.</param>
/// <returns>
/// <para>The integer as string.</para>
/// </returns>
protected override string ValueToString(uint v) => v.ToString(this.formatString, (IFormatProvider) CultureInfo.InvariantCulture.NumberFormat);
/// <summary>
/// <para>
/// Converts a string to an integer.
/// </para>
/// </summary>
/// <param name="str">The string to convert.</param>
/// <returns>
/// <para>The integer parsed from the string.</para>
/// </returns>
protected override uint StringToValue(string str)
{
uint num;
return ClientSimUINumericFieldsUtils.TryConvertStringToUInt(str, this.textInputBase.text, out num) ? num : this.rawValue;
}
/// <summary>
/// <para>
/// Constructor.
/// </para>
/// </summary>
public UIntField()
: this((string) null)
{
}
/// <summary>
/// <para>
/// Constructor.
/// </para>
/// </summary>
/// <param name="maxLength">Maximum number of characters the field can take.</param>
public UIntField(int maxLength)
: this((string) null, maxLength)
{
}
/// <summary>
/// <para>
/// Constructor.
/// </para>
/// </summary>
/// <param name="maxLength">Maximum number of characters the field can take.</param>
/// <param name="label"></param>
public UIntField(string label, int maxLength = -1)
: base(label, maxLength, (TextValueField<uint>.TextValueInput) new UIntField.UIntInput())
{
this.AddToClassList(UIntField.ussClassName);
this.labelElement.AddToClassList(UIntField.labelUssClassName);
this.AddLabelDragger<uint>();
}
/// <summary>
/// <para>
/// Applies the values of a 3D delta and a speed from an input device.
/// </para>
/// </summary>
/// <param name="delta">A vector used to compute the value change.</param>
/// <param name="speed">A multiplier for the value change.</param>
/// <param name="startValue">The start value.</param>
public override void ApplyInputDeviceDelta(Vector3 delta, DeltaSpeed speed, uint startValue) => this.sbyteInput.ApplyInputDeviceDelta(delta, speed, startValue);
/// <summary>
/// <para>
/// Instantiates an IntegerField using the data read from a UXML file.
/// </para>
/// </summary>
public new class UxmlFactory : UnityEngine.UIElements.UxmlFactory<UIntField, UIntField.UxmlTraits>
{
}
/// <summary>
/// <para>
/// Defines UxmlTraits for the IntegerField.
/// </para>
/// </summary>
public new class UxmlTraits : TextValueFieldTraits<int, UxmlIntAttributeDescription>
{
}
private class UIntInput : TextValueField<uint>.TextValueInput
{
private UIntField parentUIntField => (UIntField) this.parent;
internal UIntInput() => this.formatString = ClientSimUINumericFieldsUtils.k_ByteFieldFormatString;
protected override string allowedCharacters => ClientSimUINumericFieldsUtils.k_AllowedCharactersForByte;
public override void ApplyInputDeviceDelta(Vector3 delta, DeltaSpeed speed, uint startValue)
{
double intDragSensitivity = (double) ClientSimNumericFieldDraggerUtility.CalculateIntDragSensitivity((long) startValue);
float acceleration = ClientSimNumericFieldDraggerUtility.Acceleration(speed == DeltaSpeed.Fast, speed == DeltaSpeed.Slow);
long num = (long) this.StringToValue(this.text) + (long) Math.Round((double) ClientSimNumericFieldDraggerUtility.NiceDelta((Vector2) delta, acceleration) * intDragSensitivity);
if (this.parentUIntField.isDelayed)
this.text = this.ValueToString((uint)Mathf.Clamp(num,uint.MinValue,uint.MaxValue));
else
this.parentUIntField.value = (uint)Mathf.Clamp(num,uint.MinValue,uint.MaxValue);
}
protected override string ValueToString(uint v) => v.ToString(this.formatString);
protected override uint StringToValue(string str)
{
uint num;
ClientSimUINumericFieldsUtils.TryConvertStringToUInt(str, this.text, out num);
return num;
}
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d60bebe1b61e4fec9775a266a41b8ea9
timeCreated: 1716966716

View File

@ -0,0 +1,150 @@
using System;
using System.Globalization;
using UnityEngine;
using UnityEngine.UIElements;
namespace VRC.SDK3.ClientSim.Editor.VisualElements.Fields
{
public class ULongField : TextValueField<ulong>
{
/// <summary>
/// <para>
/// USS class name of elements of this type.
/// </para>
/// </summary>
public new static readonly string ussClassName = "vrc-ulong-field";
/// <summary>
/// <para>
/// USS class name of labels in elements of this type.
/// </para>
/// </summary>
public new static readonly string labelUssClassName = ULongField.ussClassName + "__label";
/// <summary>
/// <para>
/// USS class name of input elements in elements of this type.
/// </para>
/// </summary>
public new static readonly string inputUssClassName = ULongField.ussClassName + "__input";
private ULongField.ULongInput sbyteInput => (ULongField.ULongInput) this.textInputBase;
/// <summary>
/// <para>
/// Converts the given integer to a string.
/// </para>
/// </summary>
/// <param name="v">The integer to be converted to string.</param>
/// <returns>
/// <para>The integer as string.</para>
/// </returns>
protected override string ValueToString(ulong v) => v.ToString(this.formatString, (IFormatProvider) CultureInfo.InvariantCulture.NumberFormat);
/// <summary>
/// <para>
/// Converts a string to an integer.
/// </para>
/// </summary>
/// <param name="str">The string to convert.</param>
/// <returns>
/// <para>The integer parsed from the string.</para>
/// </returns>
protected override ulong StringToValue(string str)
{
ulong num;
return ClientSimUINumericFieldsUtils.TryConvertStringToULong(str, this.textInputBase.text, out num) ? num : this.rawValue;
}
/// <summary>
/// <para>
/// Constructor.
/// </para>
/// </summary>
public ULongField()
: this((string) null)
{
}
/// <summary>
/// <para>
/// Constructor.
/// </para>
/// </summary>
/// <param name="maxLength">Maximum number of characters the field can take.</param>
public ULongField(int maxLength)
: this((string) null, maxLength)
{
}
/// <summary>
/// <para>
/// Constructor.
/// </para>
/// </summary>
/// <param name="maxLength">Maximum number of characters the field can take.</param>
/// <param name="label"></param>
public ULongField(string label, int maxLength = -1)
: base(label, maxLength, (TextValueField<ulong>.TextValueInput) new ULongField.ULongInput())
{
this.AddToClassList(UIntField.ussClassName);
this.labelElement.AddToClassList(UIntField.labelUssClassName);
this.AddLabelDragger<ulong>();
}
/// <summary>
/// <para>
/// Applies the values of a 3D delta and a speed from an input device.
/// </para>
/// </summary>
/// <param name="delta">A vector used to compute the value change.</param>
/// <param name="speed">A multiplier for the value change.</param>
/// <param name="startValue">The start value.</param>
public override void ApplyInputDeviceDelta(Vector3 delta, DeltaSpeed speed, ulong startValue) => this.sbyteInput.ApplyInputDeviceDelta(delta, speed, startValue);
/// <summary>
/// <para>
/// Instantiates an IntegerField using the data read from a UXML file.
/// </para>
/// </summary>
public new class UxmlFactory : UnityEngine.UIElements.UxmlFactory<ULongField, ULongField.UxmlTraits>
{
}
/// <summary>
/// <para>
/// Defines UxmlTraits for the IntegerField.
/// </para>
/// </summary>
public new class UxmlTraits : TextValueFieldTraits<int, UxmlIntAttributeDescription>
{
}
private class ULongInput : TextValueField<ulong>.TextValueInput
{
private ULongField parentULongField => (ULongField) this.parent;
internal ULongInput() => this.formatString = ClientSimUINumericFieldsUtils.k_ByteFieldFormatString;
protected override string allowedCharacters => ClientSimUINumericFieldsUtils.k_AllowedCharactersForByte;
public override void ApplyInputDeviceDelta(Vector3 delta, DeltaSpeed speed, ulong startValue)
{
double intDragSensitivity = (double) ClientSimNumericFieldDraggerUtility.CalculateIntDragSensitivity((long) startValue);
float acceleration = ClientSimNumericFieldDraggerUtility.Acceleration(speed == DeltaSpeed.Fast, speed == DeltaSpeed.Slow);
long num = (long) this.StringToValue(this.text) + (long) Math.Round((double) ClientSimNumericFieldDraggerUtility.NiceDelta((Vector2) delta, acceleration) * intDragSensitivity);
if (this.parentULongField.isDelayed)
this.text = this.ValueToString((uint)Mathf.Clamp(num,uint.MinValue,uint.MaxValue));
else
this.parentULongField.value = (uint)Mathf.Clamp(num,uint.MinValue,uint.MaxValue);
}
protected override string ValueToString(ulong v) => v.ToString(this.formatString);
protected override ulong StringToValue(string str)
{
ulong num;
ClientSimUINumericFieldsUtils.TryConvertStringToULong(str, this.text, out num);
return num;
}
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e4558ecaaa6441868c8be3649d1222b4
timeCreated: 1716968548

View File

@ -0,0 +1,150 @@
using System;
using System.Globalization;
using UnityEngine;
using UnityEngine.UIElements;
namespace VRC.SDK3.ClientSim.Editor.VisualElements.Fields
{
public class UShortField : TextValueField<ushort>
{
/// <summary>
/// <para>
/// USS class name of elements of this type.
/// </para>
/// </summary>
public new static readonly string ussClassName = "vrc-ushort-field";
/// <summary>
/// <para>
/// USS class name of labels in elements of this type.
/// </para>
/// </summary>
public new static readonly string labelUssClassName = UShortField.ussClassName + "__label";
/// <summary>
/// <para>
/// USS class name of input elements in elements of this type.
/// </para>
/// </summary>
public new static readonly string inputUssClassName = UShortField.ussClassName + "__input";
private UShortField.UShortInput ushortInput => (UShortField.UShortInput) this.textInputBase;
/// <summary>
/// <para>
/// Converts the given integer to a string.
/// </para>
/// </summary>
/// <param name="v">The integer to be converted to string.</param>
/// <returns>
/// <para>The integer as string.</para>
/// </returns>
protected override string ValueToString(ushort v) => v.ToString(this.formatString, (IFormatProvider) CultureInfo.InvariantCulture.NumberFormat);
/// <summary>
/// <para>
/// Converts a string to an integer.
/// </para>
/// </summary>
/// <param name="str">The string to convert.</param>
/// <returns>
/// <para>The integer parsed from the string.</para>
/// </returns>
protected override ushort StringToValue(string str)
{
ushort num;
return ClientSimUINumericFieldsUtils.TryConvertStringToUShort(str, this.textInputBase.text, out num) ? num : this.rawValue;
}
/// <summary>
/// <para>
/// Constructor.
/// </para>
/// </summary>
public UShortField()
: this((string) null)
{
}
/// <summary>
/// <para>
/// Constructor.
/// </para>
/// </summary>
/// <param name="maxLength">Maximum number of characters the field can take.</param>
public UShortField(int maxLength)
: this((string) null, maxLength)
{
}
/// <summary>
/// <para>
/// Constructor.
/// </para>
/// </summary>
/// <param name="maxLength">Maximum number of characters the field can take.</param>
/// <param name="label"></param>
public UShortField(string label, int maxLength = -1)
: base(label, maxLength, (TextValueField<ushort>.TextValueInput) new UShortField.UShortInput())
{
this.AddToClassList(UShortField.ussClassName);
this.labelElement.AddToClassList(UShortField.labelUssClassName);
this.AddLabelDragger<ushort>();
}
/// <summary>
/// <para>
/// Applies the values of a 3D delta and a speed from an input device.
/// </para>
/// </summary>
/// <param name="delta">A vector used to compute the value change.</param>
/// <param name="speed">A multiplier for the value change.</param>
/// <param name="startValue">The start value.</param>
public override void ApplyInputDeviceDelta(Vector3 delta, DeltaSpeed speed, ushort startValue) => this.ushortInput.ApplyInputDeviceDelta(delta, speed, startValue);
/// <summary>
/// <para>
/// Instantiates an IntegerField using the data read from a UXML file.
/// </para>
/// </summary>
public new class UxmlFactory : UnityEngine.UIElements.UxmlFactory<UShortField, UShortField.UxmlTraits>
{
}
/// <summary>
/// <para>
/// Defines UxmlTraits for the IntegerField.
/// </para>
/// </summary>
public new class UxmlTraits : TextValueFieldTraits<int, UxmlIntAttributeDescription>
{
}
private class UShortInput : TextValueField<ushort>.TextValueInput
{
private UShortField parentByteField => (UShortField) this.parent;
internal UShortInput() => this.formatString = ClientSimUINumericFieldsUtils.k_ByteFieldFormatString;
protected override string allowedCharacters => ClientSimUINumericFieldsUtils.k_AllowedCharactersForByte;
public override void ApplyInputDeviceDelta(Vector3 delta, DeltaSpeed speed, ushort startValue)
{
double intDragSensitivity = (double) ClientSimNumericFieldDraggerUtility.CalculateIntDragSensitivity((long) startValue);
float acceleration = ClientSimNumericFieldDraggerUtility.Acceleration(speed == DeltaSpeed.Fast, speed == DeltaSpeed.Slow);
long num = (long) this.StringToValue(this.text) + (long) Math.Round((double) ClientSimNumericFieldDraggerUtility.NiceDelta((Vector2) delta, acceleration) * intDragSensitivity);
if (this.parentByteField.isDelayed)
this.text = this.ValueToString((ushort)Mathf.Clamp(num,0,255));
else
this.parentByteField.value = (ushort)Mathf.Clamp(num,0,255);
}
protected override string ValueToString(ushort v) => v.ToString(this.formatString);
protected override ushort StringToValue(string str)
{
ushort num;
ClientSimUINumericFieldsUtils.TryConvertStringToUShort(str, this.text, out num);
return num;
}
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2134bc1ca6ec4053bcfecd5650b4efdf
timeCreated: 1717422039