读取asset目录下面文皮中件, 返回string
将文件保存到外部
Description
这是一个很容易的创建一个新的派生类实例的方法scriptableobject资产文件。该资产是唯一命名,并放置在当前选定的项目路径,scriptableobject资产文件用于存储数据,不适合自然MonoBehaviour /对象预制系统内。因为他们使用Unity内置的序列化,他们是保证完全映射到一个现有的类;因此,scriptableobject资产工作弯穗在Unity比XML,CSV文件或其他传盯闹键统的存储这些数据的方法更容易.
Usage
scriptableobjectutility.cs复制到您的项目。然后创建一个类yourclassasset.cs
ScriptableObjectUtility.cs
using UnityEngine
using UnityEditor
using System.IO
public static class ScriptableObjectUtility
{
/// <summary>
// This makes it easy to create, name and place unique new ScriptableObject asset files.
/// </summary>
public static void CreateAsset<T>() where T : ScriptableObject
{
T asset = ScriptableObject.CreateInstance<T>()
string path = AssetDatabase.GetAssetPath (Selection.activeObject)
if (path == "")
{
path = "Assets"
}
else if (Path.GetExtension (path) != "")
{
path = path.Replace (Path.GetFileName (AssetDatabase.GetAssetPath (Selection.activeObject)), "")
}
string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath (path + "/New " + typeof(T).ToString() + ".asset")
AssetDatabase.CreateAsset (asset, assetPathAndName)
AssetDatabase.SaveAssets ()
AssetDatabase.Refresh()
EditorUtility.FocusProjectWindow ()
Selection.activeObject = asset
}
}
YourEditorAsset.cs
using UnityEngine
using UnityEditor
public class YourEditorAsset
{
[MenuItem("Assets/Create/YourClass")]
public static void CreateAsset ()
{
ScriptableObjectUtility.CreateAsset<YourClass>()
}
}
YourClassAsset.cs
using UnityEngine
using UnityEditor
public class YourClassAsset : ScriptableObject
{
//写上各种变量
}
之后就凯巧可以生成出像这样高大上的*.asset文件
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)