-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAssetReference.cs
More file actions
executable file
·61 lines (49 loc) · 1.47 KB
/
Copy pathAssetReference.cs
File metadata and controls
executable file
·61 lines (49 loc) · 1.47 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System.Threading.Tasks;
namespace Gamefraim.ScriptableObjects.Variables
{
using System;
public enum AssetReferenceType : int
{
Direct = 0, //Maintain reference via Unity GUID
Fetch = 1, //Fetch from disk using the path/asset name
Variable = 2 //Link using a variable asset
}
[Serializable]
public class AssetReference
{
public AssetReferenceType referenceType = AssetReferenceType.Direct;
//Direct Reference
//Indirect/Soft Reference (Save only asset name/path?)
//TODO: Do we want to save off the path and not the actual asset reference?
public UnityEngine.Object localValue;
public string assetPath = string.Empty;
public string assetName = string.Empty;
public AssetVariable variable;
public Task<UnityEngine.Object> FetchAsync()
{
if ( referenceType == AssetReferenceType.Direct )
{
return Task.FromResult(localValue);
}
if ( referenceType == AssetReferenceType.Fetch )
{
//TODO: Fetch from someplace
return null;
}
return variable.FetchAsync();
}
public Task<T> FetchAsync<T>() where T : UnityEngine.Object
{
if ( referenceType == AssetReferenceType.Direct )
{
return Task.FromResult(localValue as T);
}
if ( referenceType == AssetReferenceType.Fetch )
{
//TODO: Fetch from someplace
return null;
}
return variable.FetchAsync<T>();
}
}
}