Unity编辑器-persistentDataPath-dataPath-streamingAssetsPath

Unity中persistentDataPath, dataPath, streamingAssetsPath在不同的平台对应的路径 为了方便以后的开发,自己结合官方资料和自己的实际开发,把上面的路径变量在不同的平台对应的正式路径总结一下 Application.persistentDataPath 官方参考:https://docs.unity3d.com/2020.3/Documentation/ScriptReference/Application-persistentDataPath.html 对app是只读的,对玩家来说读写都可以,如果是IOS或者安卓,该路径指向设备的公共目录 app更新的时候,不会删除该目录,但是用户自己是可以对该目录增删改查的 平台 指向的位置 Windows Store Apps %userprofile%\AppData\Local\Packages&lt;productname>\LocalState Windows Editor and Standalone Player %userprofile%\AppData\LocalLow&lt;companyname>&lt;productname> WebGL /idbfs/<md5 hash of data path> 该路径是URL最后一个斜杠“/”和“?”之间的字符串 Linux $XDG_CONFIG_HOME/unity3d 或者$HOME/.config/unity3d iOS /var/mobile/Containers/Data/Application/<guid>/Documents tvOS 不支持且返回空字符串 Android 通常指向/storage/emulated/0/Android/data/<packagename>/files,有的老机型可能指向SD卡的路径 Mac 指向用户的Library目录,通常该目录是隐藏的,现在Unity是指向~/Library/Application Support/company name/product name Application.dataPath 官方参考:https://docs.unity3d.com/2020.3/Documentation/ScriptReference/Application-streamingAssetsPath.html 对玩家和app都是只读的,是指设备的游戏目录,只能读取 根据不同的平台,游戏目录不一样 平台 指向位置 Unity Editor <项目路径>/Assets Mac player <path to player app bundle>/Contents iOS player <path to player app bundle>/<AppName.app>/Data Win/Linux player <游戏的可执行文件的数据目录> (请注意Linux目录是大小写敏感的,window不是) WebGL 玩家数据目录的绝对URL(没有具体的文件名) Android 通常指向APK,如果你使用的是安卓分包,那么它指向OBB(也就是说游戏数据文件都保存到了OBB文件中) Windows Store Apps 是一个指向玩家数据目录的绝对路径 注意:PC上返回的路径是用反斜杠(“\”)做分割的...

October 27, 2022 · 1 min · 150 words · Link

在Unity编辑器不同位置添加菜单

在Unity编辑器不同位置添加菜单 有时候由于自定义工作流的需要,我们需要在编辑器中添加我们自己的菜单,用来执行不同的操作,这里介绍在编辑器的不同位置该如何添加菜单,比如在主菜单添加,Hierarchy, Project,Inspector等位置。主菜单通过下拉列表弹出,Hierarchy,Project和Inspector分别是鼠标右键弹出。 在主菜单中弹出 using UnityEngine; using UnityEditor; using System.Collections; public class ExampleClass : MonoBehaviour { // Add Example1 has priority of 100 [MenuItem("Example/Example1", priority = 1)] public static void Example1() { print("Example/Example1"); } // Example2 has a priority of 111 which is 11 more than Example1. // This will cause a divider to be created. [MenuItem("Example/Example2", priority = 11)] public static void Example2() { print("Example/Example2"); } } 效果如下图: 注意当两个菜单的 priority 差值大于10【小于等于10不会有】的时候,菜单之间会自动生成一条横线。并且 priority 越大,菜单就会在越下面 在Hierarchy中弹出 using UnityEngine; using UnityEditor; using System....

September 22, 2022 · 2 min · 280 words · Link

在Unity的Hierarchy面板上添加鼠标右键菜单

在Unity的Hierarchy面板上添加右键菜单 这里添加的是复制一个模型的节点信息的功能,从子节点自身开始复制,一直到模型的父节点终止。因为有时候模型的子节点比较多,一个一个的去点开查找比较麻烦,或者想查看子节点的路径对不对。记得priority要写。 代码如下: public static class EditorTool { [MenuItem("GameObject/EditorTool/CopyPath", priority = 0)] static string CopyPath() { if (Selection.gameObjects.Length == 1) { GameObject selectObj = Selection.gameObjects[0]; StringBuilder pathSB = new StringBuilder(selectObj.name); while (selectObj.transform.parent != null) { pathSB.Insert(0, selectObj.transform.parent.name + "/"); selectObj = selectObj.transform.parent.gameObject; } GUIUtility.systemCopyBuffer = pathSB.ToString(); return pathSB.ToString(); } return ""; } } {: .shadow width = “50%” }

May 25, 2021 · 1 min · 59 words · Link