Skip to content

Commit 88058ae

Browse files
author
Chris Tchou
authored
[2021.2] [ShaderGraph] [bugfix 1301915] Node Include files are now tracked explicitly BY GUID (#3290)
* Node Include files are now tracked explicitly BY GUID, propagated out of subgraphs, and uniquely merged Some care was taken to keep the HDRP "replace placeholder" functionality working properly.. * Adding file move tests * Update Changelog * Fix for VFX when using node-includes
1 parent dc548b1 commit 88058ae

36 files changed

+2385
-129
lines changed
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
using System.Collections;
2+
using NUnit.Framework;
3+
using UnityEditor.Experimental.GraphView;
4+
using UnityEditor.ShaderGraph;
5+
using UnityEditor.ShaderGraph.Drawing;
6+
using System.Reflection;
7+
using UnityEngine;
8+
using UnityEngine.TestTools;
9+
using UnityEngine.UIElements;
10+
using System.IO;
11+
using System.Collections.Generic;
12+
using System.Text.RegularExpressions;
13+
14+
/* Changes:
15+
* Made ShaderGraphImporterEditor.ShowGraphEditWindow public
16+
* Made MaterialGraphEditWindow.graphEditorView public
17+
* Altered MasterPreviewView.OnMouseDragPreviewMesh slightly
18+
*/
19+
20+
namespace UnityEditor.ShaderGraph.UnitTests
21+
{
22+
[TestFixture]
23+
internal class FileMoveTests
24+
{
25+
GraphEditorView m_GraphEditorView;
26+
MaterialGraphEditWindow m_Window;
27+
GraphData m_Graph;
28+
29+
static string sourceDirectoryPath => Application.dataPath + "/../MoveTest";
30+
static string sourceDirectoryPathSub => Application.dataPath + "/../MoveTest/SubFolder";
31+
static string targetDirectoryPath => Application.dataPath + "/Testing/MoveTest";
32+
static string targetDirectoryPath2 => Application.dataPath + "/Testing/MoveTest2";
33+
static string targetDirectoryPathSub => Application.dataPath + "/Testing/MoveTest/SubFolder";
34+
static string targetUnityDirectoryPath => "Assets/Testing/MoveTest";
35+
static string targetUnityDirectoryPath2 => "Assets/Testing/MoveTest2";
36+
37+
[OneTimeSetUp]
38+
public void Setup()
39+
{
40+
// recursive delete
41+
if (Directory.Exists(targetDirectoryPath2))
42+
{
43+
Directory.Delete(targetDirectoryPath2, true);
44+
45+
// sync AssetDatabase
46+
AssetDatabase.DeleteAsset(targetUnityDirectoryPath2);
47+
}
48+
49+
Directory.CreateDirectory(targetDirectoryPath);
50+
Directory.CreateDirectory(targetDirectoryPathSub);
51+
52+
try
53+
{
54+
AssetDatabase.StartAssetEditing();
55+
56+
// copy all files from source directory to target directory
57+
string[] sourceFiles = Directory.GetFiles(sourceDirectoryPath, "*", SearchOption.TopDirectoryOnly);
58+
foreach (var sourceFilePath in sourceFiles)
59+
{
60+
string fileName = Path.GetFileName(sourceFilePath);
61+
File.Copy(sourceFilePath, targetDirectoryPath + "/" + fileName);
62+
}
63+
64+
// copy all files from source directory to target directory
65+
sourceFiles = Directory.GetFiles(sourceDirectoryPathSub, "*", SearchOption.TopDirectoryOnly);
66+
foreach (var sourceFilePath in sourceFiles)
67+
{
68+
string fileName = Path.GetFileName(sourceFilePath);
69+
File.Copy(sourceFilePath, targetDirectoryPathSub + "/" + fileName);
70+
}
71+
}
72+
finally
73+
{
74+
AssetDatabase.StopAssetEditing();
75+
}
76+
77+
// after all files are copied, make sure everything in the directory is imported
78+
AssetDatabase.ImportAsset(targetUnityDirectoryPath, ImportAssetOptions.ImportRecursive);
79+
}
80+
81+
public void OpenGraphWindow(string graphName)
82+
{
83+
// Open up the window
84+
if (!ShaderGraphImporterEditor.ShowGraphEditWindow(graphName))
85+
{
86+
Assert.Fail("ShaderGraphImporterEditor.ShowGraphEditWindow could not open " + graphName);
87+
}
88+
89+
m_Window = EditorWindow.GetWindow<MaterialGraphEditWindow>();
90+
91+
if (m_Window == null)
92+
{
93+
Assert.Fail("Could not open MaterialGraphEditWindow");
94+
}
95+
96+
// EditorWindow.GetWindow will return a new window if one is not found. A new window will have graphObject == null.
97+
if (m_Window.graphObject == null)
98+
{
99+
Assert.Fail("Existing Shader Graph window of " + graphName + " not found.");
100+
}
101+
102+
m_GraphEditorView = m_Window.graphEditorView;
103+
}
104+
105+
[TearDown]
106+
public void CloseGraphWindow()
107+
{
108+
if (m_Window != null)
109+
{
110+
m_Window.graphObject = null; // Don't spawn ask-to-save dialog
111+
m_Window.Close();
112+
}
113+
m_Window = null;
114+
m_GraphEditorView = null;
115+
}
116+
117+
[OneTimeTearDown]
118+
public void Cleanup()
119+
{
120+
try
121+
{
122+
123+
AssetDatabase.StartAssetEditing();
124+
125+
// delete everything from target directory (via assetdatabase to clear anything relevant)
126+
foreach (string assetGuid in AssetDatabase.FindAssets("*", new string[] { targetUnityDirectoryPath }))
127+
{
128+
AssetDatabase.DeleteAsset(AssetDatabase.GUIDToAssetPath(assetGuid));
129+
}
130+
131+
foreach (string assetGuid in AssetDatabase.FindAssets("*", new string[] { targetUnityDirectoryPath2 }))
132+
{
133+
AssetDatabase.DeleteAsset(AssetDatabase.GUIDToAssetPath(assetGuid));
134+
}
135+
136+
FileUtil.DeleteFileOrDirectory(targetDirectoryPath2);
137+
}
138+
finally
139+
{
140+
AssetDatabase.StopAssetEditing();
141+
}
142+
143+
if (Directory.Exists(targetDirectoryPath2))
144+
{
145+
Directory.Delete(targetDirectoryPath2, true);
146+
147+
// sync AssetDatabase
148+
AssetDatabase.DeleteAsset(targetUnityDirectoryPath2);
149+
}
150+
}
151+
152+
// Tests that loading and saving a fully versioned graph file doesn't change the file on disk.
153+
[UnityTest]
154+
public IEnumerator MoveDirectoryTests()
155+
{
156+
yield return null;
157+
158+
// rename the directory
159+
AssetDatabase.MoveAsset(targetUnityDirectoryPath, targetUnityDirectoryPath2);
160+
161+
yield return null;
162+
yield return null;
163+
yield return null;
164+
yield return null;
165+
yield return null;
166+
yield return null;
167+
yield return null;
168+
yield return null;
169+
170+
var graphPath = targetUnityDirectoryPath2 + "/ShaderGraph.shadergraph";
171+
OpenGraphWindow(graphPath);
172+
173+
yield return null;
174+
yield return null;
175+
yield return null;
176+
yield return null;
177+
yield return null;
178+
yield return null;
179+
yield return null;
180+
yield return null;
181+
182+
// try adding the subgraph node -- see if the asset still works after the files have been moved
183+
m_Graph = m_Window.graphObject.graph as GraphData;
184+
var subgraph = AssetDatabase.LoadAssetAtPath<SubGraphAsset>(graphPath);
185+
var node = new SubGraphNode { asset = subgraph };
186+
m_Graph.AddNode(node);
187+
188+
yield return null;
189+
yield return null;
190+
yield return null;
191+
yield return null;
192+
yield return null;
193+
yield return null;
194+
yield return null;
195+
yield return null;
196+
197+
CloseGraphWindow();
198+
}
199+
}
200+
}

com.unity.shadergraph/Editor/Interface/IShaderString.cs.meta renamed to TestProjects/ShaderGraph/Assets/CommonAssets/Editor/FileMoveTests.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!21 &2100000
4+
Material:
5+
serializedVersion: 6
6+
m_ObjectHideFlags: 0
7+
m_CorrespondingSourceObject: {fileID: 0}
8+
m_PrefabInstance: {fileID: 0}
9+
m_PrefabAsset: {fileID: 0}
10+
m_Name: Shader Graphs_ShaderGraph
11+
m_Shader: {fileID: -6465566751694194690, guid: e729d15e0112af8449c81fa47e54974d,
12+
type: 3}
13+
m_ShaderKeywords:
14+
m_LightmapFlags: 4
15+
m_EnableInstancingVariants: 0
16+
m_DoubleSidedGI: 0
17+
m_CustomRenderQueue: -1
18+
stringTagMap: {}
19+
disabledShaderPasses: []
20+
m_SavedProperties:
21+
serializedVersion: 3
22+
m_TexEnvs:
23+
- unity_Lightmaps:
24+
m_Texture: {fileID: 0}
25+
m_Scale: {x: 1, y: 1}
26+
m_Offset: {x: 0, y: 0}
27+
- unity_LightmapsInd:
28+
m_Texture: {fileID: 0}
29+
m_Scale: {x: 1, y: 1}
30+
m_Offset: {x: 0, y: 0}
31+
- unity_ShadowMasks:
32+
m_Texture: {fileID: 0}
33+
m_Scale: {x: 1, y: 1}
34+
m_Offset: {x: 0, y: 0}
35+
m_Ints: []
36+
m_Floats: []
37+
m_Colors: []
38+
m_BuildTextureStacks: []

TestProjects/ShaderGraph/MoveTest/Shader Graphs_ShaderGraph.mat.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)