当前位置:   article > 正文

Unity .asset文件_assetdatabase.createasset exe不执行

assetdatabase.createasset exe不执行

概念

 Unity中的自定义资源类型,一般用于数据配置管理。

创建

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class DataBase : ScriptableObject
  5. {
  6. public int a;
  7. public float b;
  8. public bool c;
  9. public string d;
  10. public Texture e;
  11. public GameObject f;
  12. }
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. public class CreateAsset : Editor
  6. {
  7. [MenuItem("Tools/CreateAsset")]
  8. public static void CreateDatabase()
  9. {
  10. DataBase dataBase = ScriptableObject.CreateInstance<DataBase>();
  11. AssetDatabase.CreateAsset(dataBase, "Assets/GameData.asset");
  12. AssetDatabase.SaveAssets();
  13. AssetDatabase.Refresh();
  14. }
  15. }

加载

 

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class LoadAsset : MonoBehaviour
  5. {
  6. void Start ()
  7. {
  8. DataBase dataBase = Resources.Load<DataBase>("GameData");
  9. Debug.Log(dataBase.a);
  10. }
  11. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/81922
推荐阅读
相关标签
  

闽ICP备14008679号