Adaug proiectul Unity

This commit is contained in:
2026-11-01 23:39:55 +02:00
parent cb14d9d37d
commit 863eac8f2c
23463 changed files with 5412601 additions and 0 deletions
@@ -0,0 +1,27 @@
using UnityEngine.Rendering;
namespace UnityEditor.Rendering.Utilities
{
/// <summary>
/// Editor MaterialQuality utility class.
/// </summary>
public static class EditorMaterialQualityUtilities
{
/// <summary>
/// Get the material quality levels enabled in a keyword set.
/// </summary>
/// <param name="keywordSet">Input keywords.</param>
/// <returns>All available MaterialQuality levels in the keyword set.</returns>
public static MaterialQuality GetMaterialQuality(this ShaderKeywordSet keywordSet)
{
var result = (MaterialQuality)0;
for (var i = 0; i < MaterialQualityUtilities.Keywords.Length; ++i)
{
if (keywordSet.IsEnabled(MaterialQualityUtilities.Keywords[i]))
result |= (MaterialQuality)(1 << i);
}
return result;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2475d4ff1fb90a64c828b1e6f47e671e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,65 @@
using System.Collections.Generic;
using UnityEditorInternal;
using UnityEditor.EditorTools;
using UnityEngine;
using Object = UnityEngine.Object;
using System.Runtime.CompilerServices;
using UnityEditor;
[assembly: InternalsVisibleTo("Unity.RenderPipelines.Universal.Editor")]
[assembly: InternalsVisibleTo("Unity.RenderPipelines.HighDefinition.Editor")]
namespace UnityEditor.Rendering.Utilities
{
class GenericEditorTool<T> : EditorTool where T : Component
{
readonly string m_Description;
readonly EditMode.SceneViewEditMode m_Mode;
readonly string m_IconName;
GUIContent m_IconContent;
protected GenericEditorTool(string description, EditMode.SceneViewEditMode mode, string iconName)
{
m_Description = description;
m_Mode = mode;
m_IconName = iconName;
}
public override GUIContent toolbarIcon => m_IconContent;
public override void OnWillBeDeactivated() => EditMode.SetEditModeToNone();
public override void OnToolGUI(EditorWindow window)
{
if (EditMode.editMode == m_Mode)
return;
List<T> usefulTargets = new();
foreach (Object thisTarget in targets)
if (thisTarget is T usefulTarget)
usefulTargets.Add(usefulTarget);
if (usefulTargets.Count == 0)
return;
Bounds bounds = GetBoundsOfTargets(usefulTargets);
EditMode.ChangeEditMode(m_Mode, bounds);
ToolManager.SetActiveTool(this);
}
private static Bounds GetBoundsOfTargets(IEnumerable<T> targets)
{
var bounds = new Bounds { min = Vector3.positiveInfinity, max = Vector3.negativeInfinity };
foreach (T t in targets)
bounds.Encapsulate(t.transform.position);
return bounds;
}
private void OnEnable() => m_IconContent = EditorGUIUtility.TrIconContent(m_IconName, m_Description);
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 78d06e068976749e285dd70a52d49c80
@@ -0,0 +1,47 @@
using System;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace UnityEditor.Rendering.Utilities
{
// Temporary helper class duplicated from GraphicsSettingsUtils.cs while better UXML localization support is not available.
internal class LocalizationHelper
{
static void Localize(VisualElement visualElement, Func<VisualElement, string> get, Action<VisualElement, string> set)
{
var extractedText = get.Invoke(visualElement);
if (string.IsNullOrWhiteSpace(extractedText))
return;
var localizedString = L10n.Tr(extractedText);
set.Invoke(visualElement, localizedString);
}
internal static void LocalizeTooltip(VisualElement visualElement)
{
Localize(visualElement, e => e.tooltip, (e, s) => e.tooltip = s);
}
internal static void LocalizeText(Label label)
{
Localize(label, e => ((Label)e).text, (e, s) => ((Label)e).text = s);
}
internal static void LocalizePropertyField(PropertyField propertyField)
{
Localize(propertyField, e => ((PropertyField)e).label, (e, s) => ((PropertyField)e).label = s);
}
internal static void LocalizeVisualTree(VisualElement root)
{
root.Query<VisualElement>().ForEach(LocalizeTooltip);
root.Query<PropertyField>().ForEach(LocalizePropertyField);
root.Query<Label>().ForEach(label =>
{
if (label.ClassListContains("unity-object-field-display__label"))
return;
LocalizeText(label);
});
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: be7a7d4a589240ca90e5fa75520baf83
timeCreated: 1686638124
@@ -0,0 +1,22 @@
using UnityEngine.Rendering;
using UnityEngine.UIElements;
using UnityEditor.UIElements;
namespace UnityEditor.Rendering
{
[CustomEditor(typeof(SceneRenderPipeline))]
class SceneRenderPipelineEditor : Editor
{
public override VisualElement CreateInspectorGUI()
{
var root = new VisualElement();
root.Add(new HelpBox("This script is <b>Editor Only</b>.\nIt <b>modifies the project configuration</b> when this scene is opened.\nUse it with caution.", HelpBoxMessageType.Warning));
var rpAssetProperty = serializedObject.FindProperty("renderPipelineAsset");
var rpAssetField = new PropertyField(rpAssetProperty);
rpAssetField.RegisterValueChangeCallback(evt => GraphicsSettings.defaultRenderPipeline = rpAssetProperty.objectReferenceValue as RenderPipelineAsset);
root.Add(rpAssetField);
return root;
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: c0fcf015f898cd845a455f44ee9b00bb
timeCreated: 1504094117
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,251 @@
using System;
namespace UnityEditor.Rendering
{
/// <summary>Serialisation of BitArray, Utility class</summary>
public static partial class SerializedBitArrayUtilities
{
/// <summary>Construct a SerializedBitArrayAny of appropriate size</summary>
/// <param name="serializedProperty">The SerializedProperty</param>
/// <param name="targetSerializedObjects">An individual SerializedObject for each targetObject</param>
/// <returns>A SerializedBitArrayAny</returns>
public static SerializedBitArrayAny ToSerializedBitArray(this SerializedProperty serializedProperty, SerializedObject[] targetSerializedObjects)
{
if (!TryGetCapacityFromTypeName(serializedProperty, out uint capacity))
throw new Exception("Cannot get SerializeBitArray's Capacity");
return new SerializedBitArrayAny(serializedProperty, targetSerializedObjects, capacity);
}
/// <summary>Construct a SerializedBitArrayAny of appropriate size</summary>
/// <param name="serializedProperty">The SerializedProperty</param>
/// <returns>A SerializedBitArrayAny</returns>
/// <remarks>Note that this variant doesn't properly support editing multiple targets, especially if there
/// are several BitArrays on the target objects.</remarks>
public static SerializedBitArrayAny ToSerializedBitArray(this SerializedProperty serializedProperty)
{
if (!TryGetCapacityFromTypeName(serializedProperty, out uint capacity))
throw new Exception("Cannot get SerializeBitArray's Capacity");
return new SerializedBitArrayAny(serializedProperty, capacity);
}
/// <summary>Try to construct a SerializedBitArray of appropriate size</summary>
/// <param name="serializedProperty">The SerializedProperty</param>
/// <param name="targetSerializedObjects">An individual SerializedObject for each targetObject</param>
/// <param name="serializedBitArray">Out SerializedBitArray</param>
/// <returns>True if construction was successful</returns>
public static bool TryGetSerializedBitArray(this SerializedProperty serializedProperty, SerializedObject[] targetSerializedObjects, out SerializedBitArrayAny serializedBitArray)
{
serializedBitArray = null;
if (!TryGetCapacityFromTypeName(serializedProperty, out uint capacity))
return false;
serializedBitArray = new SerializedBitArrayAny(serializedProperty, targetSerializedObjects, capacity);
return true;
}
/// <summary>Try to construct a SerializedBitArray of appropriate size</summary>
/// <param name="serializedProperty">The SerializedProperty</param>
/// <param name="serializedBitArray">Out SerializedBitArray</param>
/// <returns>True if construction was successful</returns>
/// <remarks>Note that this variant doesn't properly support editing multiple targets, especially if there
/// are several BitArrays on the target objects.</remarks>
public static bool TryGetSerializedBitArray(this SerializedProperty serializedProperty, out SerializedBitArrayAny serializedBitArray)
{
serializedBitArray = null;
if (!TryGetCapacityFromTypeName(serializedProperty, out uint capacity))
return false;
serializedBitArray = new SerializedBitArrayAny(serializedProperty, capacity);
return true;
}
static bool TryGetCapacityFromTypeName(SerializedProperty serializedProperty, out uint capacity)
{
capacity = 0u;
const string baseTypeName = "BitArray";
string type = serializedProperty.type;
return type.StartsWith(baseTypeName)
&& uint.TryParse(type.Substring(baseTypeName.Length), out capacity);
}
}
/// <summary>interface to handle generic SerializedBitArray</summary>
public interface ISerializedBitArray
{
/// <summary>Capacity of the bitarray</summary>
uint capacity { get; }
/// <summary>Get the bit at given index</summary>
/// <param name="bitIndex">The index</param>
/// <returns>Bit value</returns>
bool GetBitAt(uint bitIndex);
/// <summary>Set the bit at given index</summary>
/// <param name="bitIndex">The index</param>
/// <param name="value">The value</param>
void SetBitAt(uint bitIndex, bool value);
/// <summary>Does the bit at given index have multiple different values?</summary>
/// <param name="bitIndex">The index</param>
/// <returns>True: Multiple different value</returns>
bool HasBitMultipleDifferentValue(uint bitIndex);
}
/// <summary>Base class for SerializedBitArrays</summary>
public sealed class SerializedBitArrayAny : ISerializedBitArray
{
//To only be used for bit isolation as internal operator only support 32 bit formats.
//Why:
// - We cannot access easily the root of the BitArray from the target (most of the time there is a non null serialization path to take)
// - The BitArray is a struct making any reflection process to access it difficult especially if we want to modify a bit and not just read (potential copy issue)
// - We are in Editor only here so we can use Unity serialization to do this access, using a bunch of SerializedProperty. We just need to keep them in sync.
// - For the bit isolation:
// - If we want to isolate and only work on 1 bit, we want to modify it, whatever the data was in other bits.
// - If the data on other bits was different per targets beffore writting on 1 bit, it should still be different per targets.
// - Internal method HasMultipleDifferentValuesBitwise and SetBitAtIndexForAllTargetsImmediate is only supported for 32bits formats.
//Todo: Ideally, if we move this BitArray to Unity, we can rewrite a little the HasMultipleDifferentValuesBitwise and SetBitAtIndexForAllTargetsImmediate to work on other format and thus we should not need this m_SerializedPropertyPerTargets anymore.
SerializedProperty[] m_SerializedPropertyPerTargets;
/// <summary>Capacity of the bitarray</summary>
public uint capacity { get; }
internal SerializedBitArrayAny(SerializedProperty serializedProperty, SerializedObject[] targetSerializedObjects, uint capacity)
{
this.capacity = capacity;
m_SerializedPropertyPerTargets = new SerializedProperty[targetSerializedObjects.Length];
for (int i = 0; i < targetSerializedObjects.Length; i++)
{
m_SerializedPropertyPerTargets[i] = targetSerializedObjects[i].FindProperty(serializedProperty.propertyPath);
}
}
// Old constructor that doesn't properly work with multiple target objects.
internal SerializedBitArrayAny(SerializedProperty serializedProperty, uint capacity)
{
this.capacity = capacity;
m_SerializedPropertyPerTargets = new SerializedProperty[serializedProperty.serializedObject.targetObjects.Length];
for (int i = 0; i < serializedProperty.serializedObject.targetObjects.Length; i++)
{
m_SerializedPropertyPerTargets[i] = new SerializedObject(serializedProperty.serializedObject.targetObjects[i]).FindProperty(serializedProperty.propertyPath);
}
}
//To update if we need container over 256bits
ulong GetTargetValueUnverified(int targetIndex, int part)
=> part switch
{
0 => Unbox(m_SerializedPropertyPerTargets[targetIndex].FindPropertyRelative(capacity <= 64 ? "data" : "data1").boxedValue),
1 => Unbox(m_SerializedPropertyPerTargets[targetIndex].FindPropertyRelative("data2")?.boxedValue ?? 0ul),
2 => Unbox(m_SerializedPropertyPerTargets[targetIndex].FindPropertyRelative("data3")?.boxedValue ?? 0ul),
3 => Unbox(m_SerializedPropertyPerTargets[targetIndex].FindPropertyRelative("data4")?.boxedValue ?? 0ul),
_ => 0ul
};
void SetTargetValueUnverified(int targetIndex, int part, object value)
{
switch (part)
{
case 0: m_SerializedPropertyPerTargets[targetIndex].FindPropertyRelative(capacity <= 64 ? "data" : "data1").boxedValue = value; break;
case 1: m_SerializedPropertyPerTargets[targetIndex].FindPropertyRelative("data2").boxedValue = value; break;
case 2: m_SerializedPropertyPerTargets[targetIndex].FindPropertyRelative("data3").boxedValue = value; break;
case 3: m_SerializedPropertyPerTargets[targetIndex].FindPropertyRelative("data4").boxedValue = value; break;
};
}
//we cannot directly cast from boxed value to the ulong we want in C#, We first need to unbox in the true type
ulong Unbox(object boxedValue)
=> capacity switch
{
8 => (byte)boxedValue,
16 => (ushort)boxedValue,
32 => (uint)boxedValue,
64 => (ulong)boxedValue,
_ => (ulong)boxedValue //any higher is a composition of ulong
};
bool ExtractBitFrom64BitsPart(ulong part, uint bitIndexInPart)
=> (part & (1ul << (int) (bitIndexInPart % 64))) != 0;
void AssertInRange(uint bitIndex)
{
if (bitIndex >= capacity)
throw new IndexOutOfRangeException("Index out of bound in BitArray" + capacity);
}
/// <summary>Does the bit at given index have multiple different values?</summary>
/// <param name="partIndex">The index of the 64bits bucket to check</param>
/// <returns>Bitwise discrepancy over 64 bits. If 1 : multiple different value for this bit.</returns>
ulong HasBitMultipleDifferentValueBitwiseOver64Bits(int partIndex)
{
ulong diff = 0ul;
var firstValue = GetTargetValueUnverified(0, partIndex);
for (int i = 1; i < m_SerializedPropertyPerTargets.Length; ++i)
diff |= firstValue ^ GetTargetValueUnverified(i, partIndex);
return diff;
}
/// <summary>Does the bit at given index have multiple different values</summary>
/// <param name="bitIndex">The index</param>
/// <returns>True: Multiple different value for the given bit index</returns>
public bool HasBitMultipleDifferentValue(uint bitIndex)
{
AssertInRange(bitIndex);
return ExtractBitFrom64BitsPart(HasBitMultipleDifferentValueBitwiseOver64Bits((int)bitIndex / 64), bitIndex % 64);
}
/// <summary>Get the bit at given index</summary>
/// <param name="bitIndex">The index</param>
/// <returns>Bit value</returns>
public bool GetBitAt(uint bitIndex)
{
AssertInRange(bitIndex);
if (HasBitMultipleDifferentValue(bitIndex))
return default; //we cannot assess anything if different
//As no different value on this bit, lets use the one from first target
return ExtractBitFrom64BitsPart(GetTargetValueUnverified(0, (int)bitIndex / 64), bitIndex % 64);
}
/// <summary>Set the bit at given index</summary>
/// <param name="bitIndex">The index</param>
/// <param name="value">The value</param>
public void SetBitAt(uint bitIndex, bool value)
{
// Update the serialized object to make sure we have the latest values.
Update();
AssertInRange(bitIndex);
int part = (int)bitIndex / 64;
int indexInPart = (int)bitIndex % 64;
for (int i = 0; i < m_SerializedPropertyPerTargets.Length; ++i)
{
ulong targetValue = GetTargetValueUnverified(i, part);
if (value)
targetValue |= 1ul << indexInPart;
else
targetValue &= ~(1ul << indexInPart);
SetTargetValueUnverified(i, part, targetValue);
}
ResyncSerialization();
}
/// <summary>Sync again every serializedProperty</summary>
void ResyncSerialization()
{
ApplyModifiedProperties();
Update();
}
/// <summary>Sync the reflected value with target value change</summary>
public void Update()
{
foreach (var property in m_SerializedPropertyPerTargets)
property.serializedObject.Update();
}
/// <summary>Apply the reflected value onto targets</summary>
public void ApplyModifiedProperties()
{
foreach (var property in m_SerializedPropertyPerTargets)
property.serializedObject.ApplyModifiedProperties();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bd071ec383b774e48b51bd8c4a33000f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,318 @@
using System;
namespace UnityEditor.Rendering
{
public static partial class SerializedBitArrayUtilities
{
/// <summary>Convert to 8bit</summary>
/// <param name="serializedProperty">The SerializedProperty</param>
/// <returns>A SerializedBitArray8</returns>
[Obsolete("Since SerializedBitArray unification, only use SerializedBitArrayAny. #from(23.2)")]
public static SerializedBitArray8 ToSerializeBitArray8(this SerializedProperty serializedProperty) => null;
/// <summary>Try convert to 8bit</summary>
/// <param name="serializedProperty">The SerializedProperty</param>
/// <param name="serializedBitArray">Out SerializedBitArray8</param>
/// <returns>True if convertion was a success</returns>
[Obsolete("Since SerializedBitArray unification, only use SerializedBitArrayAny. #from(23.2)")]
public static bool TryGetSerializeBitArray8(this SerializedProperty serializedProperty, out SerializedBitArray8 serializedBitArray)
{
serializedBitArray = null;
return false;
}
/// <summary>Convert to 16bit</summary>
/// <param name="serializedProperty">The SerializedProperty</param>
/// <returns>A SerializedBitArray16</returns>
[Obsolete("Since SerializedBitArray unification, only use SerializedBitArrayAny. #from(23.2)")]
public static SerializedBitArray16 ToSerializeBitArray16(this SerializedProperty serializedProperty) => null;
/// <summary>Try convert to 16bit</summary>
/// <param name="serializedProperty">The SerializedProperty</param>
/// <param name="serializedBitArray">Out SerializedBitArray16</param>
/// <returns>True if convertion was a success</returns>
[Obsolete("Since SerializedBitArray unification, only use SerializedBitArrayAny. #from(23.2)")]
public static bool TryGetSerializeBitArray16(this SerializedProperty serializedProperty, out SerializedBitArray16 serializedBitArray)
{
serializedBitArray = null;
return false;
}
/// <summary>Convert to 32bit</summary>
/// <param name="serializedProperty">The SerializedProperty</param>
/// <returns>A SerializedBitArray32</returns>
[Obsolete("Since SerializedBitArray unification, only use SerializedBitArrayAny. #from(23.2)")]
public static SerializedBitArray32 ToSerializeBitArray32(this SerializedProperty serializedProperty) => null;
/// <summary>Try convert to 32bit</summary>
/// <param name="serializedProperty">The SerializedProperty</param>
/// <param name="serializedBitArray">Out SerializedBitArray32</param>
/// <returns>True if convertion was a success</returns>
[Obsolete("Since SerializedBitArray unification, only use SerializedBitArrayAny. #from(23.2)")]
public static bool TryGetSerializeBitArray32(this SerializedProperty serializedProperty, out SerializedBitArray32 serializedBitArray)
{
serializedBitArray = null;
return false;
}
/// <summary>Convert to 64bit</summary>
/// <param name="serializedProperty">The SerializedProperty</param>
/// <returns>A SerializedBitArray64</returns>
[Obsolete("Since SerializedBitArray unification, only use SerializedBitArrayAny. #from(23.2)")]
public static SerializedBitArray64 ToSerializeBitArray64(this SerializedProperty serializedProperty) => null;
/// <summary>Try convert to 64bit</summary>
/// <param name="serializedProperty">The SerializedProperty</param>
/// <param name="serializedBitArray">Out SerializedBitArray64</param>
/// <returns>True if convertion was a success</returns>
[Obsolete("Since SerializedBitArray unification, only use SerializedBitArrayAny. #from(23.2)")]
public static bool TryGetSerializeBitArray64(this SerializedProperty serializedProperty, out SerializedBitArray64 serializedBitArray)
{
serializedBitArray = null;
return false;
}
/// <summary>Convert to 128bit</summary>
/// <param name="serializedProperty">The SerializedProperty</param>
/// <returns>A SerializedBitArray128</returns>
[Obsolete("Since SerializedBitArray unification, only use SerializedBitArrayAny. #from(23.2)")]
public static SerializedBitArray128 ToSerializeBitArray128(this SerializedProperty serializedProperty) => null;
/// <summary>Try convert to 128bit</summary>
/// <param name="serializedProperty">The SerializedProperty</param>
/// <param name="serializedBitArray">Out SerializedBitArray128</param>
/// <returns>True if convertion was a success</returns>
[Obsolete("Since SerializedBitArray unification, only use SerializedBitArrayAny. #from(23.2)")]
public static bool TryGetSerializeBitArray128(this SerializedProperty serializedProperty, out SerializedBitArray128 serializedBitArray)
{
serializedBitArray = null;
return false;
}
/// <summary>Convert to 256bit</summary>
/// <param name="serializedProperty">The SerializedProperty</param>
/// <returns>A SerializedBitArray256</returns>
[Obsolete("Since SerializedBitArray unification, only use SerializedBitArrayAny. #from(23.2)")]
public static SerializedBitArray256 ToSerializeBitArray256(this SerializedProperty serializedProperty) => null;
/// <summary>Try convert to 256bit</summary>
/// <param name="serializedProperty">The SerializedProperty</param>
/// <param name="serializedBitArray">Out SerializedBitArray256</param>
/// <returns>True if convertion was a success</returns>
[Obsolete("Since SerializedBitArray unification, only use SerializedBitArrayAny. #from(23.2)")]
public static bool TryGetSerializeBitArray256(this SerializedProperty serializedProperty, out SerializedBitArray256 serializedBitArray)
{
serializedBitArray = null;
return false;
}
}
/// <summary>Abstract base classe of all SerializedBitArray</summary>
[Obsolete("Since SerializedBitArray unification, only use SerializedBitArrayAny. #from(23.2)")]
public abstract class SerializedBitArray : ISerializedBitArray
{
/// <summary>Capacity of the bitarray</summary>
public uint capacity { get; }
internal SerializedBitArray(SerializedProperty serializedProperty, uint capacity)
{}
/// <summary>Does the bit at given index have multiple different values?</summary>
/// <param name="bitIndex">The index</param>
/// <returns>True: Multiple different value for the given bit index</returns>
public bool HasBitMultipleDifferentValue(uint bitIndex) => default;
/// <summary>Get the bit at given index</summary>
/// <param name="bitIndex">The index</param>
/// <returns>Bit value</returns>
public bool GetBitAt(uint bitIndex) => default;
/// <summary>Set the bit at given index</summary>
/// <param name="bitIndex">The index</param>
/// <param name="value">The value</param>
public void SetBitAt(uint bitIndex, bool value) { }
/// <summary>Sync again every serializedProperty</summary>
protected void ResyncSerialization() { }
/// <summary>Sync the reflected value with target value change</summary>
public void Update() { }
/// <summary>Set the bit at given index</summary>
[Obsolete("Was only working under specific 32 bit mask size. Removed for disambiguisation. Use SetBitAt instead. #from(23.2)")]
protected static Action<SerializedProperty, int, bool> SetBitAtIndexForAllTargetsImmediate = (SerializedProperty sp, int index, bool value) => { };
// Note: this should be exposed at the same time as issue with type other than Int32 is fixed on C++ side
/// <summary>Has multiple differente value bitwise</summary>
[Obsolete("Was only working under specific 32 bit mask size. Removed for disambiguisation. Use HasBitMultipleDifferentValueBitwise_For64BitsOrLess instead. #from(23.2)")]
protected static Func<SerializedProperty, int> HasMultipleDifferentValuesBitwise = (SerializedProperty sp) => 0;
/// <summary>The underlying serialized property</summary>
[Obsolete("As it is required to discompose per target to isolate works per bit, this cannot be used when there is multiple selection. #from(23.2)")]
protected SerializedProperty m_SerializedProperty;
/// <summary>Initialisation of dedicated SerializedPropertiws</summary>
/// <returns>Arrays of SerializedProperty</returns>
[Obsolete("Use m_SerializedProperty only to prevent desynchronisation between objects #from(23.2)")]
protected SerializedProperty[] GetOrInitializeSerializedProperties()
=> new SerializedProperty[] { };
/// <summary>Say if the properties have differente values</summary>
/// <param name="bitIndex">The index</param>
/// <returns>True: properties have different value</returns>
[Obsolete("Replaced by an autocasting to 64 bit buckets for all IBitArray. Now difference computation is not implementation specific anymore #from(23.2)")]
virtual protected bool HasBitMultipleDifferentValue_Internal(uint bitIndex) => HasBitMultipleDifferentValue(bitIndex);
/// <summary>
/// Safety: serializedProperty must match its path
/// </summary>
/// <param name="propertyPath">serializedProperty must match its path</param>
/// <param name="serializedProperty">serializedProperty must match its path</param>
/// <param name="bitIndex">The index of the bit to be checked.</param>
/// <returns>True if the bit has multiple different values; otherwise, false.</returns>
[Obsolete("Replaced by HasBitMultipleDifferentValue that now works for all IBitArray implementations. #from(23.2)")]
unsafe protected bool HasBitMultipleDifferentValue_For64Bits(string propertyPath, SerializedProperty serializedProperty, uint bitIndex)
=> HasBitMultipleDifferentValue(bitIndex);
/// <summary>Get the value at index</summary>
/// <param name="bitIndex">The index</param>
/// <returns>Value at the index</returns>
[Obsolete("Replaced by GetBitAt that now works for all IBitArray implementations. #from(23.2)")]
virtual protected bool GetBitAt_Internal(uint bitIndex) => GetBitAt(bitIndex);
/// <summary>Set the bit at given index</summary>
/// <param name="bitIndex">The index</param>
/// <param name="value">The value</param>
[Obsolete("Replaced by SetBitAt that now works for all IBitArray implementations. #from(23.2)")]
virtual protected void SetBitAt_Internal(uint bitIndex, bool value) => SetBitAt(bitIndex, value);
/// <summary>
/// Update all the targets at specific bit index only
/// </summary>
/// <param name="serializedProperty">The serializedProperty to update</param>
/// <param name="bitIndex">Index to assign the value</param>
/// <param name="value">Boolean value that the bit should be updated to</param>
[Obsolete("Replaced by SetBitAt that now works for all IBitArray implementations. #from(23.2)")]
protected void SetBitAt_For64Bits(SerializedProperty serializedProperty, uint bitIndex, bool value)
=> SetBitAtIndexForAllTargetsImmediate(serializedProperty, (int)bitIndex, value);
}
/// <summary>SerializedBitArray spetialized for 8bit capacity</summary>
[Obsolete("Since SerializedBitArray unification, only use SerializedBitArrayAny. #from(23.2)")]
public sealed class SerializedBitArray8 : SerializedBitArray
{
/// <inheritdoc cref="SerializedBitArray"/>
public SerializedBitArray8(SerializedProperty serializedProperty, uint capacity) : base(serializedProperty, capacity) { }
/// <inheritdoc/>
[Obsolete]
protected override bool GetBitAt_Internal(uint bitIndex) => default;
/// <inheritdoc/>
[Obsolete]
protected override bool HasBitMultipleDifferentValue_Internal(uint bitIndex) => default;
/// <inheritdoc/>
[Obsolete]
protected override void SetBitAt_Internal(uint bitIndex, bool value) { }
}
/// <summary>SerializedBitArray spetialized for 8bit capacity</summary>
[Obsolete("Since SerializedBitArray unification, only use SerializedBitArrayAny. #from(23.2)")]
public sealed class SerializedBitArray16 : SerializedBitArray
{
/// <inheritdoc cref="SerializedBitArray"/>
public SerializedBitArray16(SerializedProperty serializedProperty, uint capacity) : base(serializedProperty, capacity) { }
/// <inheritdoc/>
[Obsolete]
protected override bool GetBitAt_Internal(uint bitIndex) => default;
/// <inheritdoc/>
[Obsolete]
protected override bool HasBitMultipleDifferentValue_Internal(uint bitIndex) => default;
/// <inheritdoc/>
[Obsolete]
protected override void SetBitAt_Internal(uint bitIndex, bool value) { }
}
/// <summary>SerializedBitArray spetialized for 8bit capacity</summary>
[Obsolete("Since SerializedBitArray unification, only use SerializedBitArrayAny. #from(23.2)")]
public sealed class SerializedBitArray32 : SerializedBitArray
{
/// <inheritdoc cref="SerializedBitArray"/>
public SerializedBitArray32(SerializedProperty serializedProperty, uint capacity) : base(serializedProperty, capacity) { }
/// <inheritdoc/>
[Obsolete]
protected override bool GetBitAt_Internal(uint bitIndex) => default;
/// <inheritdoc/>
[Obsolete]
protected override bool HasBitMultipleDifferentValue_Internal(uint bitIndex) => default;
/// <inheritdoc/>
[Obsolete]
protected override void SetBitAt_Internal(uint bitIndex, bool value) { }
}
/// <summary>SerializedBitArray spetialized for 8bit capacity</summary>
[Obsolete("Since SerializedBitArray unification, only use SerializedBitArrayAny. #from(23.2)")]
public sealed class SerializedBitArray64 : SerializedBitArray
{
/// <inheritdoc cref="SerializedBitArray"/>
public SerializedBitArray64(SerializedProperty serializedProperty, uint capacity) : base(serializedProperty, capacity) { }
/// <inheritdoc/>
[Obsolete]
protected override bool GetBitAt_Internal(uint bitIndex) => default;
/// <inheritdoc/>
[Obsolete]
protected override bool HasBitMultipleDifferentValue_Internal(uint bitIndex) => default;
/// <inheritdoc/>
[Obsolete]
protected override void SetBitAt_Internal(uint bitIndex, bool value) { }
}
/// <summary>SerializedBitArray spetialized for 8bit capacity</summary>
[Obsolete("Since SerializedBitArray unification, only use SerializedBitArrayAny. #from(23.2)")]
public sealed class SerializedBitArray128 : SerializedBitArray
{
/// <inheritdoc cref="SerializedBitArray"/>
public SerializedBitArray128(SerializedProperty serializedProperty, uint capacity) : base(serializedProperty, capacity) { }
/// <inheritdoc/>
[Obsolete]
protected override bool GetBitAt_Internal(uint bitIndex) => default;
/// <inheritdoc/>
[Obsolete]
protected override bool HasBitMultipleDifferentValue_Internal(uint bitIndex) => default;
/// <inheritdoc/>
[Obsolete]
protected override void SetBitAt_Internal(uint bitIndex, bool value) { }
}
/// <summary>SerializedBitArray spetialized for 8bit capacity</summary>
[Obsolete("Since SerializedBitArray unification, only use SerializedBitArrayAny. #from(23.2)")]
public sealed class SerializedBitArray256 : SerializedBitArray
{
/// <inheritdoc cref="SerializedBitArray"/>
public SerializedBitArray256(SerializedProperty serializedProperty, uint capacity) : base(serializedProperty, capacity) { }
/// <inheritdoc/>
[Obsolete]
protected override bool GetBitAt_Internal(uint bitIndex) => default;
/// <inheritdoc/>
[Obsolete]
protected override bool HasBitMultipleDifferentValue_Internal(uint bitIndex) => default;
/// <inheritdoc/>
[Obsolete]
protected override void SetBitAt_Internal(uint bitIndex, bool value) { }
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6ad0ab18133a3b54ebaba4af2b423f17
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,64 @@
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using Unity.Collections.LowLevel.Unsafe;
namespace UnityEditor.Rendering
{
/// <summary>
/// Allows time measurements
/// </summary>
/// <example>
/// double duration = 0;
/// using (TimedScope.FromPtr(&amp;duration))
/// {
/// // something to get the time
/// }
/// Debug.Log($"Duration: {duration}")
/// </example>
public unsafe struct TimedScope : IDisposable
{
static readonly ThreadLocal<Stopwatch> s_StopWatch = new ThreadLocal<Stopwatch>(() => new Stopwatch());
double* m_DurationMsPtr;
TimedScope(double* durationMsPtr)
{
m_DurationMsPtr = durationMsPtr;
s_StopWatch.Value.Start();
}
/// <summary>
/// Dispose method to retrieve the time
/// </summary>
void IDisposable.Dispose()
{
s_StopWatch.Value.Stop();
*m_DurationMsPtr = s_StopWatch.Value.Elapsed.TotalMilliseconds;
s_StopWatch.Value.Reset();
}
/// <summary>
/// Obtains a <see cref="TimedScope"/>.
///
/// Safety: <paramref name="durationMsPtr"/> must be a non-null pointer to a valid memory location for a double.
/// </summary>
/// <param name="durationMsPtr">The location to write the duration in milliseconds to.</param>
/// <returns>A <see cref="TimedScope"/></returns>
public static unsafe TimedScope FromPtr([DisallowNull] double* durationMsPtr)
{
return new TimedScope(durationMsPtr);
}
/// <summary>
/// Obtains a <see cref="TimedScope"/>
/// </summary>
/// <param name="durationMs">The location to write the duration in milliseconds to.</param>
/// <returns>A <see cref="TimedScope"/></returns>
public static TimedScope FromRef(ref double durationMs)
{
return new TimedScope((double*)UnsafeUtility.AddressOf(ref durationMs));
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a93fadbee2eb1eb4d96832313dda4a94
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,126 @@
using System;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor.Rendering
{
// Utility class for adding search filtering functionality to UITK views.
// Provides text highlighting, search input throttling, and common search operations.
class UIElementSearchFilter
{
internal const string k_SelectionColorBeginTag = "<mark=#3169ACAB>";
internal const string k_SelectionColorEndTag = "</mark>";
const int k_SearchStringLimit = 32;
IVisualElementScheduledItem m_PreviousSearch;
string m_PendingSearchString;
readonly VisualElement m_RootElement;
readonly Action<string> m_PerformSearchCallback;
public UIElementSearchFilter(VisualElement rootElement, Action<string> performSearchCallback)
{
m_RootElement = rootElement;
m_PerformSearchCallback = performSearchCallback;
}
public void InitializeSearchField(string searchFieldName)
{
var searchField = m_RootElement.Q<ToolbarSearchField>(searchFieldName);
searchField.placeholderText = L10n.Tr("Search");
searchField.Q<TextField>().maxLength = k_SearchStringLimit;
searchField.RegisterValueChangedCallback(evt => OnSearchFilterChanged(evt.newValue));
// Apply empty search once in case the entire window was reloaded with a non-empty search. Search
// modifies the UI document directly, and its state is not reset when triggering the Reload Window option.
OnSearchFilterChanged(string.Empty);
}
void OnSearchFilterChanged(string searchString)
{
// Sanitize to not match rich text tags
searchString = searchString.Replace("<", string.Empty).Replace(">", string.Empty);
// If the search string hasn't changed, avoid repeating the same search
if (m_PendingSearchString == searchString)
return;
m_PendingSearchString = searchString;
if (m_PreviousSearch != null && m_PreviousSearch.isActive)
m_PreviousSearch.Pause();
m_PreviousSearch = m_RootElement
.schedule
.Execute(() => m_PerformSearchCallback(searchString))
.StartingIn(5); // Avoid spamming multiple search if the user types really fast
}
static bool IsInsideTag(string input, int index)
{
int openTagIndex = input.LastIndexOf('<', index);
int closeTagIndex = input.LastIndexOf('>', index);
return openTagIndex > closeTagIndex;
}
static bool IsSearchFilterMatch(string str, string searchString, out int startIndex, out int endIndex)
{
startIndex = -1;
endIndex = -1;
if (searchString.Length == 0)
return true;
int searchStartIndex = 0;
for (;;)
{
startIndex = str.IndexOf(searchString, searchStartIndex, StringComparison.CurrentCultureIgnoreCase);
// If we found a match but it is inside another tag, ignore it and continue
if (startIndex != -1 && IsInsideTag(str, startIndex))
{
searchStartIndex = startIndex + 1;
continue;
}
// Either valid match (not inside another tag) or no match
break;
}
if (startIndex == -1)
return false;
endIndex = startIndex + searchString.Length - 1;
return true;
}
public static void ApplySearchAndHighlight(TextElement textElement, string searchString, out bool isMatch)
{
var text = textElement.text;
// Remove existing match highlight tags
var hasHighlight = text.IndexOf(k_SelectionColorBeginTag, StringComparison.Ordinal) >= 0;
if (hasHighlight)
{
text = text.Replace(k_SelectionColorBeginTag, string.Empty);
text = text.Replace(k_SelectionColorEndTag, string.Empty);
}
if (!IsSearchFilterMatch(text, searchString, out int startHighlight, out int endHighlight))
{
// Reset original text
textElement.text = text;
isMatch = false;
return;
}
if (startHighlight >= 0 && endHighlight >= 0)
{
text = text.Insert(startHighlight, k_SelectionColorBeginTag);
text = text.Insert(endHighlight + k_SelectionColorBeginTag.Length + 1, k_SelectionColorEndTag);
}
textElement.text = text;
isMatch = true;
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 5b5f2f0a59748ee45bd932de0ff19731