Skip to content

Commit e6f57ed

Browse files
authored
Merge pull request #41 from mackysoft/feature/new-object-from-json
Restore values from json on create new managed reference
2 parents cdcbbed + 59da386 commit e6f57ed

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

.github/workflows/package.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@ jobs:
2828

2929
# Build
3030
- name: Build .unitypackage
31-
uses: game-ci/unity-builder@v2
31+
uses: game-ci/unity-builder@v4
32+
env:
33+
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
34+
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
35+
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
3236
with:
33-
unityVersion: 2020.3.8f1
37+
unityVersion: 2021.3.29f1
3438
buildMethod: MackySoft.PackageTools.Editor.UnityPackageExporter.Export
3539

3640
# Upload

Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/ManagedReferenceUtility.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,27 @@
22
using System;
33
using System.Reflection;
44
using UnityEditor;
5+
using UnityEngine;
56

67
namespace 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) {

0 commit comments

Comments
 (0)