Skip to content

Commit 9709d6d

Browse files
iTris666GitHub Enterprise
authored andcommitted
Use the AssetDatabase.FindAsset to find VFXResources asset (#48)
* Use the AssetDatabase.FindAsset to find VFXResources asset * Update CHANGELOG.md * Search VFXResource only if necessary. * LoadUserResourcesIfNeeded * Fix changelog merge
1 parent c23e884 commit 9709d6d

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

com.unity.visualeffectgraph/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
130130
- Make VisualEffect created from the GameObject menu have unique names [Case 1262989](https://issuetracker.unity3d.com/product/unity/issues/guid/1262989/)
131131
- Missing System Seed in new dynamic built-in operator.
132132
- Prefab highlight missing for initial event name toggle [Case 1263012](https://issuetracker.unity3d.com/product/unity/issues/guid/1263012/)
133+
- fixes the user created vfx default resources that were ignored unless loaded
133134
- fix crash when creating a loop in subgraph operators [Case 1251523](https://issuetracker.unity3d.com/product/unity/issues/guid/1251523/)
134135

135136
## [7.1.1] - 2019-09-05

com.unity.visualeffectgraph/Editor/Utils/VFXResources.cs

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,34 @@ public static Values defaultResources
1919
return s_Values;
2020
}
2121
}
22+
private static bool m_Searched; // the instance has been searched and it is null
2223
private static VFXResources s_Instance;
2324
private static Values s_Values;
2425

26+
static void LoadUserResourcesIfNeeded()
27+
{
28+
if (s_Instance == null && (!m_Searched || !object.ReferenceEquals(s_Instance,null)))
29+
// if instance is null and either it has never been searched or it was found but it has been destroyed since last time
30+
{
31+
foreach (var guid in AssetDatabase.FindAssets("t:VFXResources"))
32+
{
33+
s_Instance = AssetDatabase.LoadAssetAtPath<VFXResources>(AssetDatabase.GUIDToAssetPath(guid));
34+
if (s_Instance != null)
35+
{
36+
return;
37+
}
38+
}
39+
s_Instance = null;
40+
m_Searched = true;
41+
}
42+
}
43+
2544
void OnEnable()
2645
{
27-
if (Resources.FindObjectsOfTypeAll<VFXResources>().Length > 1)
46+
if (AssetDatabase.FindAssets("t:VFXResources").Length > 1)
2847
Debug.LogError("Having more than on VFXResources in you project is unsupported");
2948
s_Instance = this;
49+
m_Searched = false;
3050
}
3151

3252
public class Values
@@ -35,8 +55,7 @@ public AnimationCurve animationCurve
3555
{
3656
get
3757
{
38-
if (s_Instance == null)
39-
s_Instance = FindObjectOfType<VFXResources>();
58+
LoadUserResourcesIfNeeded();
4059
if (s_Instance != null)
4160
return s_Instance.animationCurve;
4261

@@ -47,8 +66,7 @@ public Gradient gradient
4766
{
4867
get
4968
{
50-
if (s_Instance == null)
51-
s_Instance = FindObjectOfType<VFXResources>();
69+
LoadUserResourcesIfNeeded();
5270
if (s_Instance != null)
5371
return s_Instance.gradient;
5472
return defaultGradient;
@@ -58,8 +76,7 @@ public Gradient gradientMapRamp
5876
{
5977
get
6078
{
61-
if (s_Instance == null)
62-
s_Instance = FindObjectOfType<VFXResources>();
79+
LoadUserResourcesIfNeeded();
6380
if (s_Instance != null)
6481
return s_Instance.gradientMapRamp;
6582
return defaultGradientMapRamp;
@@ -70,8 +87,7 @@ public Shader shader
7087
{
7188
get
7289
{
73-
if (s_Instance == null)
74-
s_Instance = FindObjectOfType<VFXResources>();
90+
LoadUserResourcesIfNeeded();
7591
if (s_Instance != null && s_Instance.shader != null)
7692
return s_Instance.shader;
7793

@@ -84,8 +100,7 @@ public Texture2D particleTexture
84100
{
85101
get
86102
{
87-
if (s_Instance == null)
88-
s_Instance = FindObjectOfType<VFXResources>();
103+
LoadUserResourcesIfNeeded();
89104
if (s_Instance != null && s_Instance.particleTexture != null)
90105
return s_Instance.particleTexture;
91106
return defaultParticleTexture;
@@ -96,8 +111,7 @@ public Texture2D noiseTexture
96111
{
97112
get
98113
{
99-
if (s_Instance == null)
100-
s_Instance = FindObjectOfType<VFXResources>();
114+
LoadUserResourcesIfNeeded();
101115
if (s_Instance != null && s_Instance.noiseTexture != null)
102116
return s_Instance.noiseTexture;
103117
return defaultNoiseTexture;
@@ -107,8 +121,7 @@ public Texture3D vectorField
107121
{
108122
get
109123
{
110-
if (s_Instance == null)
111-
s_Instance = FindObjectOfType<VFXResources>();
124+
LoadUserResourcesIfNeeded();
112125
if (s_Instance != null && s_Instance.vectorField != null)
113126
return s_Instance.vectorField;
114127
return defaultVectorField;
@@ -118,8 +131,7 @@ public Texture3D signedDistanceField
118131
{
119132
get
120133
{
121-
if (s_Instance == null)
122-
s_Instance = FindObjectOfType<VFXResources>();
134+
LoadUserResourcesIfNeeded();
123135
if (s_Instance != null && s_Instance.signedDistanceField != null)
124136
return s_Instance.signedDistanceField;
125137
return defaultSignedDistanceField;
@@ -130,8 +142,7 @@ public Mesh mesh
130142
{
131143
get
132144
{
133-
if (s_Instance == null)
134-
s_Instance = FindObjectOfType<VFXResources>();
145+
LoadUserResourcesIfNeeded();
135146
if (s_Instance != null && s_Instance.mesh != null)
136147
return s_Instance.mesh;
137148

0 commit comments

Comments
 (0)