accessing user documents folder on unity3d

孤街醉人 提交于 2019-12-25 02:38:06

问题


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.



来源:https://stackoverflow.com/questions/22545244/accessing-user-documents-folder-on-unity3d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!