Android 读取asset文件

Android 读取asset文件,第1张

读取asset目笑磨录下面文件, 返回碰握斗byte[] , fileName: key/hello.der

读取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文件


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/12271316.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存