-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefaultCloudScriptableObjectResolverNested.cs
47 lines (38 loc) · 1.59 KB
/
DefaultCloudScriptableObjectResolverNested.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System.Linq;
using Magix.Editor;
using UnityEngine;
namespace Magix
{
public class DefaultCloudScriptableObjectResolverNested : ICloudScriptableObjectResolver
{
public bool IsNestedResolutionSupported { get => true; }
public object Resolve(CloudScriptableObject scriptableObj)
{
string environmentSearchStr = string.Empty;
#if DEVELOPMENT_BUILD || UNITY_EDITOR
environmentSearchStr = Environment.Development.ToString();
#else
environmentSearchStr = Environment.Production.ToString();
#endif
var duplicateKeyName = CloudScriptableObject.PreloadedCloudResourceJsons.Count(x => x.Key.StartsWith(environmentSearchStr) && x.Key.EndsWith(scriptableObj.name)) > 1;
if (duplicateKeyName)
{
UnityEngine.Debug.LogError("Duplicate key exist on resolving the object, this likely to cause undefined behaviour.");
}
var searchKey = CloudScriptableObject.PreloadedCloudResourceJsons.FirstOrDefault(x => x.Key.StartsWith(environmentSearchStr) && x.Key.EndsWith(scriptableObj.name)).Key;
if (searchKey == null)
{
UnityEngine.Debug.Log("Cannot find entry: " + searchKey);
return null;
}
JsonUtility.FromJsonOverwrite(CloudScriptableObject.PreloadedCloudResourceJsons[searchKey], scriptableObj);
return scriptableObj;
}
#if UNITY_EDITOR
public string GetKeyFromObject(CloudScriptableObject scriptableObj, Environment env)
{
return $"{env}-res-{scriptableObj.name}";
}
#endif
}
}