unity Android路径的相关部分代码

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
public class ClientTools:MonoBehaviour {
    // Start is called before the first frame update
    public GameObject obj;
    public Text text;
    private FileInfo[] floders;
    private string AndroidDirectory = "/storage/emulated/0/Android/";//安卓路径
    private string WindowsDirectory = System.Environment.CurrentDirectory + "/资源/";//Windows路径
    private string filePath;
    /// <summary>
    ///   /storage/emulated/0/  Android 外置内存根目录
    ///   Application.persistentDataPath; 来检测Android 外置内存根目录的方法
    /// </summary>
    void Start() {
        EventTriggerListener.Get(obj).onClick = onClick;
    }


    private void onClick(GameObject sender) {
        ClientUDP.instance.Send("123123");
        if(Directory.Exists(WindowsDirectory)) {
            filePath = WindowsDirectory;
        } else if(Directory.Exists(AndroidDirectory)) {
            filePath = WindowsDirectory;
        } else {
            return;
        }

        DirectoryInfo direction = new DirectoryInfo(filePath);
        floders = direction.GetFiles("*.jpg",SearchOption.TopDirectoryOnly);
       // text.text += floders.Length.ToString() + "_____****";
        if(floders.Length > 0) {
            LoaderPic.LoadByIo(floders[0].ToString(),obj);
        }

    }
}

 

posted on 2023-02-03 09:34  zqiang0803  阅读(75)  评论(0编辑  收藏  举报

导航