Unity assets序列化

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

[CreateAssetMenu(fileName ="TestAssets",menuName ="CreateAssets",order =0 )]
public class assetSer : ScriptableObject
{
    public int Id;
    public string Name;
    public List TestList;
}

读取

using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using System.Xml.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

public class xmlxuleihua : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        ReadTestAssets();
    }
    void ReadTestAssets()
    {
        assetSer assets = UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/Scripts/TestAssets.asset");
        Debug.Log(assets.Id);
        foreach(string str in assets.TestList )
        {
            print(str);
        }
    } 
    

}

你可能感兴趣的:(unity,unity,游戏引擎)