Skip to content

Commit 954669e

Browse files
committed
Merge branch 'implicit-conversion'
2 parents 197643f + 0ed9c9e commit 954669e

File tree

7 files changed

+42
-26
lines changed

7 files changed

+42
-26
lines changed

Editor/AOTGeneration/BuildPreprocessor.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@ public void OnPreprocessBuild(BuildReport report)
1919
}
2020

2121
#if UNITY_2021_2_OR_NEWER
22-
switch (EditorUserBuildSettings.il2CppCodeGeneration)
22+
var codeGeneration =
23+
#if UNITY_2022
24+
PlayerSettings.GetIl2CppCodeGeneration(NamedBuildTarget.FromBuildTargetGroup(EditorUserBuildSettings.selectedBuildTargetGroup));
25+
#else
26+
EditorUserBuildSettings.il2CppCodeGeneration;
27+
#endif
28+
29+
switch (codeGeneration)
2330
{
2431
case Il2CppCodeGeneration.OptimizeSpeed:
2532
AOTAssemblyGenerator.GenerateCreateMethods();
@@ -28,7 +35,7 @@ public void OnPreprocessBuild(BuildReport report)
2835
AOTAssemblyGenerator.DeleteGeneratedFolder();
2936
break;
3037
default:
31-
Debug.LogWarning($"Unknown value of IL2CPP Code Generation: {EditorUserBuildSettings.il2CppCodeGeneration}");
38+
Debug.LogWarning($"Unknown value of IL2CPP Code Generation: {codeGeneration}");
3239
break;
3340
}
3441
#else

Editor/Drawers/ExtEventDrawer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using SolidUtilities.Editor;
77
using SolidUtilities.UnityEditorInternals;
88
using UnityEditor;
9-
using UnityEditorInternal;
109
using UnityEngine;
1110
using UnityEngine.Events;
1211

Editor/Drawers/PersistentArgumentDrawer.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public override void OnGUI(Rect fieldRect, SerializedProperty property, GUIConte
5858
EditorGUI.indentLevel = 0;
5959

6060
if (_showChoiceButton)
61-
DrawChoiceButton(buttonRect);
61+
DrawChoiceButton(buttonRect, property);
6262

6363
DrawValue(property, valueRect, fieldRect, previousIndent);
6464

@@ -96,9 +96,13 @@ public static SerializedProperty GetValueProperty(SerializedProperty argumentPro
9696
public static void SaveValueProperty(SerializedProperty argumentProperty, SerializedProperty valueProperty)
9797
{
9898
valueProperty.serializedObject.ApplyModifiedPropertiesWithoutUndo();
99+
LogHelper.RemoveLogEntriesByMode(LogModes.NoScriptAssetWarning);
99100
var value = valueProperty.GetObject();
100101
var serializedArgProp = argumentProperty.FindPropertyRelative(nameof(PersistentArgument._serializedArg));
101102
serializedArgProp.stringValue = PersistentArgument.SerializeValue(value, valueProperty.GetObjectType());
103+
104+
var argument = argumentProperty.GetObject<PersistentArgument>();
105+
argument._initialized = false;
102106
}
103107

104108
private void DrawValue(SerializedProperty property, Rect valueRect, Rect totalRect, int indentLevel)
@@ -271,11 +275,13 @@ private static void DrawValueInFoldout(SerializedProperty mainProperty, Serializ
271275
}
272276
}
273277

274-
private void DrawChoiceButton(Rect buttonRect)
278+
private void DrawChoiceButton(Rect buttonRect, SerializedProperty argumentProperty)
275279
{
276280
if (GUI.Button(buttonRect, _isSerialized.boolValue ? "s" : "d", ButtonStyle))
277281
{
278282
_isSerialized.boolValue = !_isSerialized.boolValue;
283+
var argument = argumentProperty.GetObject<PersistentArgument>();
284+
argument._initialized = false;
279285
}
280286
}
281287
}

Editor/Drawers/PersistentListenerDrawer.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,14 @@ private bool MethodHasChanged(SerializedProperty listenerProperty)
212212

213213
private void DrawComponentDropdown(SerializedProperty listenerProperty, SerializedProperty targetProperty, GameObject gameObject)
214214
{
215-
var components = gameObject.GetComponents<Component>().Where(component => component != null && !component.hideFlags.ContainsFlag(HideFlags.HideInInspector));
216-
var dropdownItems = new List<DropdownItem<Component>>();
215+
var components = gameObject
216+
.GetComponents<Component>()
217+
.Where(component => component != null && !component.hideFlags.ContainsFlag(HideFlags.HideInInspector))
218+
.Prepend<Object>(gameObject);
217219

218-
foreach (Component component in components)
220+
var dropdownItems = new List<DropdownItem<Object>>();
221+
222+
foreach (var component in components)
219223
{
220224
var componentType = component.GetType();
221225
var componentMenu = componentType.GetCustomAttribute<AddComponentMenu>();
@@ -231,10 +235,10 @@ private void DrawComponentDropdown(SerializedProperty listenerProperty, Serializ
231235
componentName = ObjectNames.NicifyVariableName(componentType.Name);
232236
}
233237

234-
dropdownItems.Add(new DropdownItem<Component>(component, componentName, EditorGUIUtility.ObjectContent(component, componentType).image));
238+
dropdownItems.Add(new DropdownItem<Object>(component, componentName, EditorGUIUtility.ObjectContent(component, componentType).image));
235239
}
236240

237-
var tree = new DropdownMenu<Component>(dropdownItems, component =>
241+
var tree = new DropdownMenu<Object>(dropdownItems, component =>
238242
{
239243
targetProperty.objectReferenceValue = component;
240244
targetProperty.serializedObject.ApplyModifiedProperties();

Runtime/EventElements/PersistentArgument.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,9 @@ public class PersistentArgument
3232
[SerializeField] internal bool _canBeDynamic;
3333

3434
private ArgumentHolder _argumentHolder;
35-
private bool _initialized;
3635

37-
private ArgumentHolder GetArgumentHolder(string serializedArg, Type valueType)
38-
{
39-
if (!_initialized)
40-
{
41-
// It's important to assign argumentHolder to a field so that it is not cleaned by GC until we stop using PersistentArgument.
42-
_initialized = true;
43-
var type = typeof(ArgumentHolder<>).MakeGenericType(valueType);
44-
_argumentHolder = (ArgumentHolder) JsonUtility.FromJson(serializedArg, type);
45-
}
46-
47-
return _argumentHolder;
48-
}
36+
// NonSerialized is required here, otherwise Unity will try to serialize the field even though we didn't put SerializeField attribute.
37+
[NonSerialized] internal bool _initialized;
4938

5039
internal unsafe void* SerializedValuePointer
5140
{
@@ -151,5 +140,18 @@ internal static string SerializeValue(object value, Type valueType)
151140
var argHolder = Activator.CreateInstance(argHolderType, value);
152141
return JsonUtility.ToJson(argHolder);
153142
}
143+
144+
private ArgumentHolder GetArgumentHolder(string serializedArg, Type valueType)
145+
{
146+
if (!_initialized)
147+
{
148+
// It's important to assign argumentHolder to a field so that it is not cleaned by GC until we stop using PersistentArgument.
149+
_initialized = true;
150+
var type = typeof(ArgumentHolder<>).MakeGenericType(valueType);
151+
_argumentHolder = (ArgumentHolder) JsonUtility.FromJson(serializedArg, type);
152+
}
153+
154+
return _argumentHolder;
155+
}
154156
}
155157
}

Runtime/EventElements/PersistentListener.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ public partial class PersistentListener
5858

5959
[NonSerialized] internal bool _initializationComplete;
6060
[NonSerialized] private bool _initializationSuccessful;
61-
6261
private unsafe void*[] _arguments;
63-
6462
private BaseInvokableCall _invokableCall;
6563

6664
private PersistentListener() { }

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"displayName": "ExtEvents",
55
"description": "UnityEvents, but better.",
66
"dependencies": {
7-
"com.solidalloy.util": "1.37.1",
7+
"com.solidalloy.util": "1.38.0",
88
"com.unity.settings-manager": "1.0.3",
99
"com.solidalloy.type-references": "2.15.0",
1010
"com.solidalloy.unity-dropdown": "1.1.1"

0 commit comments

Comments
 (0)