Merge pull request #47 from mackysoft/fix/compatibility-less-than-2021-3
Fix compatibility for less than Unity 2021.3
This commit is contained in:
commit
f522e0f285
@ -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;
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user