init
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
namespace Test.Util
|
||||
{
|
||||
public static class DebugLogUtil
|
||||
{
|
||||
public static string Hyperlink(string filePath) => $"<a href=\"{filePath}\">{filePath}</a>";
|
||||
public static string Hyperlink(string filePath, string displayText) => $"<a href=\"{filePath}\">{displayText}</a>";
|
||||
public static string Hyperlink(string filePath, int line) => Hyperlink($"{filePath}:{line}");
|
||||
public static string Hyperlink(string filePath, int line, string displayText) => Hyperlink($"{filePath}:{line}", displayText);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 60368f49656d495d96b4593c08a51172
|
||||
timeCreated: 1673988980
|
||||
@@ -0,0 +1,51 @@
|
||||
#nullable enable
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Test.Util
|
||||
{
|
||||
public static class SerializedUtil
|
||||
{
|
||||
public static T? GetProperty<T>(Object obj, string propertyPath)
|
||||
{
|
||||
var serializedObject = new SerializedObject(obj);
|
||||
var serializedProperty = serializedObject.FindProperty(propertyPath);
|
||||
|
||||
if (serializedProperty is null)
|
||||
throw new UnityException($"Given propertyPath '{propertyPath}' is invalid!");
|
||||
|
||||
var serializedPropertyValue = serializedProperty.boxedValue;
|
||||
|
||||
if (serializedPropertyValue is null)
|
||||
return default;
|
||||
|
||||
if (serializedPropertyValue is not T value)
|
||||
throw new UnityException($"Value of serialized property '{propertyPath}' is not equal to '{nameof(T)}'!");
|
||||
|
||||
return value;
|
||||
}
|
||||
public static T[] GetPropertyArray<T>(Object obj, string propertyPath)
|
||||
{
|
||||
|
||||
var serializedObject = new SerializedObject(obj);
|
||||
var serializedPropertyArray = serializedObject.FindProperty(propertyPath);
|
||||
|
||||
if (serializedPropertyArray is null)
|
||||
throw new UnityException($"Given propertyPath '{propertyPath}' is invalid!");
|
||||
|
||||
if (!serializedPropertyArray.isArray)
|
||||
throw new UnityException($"Given propertyPath '{propertyPath}' does not contain array!");
|
||||
|
||||
var array = new T[serializedPropertyArray.arraySize];
|
||||
for (var i = 0; i < serializedPropertyArray.arraySize; i++)
|
||||
{
|
||||
var value = serializedPropertyArray.GetArrayElementAtIndex(i).objectReferenceValue;
|
||||
if (value is not T valueT)
|
||||
throw new UnityException($"At least one of values of serialized property array '{propertyPath}' is not equal to '{nameof(T)}'!");
|
||||
array[i] = valueT;
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 90d515b20e1343da800343892bc156f7
|
||||
timeCreated: 1674063463
|
||||
Reference in New Issue
Block a user