//----create a scriptable object and add it to an existing asset
CmyScriptableObject obj = ScriptableObject.CreateInstance<CmyScriptableObject> ();
AssetDatabase.AddObjectToAsset(obj,existingAsset);
// Reimport the asset after adding an object.
// Otherwise the change only shows up when saving the project
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(obj));
Selection.activeObject = obj;
//----remove object in asset
//ref : http://answers.unity3d.com/questions/219465/how-can-i-remove-an-object-from-an-asset.html
UnityEngine.Object.DestroyImmediate(obj, true);
AssetDatabase.SaveAssets();
时间: 2024-11-18 14:10:04