Skip to content

Commit 936442c

Browse files
Added Unity Test Project
1 parent 9c8d10e commit 936442c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+5150
-0
lines changed

Unity_Test_Project/.gitignore

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# This .gitignore file should be placed at the root of your Unity project directory
2+
#
3+
# Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore
4+
#
5+
/[Ll]ibrary/
6+
/[Tt]emp/
7+
/[Oo]bj/
8+
/[Bb]uild/
9+
/[Bb]uilds/
10+
/[Ll]ogs/
11+
/[Mm]emoryCaptures/
12+
/More_Examples/
13+
/Assets/Samples/
14+
/Assets/StreamingAssets/
15+
16+
# Asset meta data should only be ignored when the corresponding asset is also ignored
17+
!/[Aa]ssets/**/*.meta
18+
19+
# Uncomment this line if you wish to ignore the asset store tools plugin
20+
# /[Aa]ssets/AssetStoreTools*
21+
22+
# Autogenerated Jetbrains Rider plugin
23+
[Aa]ssets/Plugins/Editor/JetBrains*
24+
25+
# Visual Studio cache directory
26+
.vs/
27+
28+
# Gradle cache directory
29+
.gradle/
30+
31+
# Autogenerated VS/MD/Consulo solution and project files
32+
ExportedObj/
33+
.consulo/
34+
*.csproj
35+
*.unityproj
36+
*.sln
37+
*.suo
38+
*.tmp
39+
*.user
40+
*.userprefs
41+
*.pidb
42+
*.booproj
43+
*.svd
44+
*.pdb
45+
*.mdb
46+
*.opendb
47+
*.VC.db
48+
49+
# Unity3D generated meta files
50+
*.pidb.meta
51+
*.pdb.meta
52+
*.mdb.meta
53+
54+
# Unity3D generated file on crash reports
55+
sysinfo.txt
56+
57+
# Builds
58+
*.apk
59+
*.unitypackage
60+
61+
# Crashlytics generated file
62+
crashlytics-build.properties
63+

Unity_Test_Project/.vsconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"version": "1.0",
3+
"components": [
4+
"Microsoft.VisualStudio.Workload.ManagedGame"
5+
]
6+
}
Lines changed: 307 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,307 @@
1+
using System.IO;
2+
using UnityEditor;
3+
using UnityEngine;
4+
using Newtonsoft.Json;
5+
using Newtonsoft.Json.Linq;
6+
using System;
7+
using UnityEngine.SceneManagement;
8+
using UnityEditor.SceneManagement;
9+
using BuildingVolumes.Streaming;
10+
using UnityEngine.Playables;
11+
using UnityEditor.Timeline.Actions;
12+
using UnityEngine.Timeline;
13+
using System.Collections.Generic;
14+
using System.Linq;
15+
16+
public class BumpUpPackageVersionAndCopySamples : EditorWindow
17+
{
18+
string pathToPackage = "C:\\Dev\\Volcapture\\Unity_Geometry_Sequence_Streaming\\Unity_Geometry_Sequence_Streaming\\Geometry_Sequence_Streaming_Package";
19+
20+
string pathToPackageJSON = "";
21+
string pathToSamplesPackageFolder = "";
22+
23+
string currentVersion = "";
24+
string packageJSONContent;
25+
int newMajor;
26+
int newMinor;
27+
int newPatch;
28+
29+
[MenuItem("UGGS Package/Increment package version")]
30+
static void Init()
31+
{
32+
BumpUpPackageVersionAndCopySamples window = GetWindow<BumpUpPackageVersionAndCopySamples>();
33+
window.titleContent = new GUIContent("Change package versioning");
34+
window.ShowPopup();
35+
}
36+
37+
private void CreateGUI()
38+
{
39+
pathToPackageJSON = Path.Combine(pathToPackage, "package.json");
40+
pathToSamplesPackageFolder = Path.Combine(pathToPackage, "Samples~\\StreamingSamples\\");
41+
42+
GetCurrentPackageVersion();
43+
44+
if (!Directory.Exists(pathToPackage) || !File.Exists(pathToPackageJSON))
45+
{
46+
EditorGUILayout.LabelField("Package path is not valid, please change in script", EditorStyles.boldLabel);
47+
GUILayout.Space(70);
48+
if (GUILayout.Button("Ok!")) this.Close();
49+
return;
50+
}
51+
52+
53+
}
54+
55+
void OnGUI()
56+
{
57+
EditorGUILayout.LabelField("Current package version is: " + currentVersion, EditorStyles.wordWrappedLabel);
58+
GUILayout.Space(20);
59+
EditorGUILayout.LabelField("Change version to:", EditorStyles.wordWrappedLabel);
60+
GUILayout.BeginHorizontal();
61+
newMajor = EditorGUILayout.IntField(newMajor);
62+
newMinor = EditorGUILayout.IntField(newMinor);
63+
newPatch = EditorGUILayout.IntField(newPatch);
64+
GUILayout.EndHorizontal();
65+
66+
string newVersion = newMajor + "." + newMinor + "." + newPatch;
67+
68+
if (GUILayout.Button("Change Version"))
69+
{
70+
UpdatePackageJSONAndSave(pathToPackageJSON, packageJSONContent, newVersion);
71+
UpdateSamples(currentVersion, newVersion);
72+
GetCurrentPackageVersion();
73+
EditorUtility.SetDirty(this);
74+
}
75+
76+
}
77+
78+
void GetCurrentPackageVersion()
79+
{
80+
packageJSONContent = File.ReadAllText(pathToPackageJSON);
81+
82+
JObject o = JObject.Parse(packageJSONContent);
83+
84+
JToken version = o.GetValue("version");
85+
currentVersion = version.Value<string>();
86+
string[] versionValues = currentVersion.Split('.');
87+
int major = Int32.Parse(versionValues[0]);
88+
int minor = Int32.Parse(versionValues[1]);
89+
int patch = Int32.Parse(versionValues[2]);
90+
91+
newMajor = major;
92+
newMinor = minor;
93+
newPatch = patch;
94+
}
95+
96+
void UpdatePackageJSONAndSave(string pathToJson, string jsonContent, string newVersion)
97+
{
98+
JObject obj = JObject.Parse(jsonContent);
99+
obj["version"] = newVersion;
100+
101+
try
102+
{
103+
File.WriteAllText(pathToJson, obj.ToString());
104+
}
105+
106+
catch
107+
{
108+
Debug.LogError("Could not update package JSON!");
109+
return;
110+
}
111+
112+
Debug.Log("Changed JSON package version to " + newVersion);
113+
114+
}
115+
116+
void UpdateSamples(string currentVersion, string newVersion)
117+
{
118+
119+
string pathToSamplesRootFolder = "Assets\\Samples\\Geometry Sequence Streaming\\";
120+
string pathToSamplesFolder = pathToSamplesRootFolder + currentVersion + "\\Streaming Samples\\";
121+
string pathToNewSamplesFolder = pathToSamplesRootFolder + newVersion + "\\Streaming Samples\\";
122+
string pathToScene1 = pathToSamplesFolder + "01_Basic_Example.unity";
123+
string pathToScene2 = pathToSamplesFolder + "02_Timeline_Example.unity";
124+
string pathToScene3 = pathToSamplesFolder + "03_API_Example.unity";
125+
string emptyScene = "Assets\\EmptyScene.unity";
126+
127+
string pathToNewSampleData = "Samples\\Geometry Sequence Streaming\\" + newVersion + "\\Streaming Samples\\ExampleData\\Twisty_Box";
128+
129+
UpdateSample1(pathToScene1, pathToNewSampleData);
130+
UpdateSample2(pathToScene2, pathToNewSampleData);
131+
UpdateSample3(pathToScene3, pathToNewSampleData);
132+
RenameSamplePath(pathToSamplesRootFolder + currentVersion, pathToSamplesRootFolder + newVersion);
133+
EditorSceneManager.OpenScene(emptyScene, OpenSceneMode.Single);
134+
CopySamples(pathToNewSamplesFolder, pathToSamplesPackageFolder);
135+
}
136+
137+
bool UpdateSample1(string pathToScene, string pathToNewSampleData)
138+
{
139+
//Basic Sample
140+
try
141+
{
142+
EditorSceneManager.OpenScene(pathToScene, OpenSceneMode.Single);
143+
}
144+
145+
catch
146+
{
147+
Debug.LogError("Could not load sample scene 1!");
148+
return false;
149+
}
150+
151+
GeometrySequencePlayer player = (GeometrySequencePlayer)FindObjectOfType<GeometrySequencePlayer>();
152+
if (player.GetRelativeSequencePath() == null)
153+
{
154+
Debug.LogError("Could not finde path in Sample 1!");
155+
return false;
156+
}
157+
158+
player.SetPath(pathToNewSampleData, GeometrySequenceStream.PathType.RelativeToDataPath);
159+
EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene());
160+
return true;
161+
}
162+
163+
bool UpdateSample2(string pathToScene, string pathToNewSampleData)
164+
{
165+
//Timeline Sample
166+
try
167+
{
168+
EditorSceneManager.OpenScene(pathToScene, OpenSceneMode.Single);
169+
}
170+
171+
catch
172+
{
173+
Debug.LogError("Could not load sample scene 2!");
174+
return false;
175+
}
176+
177+
178+
PlayableDirector director = (PlayableDirector)FindObjectOfType<PlayableDirector>();
179+
PlayableAsset playable = director.playableAsset;
180+
TimelineAsset timeline = (TimelineAsset)playable;
181+
IEnumerable<TimelineClip> clips = timeline.GetRootTrack(1).GetClips();
182+
183+
184+
185+
foreach (TimelineClip clip in clips)
186+
{
187+
188+
GeometrySequenceClip geoClip = (GeometrySequenceClip)clip.asset;
189+
190+
if (geoClip.relativePath == null)
191+
{
192+
Debug.LogError("Could not finde path in timeline on Sample 2!");
193+
return false;
194+
}
195+
196+
geoClip.relativePath = pathToNewSampleData;
197+
198+
}
199+
200+
EditorUtility.SetDirty(timeline);
201+
EditorUtility.SetDirty(playable);
202+
AssetDatabase.SaveAssets();
203+
EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene());
204+
return true;
205+
}
206+
207+
bool UpdateSample3(string pathToScene, string pathToNewSampleData)
208+
{
209+
//API Sample
210+
try
211+
{
212+
EditorSceneManager.OpenScene(pathToScene, OpenSceneMode.Single);
213+
}
214+
215+
catch
216+
{
217+
Debug.LogError("Could not load sample scene 3!");
218+
return false;
219+
}
220+
221+
GeometrySequenceAPIExample api = (GeometrySequenceAPIExample)FindObjectOfType<GeometrySequenceAPIExample>();
222+
if (api.sequencePath == null)
223+
{
224+
Debug.LogError("Could not find path in Sample 3!");
225+
return false;
226+
}
227+
228+
api.sequencePath = pathToNewSampleData;
229+
EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene());
230+
return true;
231+
}
232+
233+
bool RenameSamplePath(string oldpath, string newpath)
234+
{
235+
if (Directory.Exists(oldpath))
236+
{
237+
if (oldpath == newpath)
238+
return true;
239+
240+
string error = AssetDatabase.MoveAsset(oldpath, newpath);
241+
242+
if (error != "")
243+
{
244+
Debug.LogError("Could not rename sample directory: " + error);
245+
return false;
246+
}
247+
248+
}
249+
250+
else
251+
{
252+
Debug.LogError("Sample directory does not exist");
253+
return false;
254+
}
255+
256+
return true;
257+
}
258+
259+
void CopySamples(string pathToAssetSamples, string pathToPackageSampleFolder)
260+
{
261+
if(!Directory.Exists(pathToAssetSamples) || !Directory.Exists(pathToPackageSampleFolder))
262+
{
263+
Debug.LogError("Could not find " + pathToAssetSamples + " or " + pathToPackageSampleFolder);
264+
return;
265+
}
266+
267+
try
268+
{
269+
CopyDirectory(pathToAssetSamples, pathToPackageSampleFolder, true);
270+
}
271+
272+
catch (Exception e)
273+
{
274+
Debug.LogError(e.ToString());
275+
}
276+
}
277+
278+
static void CopyDirectory(string sourceDir, string destinationDir, bool recursive)
279+
{
280+
Debug.Log("Copying from: " + sourceDir + " to " + destinationDir);
281+
// Get information about the source directory
282+
var dir = new DirectoryInfo(sourceDir);
283+
284+
// Cache directories before we start copying
285+
DirectoryInfo[] dirs = dir.GetDirectories();
286+
287+
// Create the destination directory
288+
Directory.CreateDirectory(destinationDir);
289+
290+
// Get the files in the source directory and copy to the destination directory
291+
foreach (FileInfo file in dir.GetFiles())
292+
{
293+
string targetFilePath = Path.Combine(destinationDir, file.Name);
294+
file.CopyTo(targetFilePath, true);
295+
}
296+
297+
// If recursive and copying subdirectories, recursively call this method
298+
if (recursive)
299+
{
300+
foreach (DirectoryInfo subDir in dirs)
301+
{
302+
string newDestinationDir = Path.Combine(destinationDir, subDir.Name);
303+
CopyDirectory(subDir.FullName, newDestinationDir, true);
304+
}
305+
}
306+
}
307+
}

Unity_Test_Project/Assets/BumpUpPackageVersionAndCopySamples.cs.meta

Lines changed: 11 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)