Skip to content

Commit

Permalink
fix unity 2019 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
d4rkc0d3r committed Aug 17, 2024
1 parent a24a431 commit 03769cc
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 65 deletions.
8 changes: 4 additions & 4 deletions Editor/ShaderAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2551,15 +2551,15 @@ string TryPoiFurInstanceCountOptimization(ref int lineIndex)
if (source[lineIndex + 4] != "#endif")
return null;
int charIndex = 10;
var line = source[lineIndex + 3];
SkipWhitespace(line, ref charIndex);
string instanceParameter = ShaderAnalyzer.ParseIdentifierAndTrailingWhitespace(line, ref charIndex);
var instanceCountLine = source[lineIndex + 3];
SkipWhitespace(instanceCountLine, ref charIndex);
string instanceParameter = ShaderAnalyzer.ParseIdentifierAndTrailingWhitespace(instanceCountLine, ref charIndex);
if (animatedPropertyValues.ContainsKey(instanceParameter) || arrayPropertyValues.ContainsKey(instanceParameter))
return null;
if (!staticPropertyValues.TryGetValue(instanceParameter, out var instanceValue))
return null;
lineIndex += 4;
return line.Replace(instanceParameter, instanceValue);
return instanceCountLine.Replace(instanceParameter, instanceValue);
}
if (line.Length > 3 && line[1] == 'i' && line[2] == 'f')
{
Expand Down
54 changes: 30 additions & 24 deletions Editor/d4rkAvatarOptimizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2897,12 +2897,13 @@ private HashSet<Transform> FindAllMovingTransforms()
var headChopType = Type.GetType("VRC.SDK3.Avatars.Components.VRCHeadChop, VRCSDK3A");
if (headChopType != null) {
foreach (var headChop in GetComponentsInChildren(headChopType, true)) {
using var so = new SerializedObject(headChop);
var targetBonesProperty = so.FindProperty("targetBones");
for (int i = 0; i < targetBonesProperty.arraySize; i++) {
var targetBone = targetBonesProperty.GetArrayElementAtIndex(i).FindPropertyRelative("transform").objectReferenceValue as Transform;
if (targetBone != null) {
transforms.Add(targetBone);
using (var so = new SerializedObject(headChop)) {
var targetBonesProperty = so.FindProperty("targetBones");
for (int i = 0; i < targetBonesProperty.arraySize; i++) {
var targetBone = targetBonesProperty.GetArrayElementAtIndex(i).FindPropertyRelative("transform").objectReferenceValue as Transform;
if (targetBone != null) {
transforms.Add(targetBone);
}
}
}
}
Expand Down Expand Up @@ -4732,31 +4733,36 @@ public HashSet<string> GetAllExcludedTransformPaths() {

HashSet<Transform> FindReferencedTransforms(Component component)
{
using var serializedObject = new SerializedObject(component);
var visitedIds = new HashSet<long>();
var iterator = serializedObject.GetIterator();
var referencedTransforms = new HashSet<Transform>();
bool enterChildren = true;
while (iterator.Next(enterChildren))
{
enterChildren = true;
if (iterator.propertyType == SerializedPropertyType.ObjectReference && iterator.objectReferenceValue != null)
using (var serializedObject = new SerializedObject(component))
{
var visitedIds = new HashSet<long>();
var iterator = serializedObject.GetIterator();
var referencedTransforms = new HashSet<Transform>();
bool enterChildren = true;
while (iterator.Next(enterChildren))
{
if (iterator.objectReferenceValue is Transform transform)
enterChildren = true;
if (iterator.propertyType == SerializedPropertyType.ObjectReference && iterator.objectReferenceValue != null)
{
referencedTransforms.Add(transform);
if (iterator.objectReferenceValue is Transform transform)
{
referencedTransforms.Add(transform);
}
}
}
else if (iterator.propertyType == SerializedPropertyType.ManagedReference)
{
var id = iterator.managedReferenceId;
if (!visitedIds.Add(id))
else if (iterator.propertyType == SerializedPropertyType.ManagedReference)
{
enterChildren = false;
#if UNITY_2022_1_OR_NEWER
if (!visitedIds.Add(iterator.managedReferenceId))
{
enterChildren = false;
}
#else
enterChildren = false;
#endif
}
}
return referencedTransforms;
}
return referencedTransforms;
}

private void DestroyEditorOnlyGameObjects()
Expand Down
76 changes: 39 additions & 37 deletions Editor/d4rkAvatarOptimizerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1299,59 +1299,61 @@ public void DrawDebugList(string[] array)

private void DynamicTransformList(Object obj, string propertyPath)
{
using var serializedObject = new SerializedObject(obj);
// Find the SerializedProperty representing the list of Transforms
SerializedProperty listProperty = serializedObject.FindProperty(propertyPath);

// Add a null element at the end of the list for the user to add new elements
listProperty.InsertArrayElementAtIndex(listProperty.arraySize);
SerializedProperty newElement = listProperty.GetArrayElementAtIndex(listProperty.arraySize - 1);
newElement.objectReferenceValue = null;

for (int i = 0; i < listProperty.arraySize; i++)
using (var serializedObject = new SerializedObject(obj))
{
SerializedProperty element = listProperty.GetArrayElementAtIndex(i);
Transform output = null;
// Find the SerializedProperty representing the list of Transforms
SerializedProperty listProperty = serializedObject.FindProperty(propertyPath);

// Add a null element at the end of the list for the user to add new elements
listProperty.InsertArrayElementAtIndex(listProperty.arraySize);
SerializedProperty newElement = listProperty.GetArrayElementAtIndex(listProperty.arraySize - 1);
newElement.objectReferenceValue = null;

using (new EditorGUILayout.HorizontalScope())
for (int i = 0; i < listProperty.arraySize; i++)
{
output = EditorGUILayout.ObjectField(element.objectReferenceValue, typeof(Transform), true) as Transform;
SerializedProperty element = listProperty.GetArrayElementAtIndex(i);
Transform output = null;

using (new EditorGUILayout.HorizontalScope())
{
output = EditorGUILayout.ObjectField(element.objectReferenceValue, typeof(Transform), true) as Transform;

if (i == listProperty.arraySize - 1)
{
GUILayout.Space(23);
}
else if (GUILayout.Button("X", GUILayout.Width(20)))
{
output = null;
}
}

if (i == listProperty.arraySize - 1)
if (element.objectReferenceValue != output)
{
GUILayout.Space(23);
ClearUICaches();
}
else if (GUILayout.Button("X", GUILayout.Width(20)))

if (output != null && optimizer.GetTransformPathToRoot(output) == null)
{
output = null;
}
}

if (element.objectReferenceValue != output)
{
ClearUICaches();
element.objectReferenceValue = output;
}

if (output != null && optimizer.GetTransformPathToRoot(output) == null)
// Remove any null elements from the list
for (int i = listProperty.arraySize - 1; i >= 0; i--)
{
output = null;
SerializedProperty element = listProperty.GetArrayElementAtIndex(i);
if (element.objectReferenceValue == null)
{
listProperty.DeleteArrayElementAtIndex(i);
}
}

element.objectReferenceValue = output;
// Apply the modified properties to the serializedObject
serializedObject.ApplyModifiedProperties();
}

// Remove any null elements from the list
for (int i = listProperty.arraySize - 1; i >= 0; i--)
{
SerializedProperty element = listProperty.GetArrayElementAtIndex(i);
if (element.objectReferenceValue == null)
{
listProperty.DeleteArrayElementAtIndex(i);
}
}

// Apply the modified properties to the serializedObject
serializedObject.ApplyModifiedProperties();
}

static Texture _perfIcon_Excellent;
Expand Down

0 comments on commit 03769cc

Please sign in to comment.