protected override void OnInit() { mainSO = ScriptableObject.CreateInstance <TestObject>(); subSO = ScriptableObject.CreateInstance <TestSubObject>(); subSO2 = ScriptableObject.CreateInstance <TestSubObject>(); subSO.name = "sub"; m_ScriptableObjectPath = GetAssetPath("testScriptableObject.asset"); AssetDatabase.CreateAsset(mainSO, m_ScriptableObjectPath); AssetDatabase.AddObjectToAsset(subSO, m_ScriptableObjectPath); AssetDatabase.AddObjectToAsset(subSO2, m_ScriptableObjectPath); AssetDatabase.ImportAsset(m_ScriptableObjectPath, ImportAssetOptions.ForceSynchronousImport | ImportAssetOptions.ForceUpdate); // create a Sprite atlas, + sprite m_SpriteAtlasPath = GetAssetPath("testAtlas.spriteatlas"); SpriteAtlas spriteAtlas = new SpriteAtlas(); AssetDatabase.CreateAsset(spriteAtlas, m_SpriteAtlasPath); Texture2D texture = Texture2D.whiteTexture; byte[] data = texture.EncodeToPNG(); m_TexturePath = GetAssetPath("testTexture.png"); File.WriteAllBytes(m_TexturePath, data); AssetDatabase.ImportAsset(m_TexturePath, ImportAssetOptions.ForceSynchronousImport | ImportAssetOptions.ForceUpdate); TextureImporter importer = TextureImporter.GetAtPath(m_TexturePath) as TextureImporter; importer.textureType = TextureImporterType.Sprite; importer.spriteImportMode = SpriteImportMode.Single; importer.SaveAndReimport(); SpriteAtlasExtensions.Add(spriteAtlas, new[] { AssetDatabase.LoadAssetAtPath <Texture>(m_TexturePath) }); SpriteAtlasUtility.PackAtlases(new SpriteAtlas[] { spriteAtlas }, EditorUserBuildSettings.activeBuildTarget, false); }
internal void AddTestSubObject() { TestSubObject n = ScriptableObject.CreateInstance <TestSubObject>(); n.name = "testSubObject"; AssetDatabase.AddObjectToAsset(n, this); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(this), ImportAssetOptions.ForceSynchronousImport | ImportAssetOptions.ForceUpdate); }