.asset对应的类:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 通过CreateAssetMenu标注后会出现在Assets资源窗口右键功能选项中
/// </summary>
[CreateAssetMenu(fileName = "SettingsAssetConfig",menuName = "AssetConfigFile/SettingsAssetConfig",order =1)]
public class SettingsAssetConfig : ScriptableObject {
public string appName = "app的名字";
public bool isPlayBgMusic = true;
}
加载:
using System.Collections;
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class AssetConfigsMgr
{
private const string SettingsAssetConfigPath = "Assets/Frameworks/ConfigFiles/Asset/SettingsAssetConfig.asset";
/// <summary>
/// 编辑器模式下加载 通过AssetDatabase类
/// </summary>
/// <returns></returns>
public static SettingsAssetConfig GetSettingsAssetConfig()
{
SettingsAssetConfig realConfig = AssetDatabase.LoadAssetAtPath<SettingsAssetConfig>(SettingsAssetConfigPath);
return realConfig;
}
/// <summary>
/// 通过Resources类加载,SettingsAssetConfig.asset文件必须放在Resources文件夹下才可以读取
/// </summary>
/// <returns></returns>
public static SettingsAssetConfig GetSettingsAssetConfigByResources()
{
SettingsAssetConfig ret = Resources.Load<SettingsAssetConfig>("SettingsAssetConfig");
return ret;
}
/// <summary>
/// 泛型方法:通过Resources类加载
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="path"></param>
/// <returns></returns>
public static T GetAssetConfig<T>(string path)where T:UnityEngine.Object
{
T ret = Resources.Load<T>(path);
return ret;
}
public static T GetAssetConfigInEditor<T>(string fullPath) where T:UnityEngine.Object
{
T ret = AssetDatabase.LoadAssetAtPath<T>(fullPath);
return ret;
}
}