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");
        }
        public void GetMeshGUID()
        {
            //null checks
            Assert.DoesNotThrow(() =>
            {
                ModelSource errorModelSource = PolyEditorUtility.GetMeshGUID(null);
                Assert.AreEqual(errorModelSource, ModelSource.Error);
            });

            //getting a gameobject with a mesh asset linked into it
            Mesh        mesh         = _testGameObject.GetComponent <MeshFilter>().sharedMesh;
            string      guidExpected = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(mesh));
            string      guidResult   = string.Empty;
            ModelSource modelSource  = PolyEditorUtility.GetMeshGUID(mesh, ref guidResult);

            //should return an GUID because it's an asset
            Assert.IsFalse(string.IsNullOrEmpty(guidResult));
            //should be equal to the GUID extracted from the asset
            Assert.IsTrue(string.Compare(guidExpected, guidResult) == 0);
            //should return Asset modelsource
            Assert.AreEqual(modelSource, ModelSource.Asset);

            //test non asset mesh
            Mesh        duplicatedMesh        = Object.Instantiate(mesh);
            ModelSource duplicatedModelSource = PolyEditorUtility.GetMeshGUID(duplicatedMesh);

            Assert.AreEqual(duplicatedModelSource, ModelSource.Scene);
        }
        public void InSelection()
        {
            //null checks
            Assert.DoesNotThrow(() => PolyEditorUtility.InSelection(default(GameObject)));

            //no selection test
            Selection.activeObject = null;
            Assert.IsFalse(PolyEditorUtility.InSelection(_testGameObject));

            //selection test
            Selection.activeObject = _testGameObject;
            Assert.IsTrue(PolyEditorUtility.InSelection(_testGameObject));

            //child selection test
            Assert.IsFalse(PolyEditorUtility.InSelection(_childTestGameObject));
        }
Exemplo n.º 5
0
 public void Init()
 {
     m_Palette = PolyEditorUtility.CreateNew <ColorPalette>();
 }