is it possible to get the path to the current user documents folder on Unity3D using UnityScript? I am trying to access it mainly on desktop systems (Windows, Linux or OSX). On mobile systems, Application.persistentDataPath do the trick for me, but for desktop I would like to use the documents folder where the users can see and change the files easily.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I don't know if Javascript has a way to get Windows special folders, but C# has Environment.GetFolderPath.
So one way of doing this is to create a C# script that will give you the My Documents path and put it in the Standard Assets folder. That way, javascript can call that script.
C# file
using System;
public class GetUserPathCSharp
{
public static string GetUserPath()
{
return Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
}
}
Javascript file
#pragma strict
function Start () {
var test = GetUserPathCSharp.GetUserPath();
print("Path is " + test);
}
Note: Make sure that the C# script is inside the a folder called Standard Assets. It's important.