1.新建一个OpenUrl.cs脚本,并添加给Open按钮
using UnityEngine;
using System.IO;
using UnityEngine.UI;
using System.Diagnostics;
using System.Runtime.InteropServices;
public class OpenUrl : MonoBehaviour
{
private Button Open;
// Use this for initialization
void Start()
{
//鼠标点击按钮事件
Open = GameObject.Find("Open").GetComponent<Button>();
Open.onClick.AddListener(OnClick);
}
// Update is called once per frame
void Update()
{
}
//读取文件事件
public static bool ShowInExplorer(string itemPath)
{
bool result = false;
#if !UNITY_WEBPLAYER
itemPath = Path.GetFullPath(itemPath.Replace(@"/", @"\"));
if (File.Exists(itemPath))
{
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
Process.Start("explorer.exe", "/select," + itemPath);
#endif
result = true;
}
else if (Directory.Exists(itemPath))
{
UnityEngine.Application.OpenURL(itemPath);
result = true;
}
#endif
return result;
}
void OnClick()
{
ShowInExplorer("F:/2018");
}
}
2.运行结果
