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 UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
|||||||
@ -8,14 +8,19 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
|
|||||||
public static class ManagedReferenceUtility {
|
public static class ManagedReferenceUtility {
|
||||||
|
|
||||||
public static object SetManagedReference (this SerializedProperty property,Type type) {
|
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)
|
if (property.managedReferenceValue != null)
|
||||||
{
|
{
|
||||||
// Restore an previous values from json.
|
// Restore an previous values from json.
|
||||||
string json = JsonUtility.ToJson(property.managedReferenceValue);
|
string json = JsonUtility.ToJson(property.managedReferenceValue);
|
||||||
result = JsonUtility.FromJson(json, type);
|
result = JsonUtility.FromJson(json, type);
|
||||||
}
|
}
|
||||||
else
|
#endif
|
||||||
|
|
||||||
|
if (result == null)
|
||||||
{
|
{
|
||||||
result = (type != null) ? Activator.CreateInstance(type) : null;
|
result = (type != null) ? Activator.CreateInstance(type) : null;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user