Skip to content

Commit 7d720be

Browse files
committed
Merge branch 'generic-scriptable-object-improvements'
2 parents 7aeff2e + 1da0763 commit 7d720be

File tree

8 files changed

+85
-8
lines changed

8 files changed

+85
-8
lines changed

Editor/AOTGeneration/AOTAssemblyGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
public static class AOTAssemblyGenerator
2121
{
22-
private const string FolderPath = PackageSettings.PluginsPath + "/AOT Generation";
22+
public const string FolderPath = PackageSettings.PluginsPath + "/AOT Generation";
2323
private const string AssemblyName = "z_ExtEvents_AOTGeneration";
2424

2525
public static IEnumerable<(Type from, Type to, Type emittedConverterType)> EmitImplicitConverters(ModuleBuilder moduleBuilder, Dictionary<(Type from, Type to), Type> customConverters, IEnumerable<(Type from, Type to)> conversions)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace ExtEvents.Editor
2+
{
3+
using UnityEditor;
4+
using UnityEditor.Build;
5+
using UnityEditor.Build.Reporting;
6+
7+
public class BuildPostprocessor : IPostprocessBuildWithReport
8+
{
9+
public int callbackOrder { get; }
10+
11+
public void OnPostprocessBuild(BuildReport report)
12+
{
13+
AssetDatabase.DeleteAsset(AOTAssemblyGenerator.FolderPath);
14+
}
15+
}
16+
}

Editor/AOTGeneration/BuildPostprocessor.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Drawers/PersistentArgumentDrawer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ private void DrawDynamicValue(SerializedProperty property, Rect valueRect)
119119
var argNames = ExtEventDrawer.CurrentEventInfo.ArgNames;
120120
var currentArgName = argNames[indexProp.intValue];
121121

122-
var matchingArgNames = GetMatchingArgNames(argNames, ExtEventDrawer.CurrentEventInfo.ParamTypes, PersistentArgumentHelper.GetTypeFromProperty(property, nameof(PersistentArgument._fromType)));
122+
// fallback field for backwards compatibility where _fromType didn't exist.
123+
var matchingArgNames = GetMatchingArgNames(argNames, ExtEventDrawer.CurrentEventInfo.ParamTypes, PersistentArgumentHelper.GetTypeFromProperty(property, nameof(PersistentArgument._fromType), nameof(PersistentArgument._targetType)));
123124

124125
using (new EditorGUI.DisabledGroupScope(matchingArgNames.Count == 1))
125126
{

Editor/Util/PersistentArgumentHelper.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,22 @@
77

88
public static class PersistentArgumentHelper
99
{
10-
public static Type GetTypeFromProperty(SerializedProperty argProperty, string typeFieldName)
10+
public static Type GetTypeFromProperty(SerializedProperty argProperty, string typeFieldName, string fallbackTypeFieldName = null)
1111
{
12-
var typeNameAndAssembly = argProperty.FindPropertyRelative($"{typeFieldName}.{nameof(TypeReference._typeNameAndAssembly)}").stringValue;
13-
var type = Type.GetType(typeNameAndAssembly);
12+
var type = GetTypeFromPropertyInternal(argProperty, typeFieldName);
13+
14+
if (type == null && fallbackTypeFieldName != null)
15+
{
16+
type = GetTypeFromPropertyInternal(argProperty, fallbackTypeFieldName);
17+
}
18+
1419
return type;
1520
}
21+
22+
private static Type GetTypeFromPropertyInternal(SerializedProperty argProperty, string typeFieldName)
23+
{
24+
var typeNameAndAssembly = argProperty.FindPropertyRelative($"{typeFieldName}.{nameof(TypeReference._typeNameAndAssembly)}").stringValue;
25+
return Type.GetType(typeNameAndAssembly);
26+
}
1627
}
1728
}

OdinSerializer/Core/Misc/CustomSerialization.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ public static void SerializeValueToBinary<T>(T value, out byte[] bytes, out List
104104
bytes = SerializationUtility.SerializeValue(value, DataFormat.Binary, out referencedUnityObjects);
105105
}
106106

107+
public static void SerializeValueToBinaryWeak(object value, out byte[] bytes, out List<UnityEngine.Object> referencedUnityObjects)
108+
{
109+
bytes = SerializationUtility.SerializeValueWeak(value, DataFormat.Binary, out referencedUnityObjects);
110+
}
111+
107112
private static void SerializeValueToBinary(object value, Type valueType, ref SerializationData data)
108113
{
109114
data.Bytes = value == null ? null : SerializationUtility.SerializeValue(value, valueType, DataFormat.Binary, out data.ReferencedUnityObjects);
@@ -189,6 +194,11 @@ public static T DeserializeValue<T>(byte[] bytes, List<UnityEngine.Object> refer
189194
return SerializationUtility.DeserializeValue<T>(bytes, DataFormat.Binary, referencedUnityObjects);
190195
}
191196

197+
public static object DeserializeValue(Type type, byte[] bytes, List<UnityEngine.Object> referencedUnityObjects)
198+
{
199+
return SerializationUtility.DeserializeValue(type, bytes, DataFormat.Binary, referencedUnityObjects);
200+
}
201+
192202
private static DeserializationContext GetCachedContext(out Cache<DeserializationContext> cachedContext)
193203
{
194204
cachedContext = Cache<DeserializationContext>.Claim();

OdinSerializer/Core/Misc/SerializationUtility.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,32 @@ public static byte[] SerializeValue<T>(T value, DataFormat format, out List<Obje
8181
return stream.Value.MemoryStream.ToArray();
8282
}
8383

84+
public static byte[] SerializeValueWeak(object value, DataFormat format, out List<Object> unityObjects, SerializationContext context = null)
85+
{
86+
using var stream = CachedMemoryStream.Claim();
87+
var writer = GetCachedWriter(out IDisposable cache, format, stream.Value.MemoryStream, context);
88+
89+
try
90+
{
91+
if (context != null)
92+
{
93+
SerializeValueWeak(value, writer, out unityObjects);
94+
}
95+
else
96+
{
97+
using var con = Cache<SerializationContext>.Claim();
98+
writer.Context = con;
99+
SerializeValueWeak(value, writer, out unityObjects);
100+
}
101+
}
102+
finally
103+
{
104+
cache.Dispose();
105+
}
106+
107+
return stream.Value.MemoryStream.ToArray();
108+
}
109+
84110
private static void SerializeValue<T>(T value, IDataWriter writer, out List<Object> unityObjects)
85111
{
86112
using var unityResolver = Cache<UnityReferenceResolver>.Claim();
@@ -90,6 +116,16 @@ private static void SerializeValue<T>(T value, IDataWriter writer, out List<Obje
90116
unityObjects = unityResolver.Value.GetReferencedUnityObjects();
91117
}
92118

119+
private static void SerializeValueWeak(object value, IDataWriter writer, out List<Object> unityObjects)
120+
{
121+
using var unityResolver = Cache<UnityReferenceResolver>.Claim();
122+
writer.Context.IndexReferenceResolver = unityResolver.Value;
123+
var valueType = value.GetType();
124+
Serializer.Get(valueType).WriteValueWeak(value, writer);
125+
writer.FlushToStream();
126+
unityObjects = unityResolver.Value.GetReferencedUnityObjects();
127+
}
128+
93129
public static void SerializeValue(object value, Type valueType, IDataWriter writer)
94130
{
95131
Serializer.Get(valueType).WriteValueWeak(value, writer);

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"displayName": "ExtEvents",
55
"description": "UnityEvents, but better.",
66
"dependencies": {
7-
"com.solidalloy.util": "1.39.0",
7+
"com.solidalloy.util": "1.40.0",
88
"com.unity.settings-manager": "1.0.3",
9-
"com.solidalloy.type-references": "2.15.1",
10-
"com.solidalloy.unity-dropdown": "1.1.1"
9+
"com.solidalloy.type-references": "2.16.0",
10+
"com.solidalloy.unity-dropdown": "1.2.0"
1111
},
1212
"keywords": [
1313
"event",

0 commit comments

Comments
 (0)