diff --git a/Editor/ShaderAnalyzer.cs b/Editor/ShaderAnalyzer.cs index 15cf2f0..0dd2515 100644 --- a/Editor/ShaderAnalyzer.cs +++ b/Editor/ShaderAnalyzer.cs @@ -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') { diff --git a/Editor/d4rkAvatarOptimizer.cs b/Editor/d4rkAvatarOptimizer.cs index f9ad6fe..7e74d21 100644 --- a/Editor/d4rkAvatarOptimizer.cs +++ b/Editor/d4rkAvatarOptimizer.cs @@ -2897,12 +2897,13 @@ private HashSet 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); + } } } } @@ -4732,31 +4733,36 @@ public HashSet GetAllExcludedTransformPaths() { HashSet FindReferencedTransforms(Component component) { - using var serializedObject = new SerializedObject(component); - var visitedIds = new HashSet(); - var iterator = serializedObject.GetIterator(); - var referencedTransforms = new HashSet(); - 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(); + var iterator = serializedObject.GetIterator(); + var referencedTransforms = new HashSet(); + 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() diff --git a/Editor/d4rkAvatarOptimizerEditor.cs b/Editor/d4rkAvatarOptimizerEditor.cs index a68fbba..53033f0 100644 --- a/Editor/d4rkAvatarOptimizerEditor.cs +++ b/Editor/d4rkAvatarOptimizerEditor.cs @@ -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;