unity怎么调用asset文件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了unity怎么调用asset文件相关的知识,希望对你有一定的参考价值。

参考技术A 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文件

unity 在安卓平台下怎么获取streamingassetspath

参考技术A string filePath =
#if UNITY_ANDROID && !UNITY_EDITOR
"jar:file://" + Application.dataPath + "!/assets/" + flodername + "/";
#elif UNITY_IPHONE && !UNITY_EDITOR
Application.dataPath + "/Raw/";
#elif UNITY_STANDALONE_WIN || UNITY_EDITOR
"file://" + Application.dataPath + "/StreamingAssets" + "/" + flodername + "/";
#endif本回答被提问者采纳

以上是关于unity怎么调用asset文件的主要内容,如果未能解决你的问题,请参考以下文章

unity发布安卓怎么读取本地文件

Android 读取asset文件

Unity资源导入

.unitypackage文件如何打开/解压缩

Unity 读取调用资源 Resources.Load(详细+示例)

unity怎么打开模型文件