File tree Expand file tree Collapse file tree
Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22using System ;
33using System . Reflection ;
44using UnityEditor ;
5+ using UnityEngine ;
56
67namespace MackySoft . SerializeReferenceExtensions . Editor {
78 public static class ManagedReferenceUtility {
89
910 public static object SetManagedReference ( this SerializedProperty property , Type type ) {
10- object obj = ( type != null ) ? Activator . CreateInstance ( type ) : null ;
11- property . managedReferenceValue = obj ;
12- return obj ;
11+ object result ;
12+ if ( property . managedReferenceValue != null )
13+ {
14+ // Restore an previous values from json.
15+ string json = JsonUtility . ToJson ( property . managedReferenceValue ) ;
16+ result = JsonUtility . FromJson ( json , type ) ;
17+ }
18+ else
19+ {
20+ result = ( type != null ) ? Activator . CreateInstance ( type ) : null ;
21+ }
22+
23+ property . managedReferenceValue = result ;
24+ return result ;
25+
1326 }
1427
1528 public static Type GetType ( string typeName ) {
You can’t perform that action at this time.
0 commit comments