赞
踩
概念
Unity中的自定义资源类型,一般用于数据配置管理。
创建
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
-
- public class DataBase : ScriptableObject
- {
- public int a;
- public float b;
- public bool c;
- public string d;
- public Texture e;
- public GameObject f;
- }
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEditor;
-
- public class CreateAsset : Editor
- {
- [MenuItem("Tools/CreateAsset")]
- public static void CreateDatabase()
- {
- DataBase dataBase = ScriptableObject.CreateInstance<DataBase>();
- AssetDatabase.CreateAsset(dataBase, "Assets/GameData.asset");
- AssetDatabase.SaveAssets();
- AssetDatabase.Refresh();
- }
- }
加载
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
-
- public class LoadAsset : MonoBehaviour
- {
- void Start ()
- {
- DataBase dataBase = Resources.Load<DataBase>("GameData");
- Debug.Log(dataBase.a);
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。