访问unity3d上的用户文档文件夹 [英] accessing user documents folder on unity3d

查看:155
本文介绍了访问unity3d上的用户文档文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用UnityScript在Unity3D上获取当前用户文档文件夹的路径?我正在尝试主要在台式机系统(Windows,Linux或OSX)上访问它.在移动系统上,Application.persistentDataPath对我有用,但是对于台式机,我想使用documents文件夹,用户可以在其中轻松查看和更改文件.

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.

推荐答案

我不知道Javascript是否可以获取Windows特殊文件夹,但是C#具有

I don't know if Javascript has a way to get Windows special folders, but C# has Environment.GetFolderPath.

因此,一种方法是创建一个C#脚本,该脚本将为您提供我的文档"路径,并将其放在 Standard Assets 文件夹中.这样,JavaScript可以调用该脚本.

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#文件

using System;
public class GetUserPathCSharp
{
    public static string GetUserPath()
    {
        return Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
    }
}

JavaScript文件

Javascript file

#pragma strict
function Start () {
    var test = GetUserPathCSharp.GetUserPath();
    print("Path is " + test);
}

注意:确保C#脚本在名为 Standard Assets 的文件夹内. 这很重要.

Note: Make sure that the C# script is inside the a folder called Standard Assets. It's important.

这篇关于访问unity3d上的用户文档文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆