其他分享
首页 > 其他分享> > 创建和使用 ScriptableObject

创建和使用 ScriptableObject

作者:互联网

创建  

using System;
using UnityEditor;
using UnityEngine;
public class CreateAsset : Editor
{

    //在菜单栏创建功能项
    [MenuItem("数据/Excel")]
    static void Create()
    {
        ScriptableObject scriptable = Objects.CreateInstance<Objects>();
        // string path = string.Format("{0}/{1}.asset", "Assets/Resources", "nanexcle");
        //路径名称
        string path = string.Format("Assets/Resources/nanexcle.asset");
        //ExcelTable table = new ExcelTable();
        // table.Du();

        AssetDatabase.CreateAsset(scriptable, path);
    }
}

赋值

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

public class Objects : ScriptableObject
{
    public string[] str;
    public GameObject game;
    public Texture2D texture2D;
    public List<int> vs;
    [ContextMenu("刷新数据")]
    void Update()
    {
        //给数据赋值
        Debug.Log("给数据赋值");
    }
}

取值

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

public class AppObject : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        Objects objects= Resources.Load<Objects>("nanexcle");
        Debug.Log(objects.str.Length);
    }  
}

 

标签:UnityEngine,ScriptableObject,string,创建,System,Collections,使用,using,public
来源: https://www.cnblogs.com/G993/p/13926400.html