public IEnumerator CreateAndFindAsset() { const string TEST_ASSETS_ROOT = "Assets/TestRunner"; const string MAT_FOLDER = TEST_ASSETS_ROOT + "/Materials"; const string MAT_NAME = "TestRunnerMaterial"; Directory.CreateDirectory(MAT_FOLDER); string path = AssetDatabase.GenerateUniqueAssetPath($"{MAT_FOLDER}/{MAT_NAME}.mat"); AssetDatabase.CreateAsset(new Material(Shader.Find("Standard")), path); yield return(YieldEditorUtility.WaitForFramesAndIncrementUndo(1)); HashSet <string> paths = AssetEditorUtility.FindAssetPaths("t:material", MAT_NAME); Assert.AreEqual(1, paths.Count); //exact name paths = AssetEditorUtility.FindAssetPaths("t:material", MAT_NAME.Substring(0, MAT_NAME.Length - 3)); Assert.AreEqual(0, paths.Count); paths = AssetEditorUtility.FindAssetPaths("t:material", MAT_NAME, new[] { "Assets" }, shouldSearchSubFolder: true); Assert.AreEqual(1, paths.Count); //exact folder paths = AssetEditorUtility.FindAssetPaths("t:material", MAT_NAME, new[] { "Assets" }, shouldSearchSubFolder: false); Assert.AreEqual(0, paths.Count); yield return(YieldEditorUtility.WaitForFramesAndIncrementUndo(1)); AssetDatabase.DeleteAsset(path); AssetDatabase.DeleteAsset(TEST_ASSETS_ROOT); }
public IEnumerator TearDown() { if (File.Exists(TIMELINE_ASSET_PATH)) { AssetDatabase.DeleteAsset(TIMELINE_ASSET_PATH); } yield return(YieldEditorUtility.WaitForFramesAndIncrementUndo(1)); }
public IEnumerator DetectActiveClip() { PlayableDirector director = CreateDirectorWithTimelineAsset(TIMELINE_ASSET_PATH, out TimelineAsset timelineAsset); TimelineEditorUtility.SelectDirectorInTimelineWindow(director); //trigger the TimelineWindow's update etc. yield return(YieldEditorUtility.WaitForFramesAndIncrementUndo(1)); TrackAsset track = timelineAsset.CreateTrack <DummyTimelineTrack>(null, "FooTrack"); List <TimelineClip> clips = new List <TimelineClip>(); const int NUM_CLIPS = 3; double nextClipStart = 0; for (int i = 0; i < NUM_CLIPS; ++i) { TimelineClip curClip = TimelineEditorReflection.CreateClipOnTrack(typeof(DummyTimelinePlayableAsset), track, 0); curClip.asset.name = $"Clip Asset {i}"; curClip.start = nextClipStart; nextClipStart += curClip.duration; clips.Add(curClip); yield return(YieldEditorUtility.WaitForFramesAndIncrementUndo(1)); } //Check that all clips have been created successfully List <TimelineClip> trackClips = new List <TimelineClip>(track.GetClips()); HashSet <TimelineClip> trackClipsToCheck = new HashSet <TimelineClip>(trackClips); for (int i = 0; i < NUM_CLIPS; ++i) { Assert.IsTrue(trackClipsToCheck.Contains(clips[i])); trackClipsToCheck.Remove(clips[i]); } NUnit.Framework.Assert.Zero(trackClipsToCheck.Count); yield return(YieldEditorUtility.WaitForFramesAndIncrementUndo(3)); //Ensure the active clip can be detected for (int i = 0; i < NUM_CLIPS; ++i) { TimelineClip curClip = clips[i]; double time = curClip.start + curClip.duration * 0.5f; TimelineUtility.GetActiveTimelineClipInto(trackClips, time, out TimelineClip detectedClip, out TimelineAsset _); Assert.AreEqual(curClip, detectedClip); } yield return(YieldEditorUtility.WaitForFramesAndIncrementUndo(1)); TimelineEditorUtility.DestroyAssets(timelineAsset); //Cleanup }
public IEnumerator UndoAndRedoAddElements() { const int NUM_FIRST_ADDITION = 10; List <DummyScriptableObject> dummyObjects = new List <DummyScriptableObject>(); DummySerializedDictionaryComponent comp = new GameObject().AddComponent <DummySerializedDictionaryComponent>(); for (int i = 0; i < NUM_FIRST_ADDITION; ++i) { dummyObjects.Add(CreateDictionaryElement(comp, i)); } yield return(YieldEditorUtility.WaitForFramesAndIncrementUndo(1)); Undo.PerformUndo(); Assert.AreEqual(0, comp.GetNumElements()); yield return(YieldEditorUtility.WaitForFramesAndIncrementUndo(1)); Undo.PerformRedo(); Assert.AreEqual(NUM_FIRST_ADDITION, comp.GetNumElements()); yield return(YieldEditorUtility.WaitForFramesAndIncrementUndo(1)); //Additional const int NUM_SECOND_ADDITION = 3; for (int i = 0; i < NUM_SECOND_ADDITION; ++i) { dummyObjects.Add(CreateDictionaryElement(comp, i)); } yield return(YieldEditorUtility.WaitForFramesAndIncrementUndo(1)); Undo.PerformUndo(); Assert.AreEqual(NUM_FIRST_ADDITION, comp.GetNumElements()); yield return(YieldEditorUtility.WaitForFramesAndIncrementUndo(1)); const int NUM_ALL_ELEMENTS = NUM_FIRST_ADDITION + NUM_SECOND_ADDITION; Undo.PerformRedo(); Assert.AreEqual(NUM_ALL_ELEMENTS, comp.GetNumElements()); yield return(YieldEditorUtility.WaitForFramesAndIncrementUndo(1)); //Destroy for (int i = 0; i < NUM_ALL_ELEMENTS; ++i) { Object.DestroyImmediate(dummyObjects[i]); } yield return(YieldEditorUtility.WaitForFramesAndIncrementUndo(1)); }
public IEnumerator VerifyNullDeserialization() { const string testScenePath = "Assets/TestRunnerScene.unity"; List <DummyScriptableObject> dummyObjects = new List <DummyScriptableObject>(); const int NUM_ELEMENTS_TO_CREATE = 10; const int NUM_ELEMENTS_TO_DELETE = 3; //Create elements, and delete some EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects); DummySerializedDictionaryComponent comp = new GameObject().AddComponent <DummySerializedDictionaryComponent>(); for (int i = 0; i < NUM_ELEMENTS_TO_CREATE; ++i) { dummyObjects.Add(CreateDictionaryElement(comp, i)); } yield return(YieldEditorUtility.WaitForFramesAndIncrementUndo(1)); for (int i = 0; i < NUM_ELEMENTS_TO_DELETE; ++i) { Object.DestroyImmediate(dummyObjects[i]); } yield return(YieldEditorUtility.WaitForFramesAndIncrementUndo(1)); //Save and load EditorSceneManager.SaveScene(SceneManager.GetActiveScene(), testScenePath); EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects); Scene scene = EditorSceneManager.OpenScene(testScenePath); Assert.IsNotNull(scene); yield return(YieldEditorUtility.WaitForFramesAndIncrementUndo(1)); comp = Object.FindObjectOfType <DummySerializedDictionaryComponent>(); Assert.IsNotNull(comp); int expected = NUM_ELEMENTS_TO_CREATE - NUM_ELEMENTS_TO_DELETE; int numElements = comp.GetNumElements(); Assert.AreEqual(expected, numElements, $"Elements are not deserialized correctly. {expected} != {numElements}"); yield return(YieldEditorUtility.WaitForFramesAndIncrementUndo(1)); //Cleanup EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects); EditorSceneManager.CloseScene(scene, true); AssetDatabase.DeleteAsset(testScenePath); }
public IEnumerator CreateClip() { PlayableDirector director = CreateDirectorWithTimelineAsset(TIMELINE_ASSET_PATH, out TimelineAsset timelineAsset); yield return(YieldEditorUtility.WaitForFramesAndIncrementUndo(1)); TimelineClip clip = TimelineEditorUtility.CreateTrackAndClip <DummyTimelineTrack, DummyTimelinePlayableAsset>( timelineAsset, "FirstTrack"); VerifyClip(clip); TimelineEditorUtility.SelectDirectorInTimelineWindow(director); //trigger the TimelineWindow's update etc. yield return(YieldEditorUtility.WaitForFramesAndIncrementUndo(3)); DummyTimelineClipData clipData = clip.GetClipData <DummyTimelineClipData>(); Assert.IsNotNull(clipData); TimelineEditorUtility.DestroyAssets(clip); //Cleanup }
public IEnumerator ShowClipInInspector() { CreateDirectorWithTimelineAsset(TIMELINE_ASSET_PATH, out TimelineAsset timelineAsset); yield return(YieldEditorUtility.WaitForFramesAndIncrementUndo(1)); TrackAsset track = timelineAsset.CreateTrack <DummyTimelineTrack>(null, "FooTrack"); TimelineClip clip = TimelineEditorReflection.CreateClipOnTrack(typeof(DummyTimelinePlayableAsset), track, 0); VerifyClip(clip); ScriptableObject editorClip = TimelineEditorUtility.SelectTimelineClipInInspector(clip); Assert.IsNotNull(editorClip); yield return(YieldEditorUtility.WaitForFramesAndIncrementUndo(1)); Object.DestroyImmediate(editorClip); yield return(YieldEditorUtility.WaitForFramesAndIncrementUndo(1)); TimelineEditorUtility.DestroyAssets(clip); //Cleanup }
public IEnumerator CreateAndLoadAsset() { string materialName = "TestRunnerMaterial"; Material createdMat = new Material(Shader.Find("Standard")) { name = materialName }; string path = AssetEditorUtility.CreateSceneAsset(createdMat, "mat"); yield return(YieldEditorUtility.WaitForFramesAndIncrementUndo(1)); string[] guids = AssetDatabase.FindAssets($"t:material {materialName}"); Assert.IsNotNull(guids); Assert.Greater(guids.Length, 0); Material mat = AssetEditorUtility.LoadAssetByGUID <Material>(guids[0]); Assert.IsNotNull(mat); yield return(YieldEditorUtility.WaitForFramesAndIncrementUndo(1)); AssetDatabase.DeleteAsset(path); }