public void GetFirstOrNew()
        {
            RemoveAllGenericTypeAssets();

            //make sure that there is more asset of that type on the project
            string[] allGUIDs = AssetDatabase.FindAssets("t:" + typeof(UnitTestGenericType));
            Assert.IsTrue(allGUIDs == null || allGUIDs.Length == 0);

            //the function will create a new asset with the type passed in the generic parameter
            UnitTestGenericType unitTestGenericType = PolyEditorUtility.GetFirstOrNew <UnitTestGenericType>();

            //test it again, should return 1 value
            allGUIDs = AssetDatabase.FindAssets("t:" + typeof(UnitTestGenericType));
            Assert.IsTrue(allGUIDs != null && allGUIDs.Length == 1);
            UnitTestGenericType result = AssetDatabase.LoadAssetAtPath <UnitTestGenericType>(AssetDatabase.GUIDToAssetPath(allGUIDs[0]));

            Assert.IsNotNull(result);

            //call it one more time, ensure it will return the same result
            UnitTestGenericType secondResult = AssetDatabase.LoadAssetAtPath <UnitTestGenericType>(AssetDatabase.GUIDToAssetPath(allGUIDs[0]));

            Assert.AreEqual(result, secondResult);

            //cleanup
            AssetDatabase.DeleteAsset(AssetDatabase.GUIDToAssetPath(allGUIDs[0]));
        }
        public void GetAll()
        {
            RemoveAllGenericTypeAssets();

            //create two assets
            UnitTestGenericType asset1 = ScriptableObject.CreateInstance <UnitTestGenericType>();
            UnitTestGenericType asset2 = ScriptableObject.CreateInstance <UnitTestGenericType>();

            EditorUtility.SetDirty(asset1);
            EditorUtility.SetDirty(asset2);
            AssetDatabase.CreateAsset(asset1, path + "UnitTestGenericType1.asset");
            AssetDatabase.CreateAsset(asset2, path + "UnitTestGenericType2.asset");
            //check if existing
            Assert.IsNotNull(AssetDatabase.LoadAssetAtPath <UnitTestGenericType>(path + "UnitTestGenericType1.asset"));
            Assert.IsNotNull(AssetDatabase.LoadAssetAtPath <UnitTestGenericType>(path + "UnitTestGenericType2.asset"));

            //now load them with the utility function
            List <UnitTestGenericType> allAssets = PolyEditorUtility.GetAll <UnitTestGenericType>();

            Assert.IsNotNull(allAssets);
            Assert.IsTrue(allAssets.Count == 2);

            //cleanup
            AssetDatabase.DeleteAsset(path + "UnitTestGenericType1.asset");
            AssetDatabase.DeleteAsset(path + "UnitTestGenericType2.asset");
        }
 private static void RemoveAllGenericTypeAssets()
 {
     //get rid first of all previously created data
     string[] allGUIDs = AssetDatabase.FindAssets("t:" + typeof(UnitTestGenericType));
     foreach (string guid in allGUIDs)
     {
         UnitTestGenericType genericObject = AssetDatabase.LoadAssetAtPath <UnitTestGenericType>(AssetDatabase.GUIDToAssetPath(guid));
         if (genericObject != null)
         {
             AssetDatabase.DeleteAsset(AssetDatabase.GUIDToAssetPath(guid));
         }
     }
 }