創建
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); } }
