Unity中的Path对应各平台中的Path

OS:
Application.dataPath :                    Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/xxx.app/Data
Application.streamingAssetsPath : Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/xxx.app/Data/Raw
Application.persistentDataPath :    Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Documents
Application.temporaryCachePath : Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Library/Caches

Android:
Application.dataPath :  /data/app/xxx.xxx.xxx.apk
Application.streamingAssetsPath :  jar:file:///data/app/xxx.xxx.xxx.apk/!/assets
Application.persistentDataPath :  /data/data/xxx.xxx.xxx/files
Application.temporaryCachePath :  /data/data/xxx.xxx.xxx/cache

Windows Web Player:
Application.dataPath :  file:///D:/MyGame/WebPlayer (即导包后保存的文件夹,html文件所在文件夹)
Application.streamingAssetsPath : 
Application.persistentDataPath : 
Application.temporaryCachePath : 

---------------------------------------------------------------------------------------------------
各目录权限:

根目录:StreamingAssets文件夹

#if UNITY_EDITOR
string filepath = Application.dataPath +"/StreamingAssets"+"/my.xml";
#elif UNITY_IPHONE
 string filepath = Application.dataPath +"/Raw"+"/my.xml";
#elif UNITY_ANDROID
 string filepath = "jar:file://" + Application.dataPath + "!/assets/"+"/my.xml;
#endif


根目录:Resources 文件夹

可以使用Resources.Load("名字"); 把文件夹中的对象加载出来


根目录:StreamingAssets 文件夹

可以使用Application.dataPath进行读操作

Application.dataPath: 只可读不可写,放置一些资源数据


Application.persistentDataPath

IOS与android平台都可以使用这个目录下进行读写操作,可以存放各种配置文件进行修改之类的。

在PC上的地址是:C:\Users\用户名 \AppData\LocalLow\DefaultCompany\test

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Unity使用HTML格式来实现点击不同按钮播放对应视频,可以使用WebGL来加载HTML页面,并通过JavaScript与Unity交互来实现。 以下是实现步骤: 1. 创建一个WebGL项目,在Assets目录下创建一个名为“StreamingAssets”的文件夹,将HTML文件和视频文件放在该文件夹下。 2. 在Unity创建一个空对象,将WebGL发布的HTML页面加载到该对象上,代码如下: ``` public class LoadHTML : MonoBehaviour { IEnumerator Start() { UnityWebRequest www = UnityWebRequest.Get(Application.streamingAssetsPath + "/index.html"); yield return www.SendWebRequest(); if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); } else { GetComponent<UnityWebRequest>().text = www.downloadHandler.text; } } } ``` 3. 在HTML页面添加按钮,每个按钮都有一个唯一的ID,代码如下: ``` <button id="btn1">Play Video 1</button> <button id="btn2">Play Video 2</button> ``` 4. 在HTML页面添加JavaScript代码,当按钮被点击时,通过调用Unity的方法来播放对应的视频,代码如下: ``` <script> var btn1 = document.getElementById("btn1"); btn1.addEventListener("click", function() { unityInstance.SendMessage("VideoPlayer", "PlayVideo", "video1.mp4"); }); var btn2 = document.getElementById("btn2"); btn2.addEventListener("click", function() { unityInstance.SendMessage("VideoPlayer", "PlayVideo", "video2.mp4"); }); </script> ``` 5. 在Unity创建一个名为“VideoPlayer”的空对象,添加一个名为“VideoPlayerControl”的C#脚本,代码如下: ``` using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Video; public class VideoPlayerControl : MonoBehaviour { public VideoPlayer videoPlayer; public void PlayVideo(string fileName) { string path = System.IO.Path.Combine(Application.streamingAssetsPath, fileName); videoPlayer.url = path; videoPlayer.Play(); } } ``` 6. 将VideoPlayer组件添加到“VideoPlayer”对象上,将VideoPlayerControl脚本挂在“VideoPlayer”对象上,运行Unity项目并在WebGL页面点击按钮,即可播放对应的视频。 注意事项: 1. 使用HTML和JavaScript时,需要注意跨域访问的问题。 2. 在Unity加载HTML页面时,需要使用UnityWebRequest来获取HTML文件。 3. 在HTML页面调用Unity的方法时,需要使用SendMessage方法,并且需要指定目标对象和方法名。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值