Skip to content

Commit

Permalink
Merge pull request #47 from mackysoft/fix/compatibility-less-than-2021-3
Browse files Browse the repository at this point in the history
Fix compatibility for less than Unity 2021.3
  • Loading branch information
mackysoft committed Jan 10, 2024
2 parents afb3089 + d061f74 commit f522e0f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#if UNITY_2019_3_OR_NEWER
// NOTE: managedReferenceValue getter is available only in Unity 2021.3 or later.
#if UNITY_2021_3_OR_NEWER
using UnityEditor;
using UnityEngine;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
public static class ManagedReferenceUtility {

public static object SetManagedReference (this SerializedProperty property,Type type) {
object result;
object result = null;

#if UNITY_2021_3_OR_NEWER
// NOTE: managedReferenceValue getter is available only in Unity 2021.3 or later.
if (property.managedReferenceValue != null)
{
// Restore an previous values from json.
string json = JsonUtility.ToJson(property.managedReferenceValue);
result = JsonUtility.FromJson(json, type);
}
else
#endif

if (result == null)
{
result = (type != null) ? Activator.CreateInstance(type) : null;
}
Expand Down

0 comments on commit f522e0f

Please sign in to comment.