创建和使用 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);
    }  
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM