Version: 2020.3

AssetDatabase.RemoveObjectFromAsset

매뉴얼로 전환
public static void RemoveObjectFromAsset (Object objectToRemove);

설명

Removes object from its asset (See Also: AssetDatabase.AddObjectToAsset).

using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class Scriptable : ScriptableObject { } public class AssetDatabaseExamples : MonoBehaviour { [MenuItem("AssetDatabase/Remove Object From Asset Example")] public static void RemoveObjectFromAssetExample() { var scriptableObjectList = new List<Scriptable>();

//Create Scriptable Objects and store them in a List for (var i = 0; i < 10; i++) { scriptableObjectList.Add(ScriptableObject.CreateInstance<Scriptable>()); AssetDatabase.CreateAsset(scriptableObjectList[i], $"Assets/ScriptableObjects/SO{i}.asset"); }

//Add Materials as Sub Assets to the Scriptable Objects foreach (var so in scriptableObjectList) { AssetDatabase.AddObjectToAsset(new Material(Shader.Find("Standard")), so); } AssetDatabase.SaveAssets();

//Remove Materials from their Scriptable Objects foreach (var so in scriptableObjectList) { var material = AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPath(so), typeof(Material)); AssetDatabase.RemoveObjectFromAsset(material); } AssetDatabase.SaveAssets(); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961