【问题标题】:Copy image from one folder to another folder in Unity 3d Android Platform在 Unity 3d Android 平台中将图像从一个文件夹复制到另一个文件夹
【发布时间】:2020-09-29 12:38:11
【问题描述】:

我正在寻找这个问题很多天。我正在开发 Unity 3d Android 项目。是否可以在按下按钮时选择图像,然后在按下另一个按钮时将该图像复制到另一个文件夹?我见过太多的插件,其中大部分是 UnityEditor(PC 平台)和 android 平台都不起作用。请回复。

【问题讨论】:

  • 为什么不可能?
  • 那么请帮帮我
  • 我正忙着帮助你。你还没有回答我的问题。重复:为什么认为这是不可能的?
  • 我尝试实现docs.unity3d.com/ScriptReference/… 的代码,但这仅适用于PC 平台。我想要一个简单的 android 平台。请帮帮我兄弟
  • 所以你只需要代码。而你仍然没有回答我的问题。

标签: android image unity3d copy textures


【解决方案1】:

这是我的代码

    using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using System;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

    public class FileC : MonoBehaviour
    {
    public void save()
        {
            string fileName = "a.png";

        string sourcePath = @"/mnt/sdcard/Test1";

        string targetPath =  @"/mnt/sdcard/Test2";


            // Use Path class to manipulate file and directory paths.
            string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
            string destFile = System.IO.Path.Combine(targetPath, fileName);

            // To copy a folder's contents to a new location:
            // Create a new target folder, if necessary.
            if (!System.IO.Directory.Exists(targetPath))
            {
                System.IO.Directory.CreateDirectory(targetPath);
            }

        // Create a new target folder, if necessary.
        if (!System.IO.Directory.Exists(sourcePath))
        {
            System.IO.Directory.CreateDirectory(sourcePath);
        }

            // To copy a file to another location and 
            // overwrite the destination file if it already exists.
            System.IO.File.Copy(sourceFile, destFile, true);

            // To copy all the files in one directory to another directory.
            // Get the files in the source folder. (To recursively iterate through
            // all subfolders under the current directory, see
            // "How to: Iterate Through a Directory Tree.")
            // Note: Check for target path was performed previously
            //       in this code example.
            if (System.IO.Directory.Exists(sourcePath))
            {
                string[] files = System.IO.Directory.GetFiles(sourcePath);

                // Copy the files and overwrite destination files if they already exist.
                foreach (string s in files)
                {
                    // Use static Path methods to extract only the file name from the path.
                    fileName = System.IO.Path.GetFileName(s);
                    destFile = System.IO.Path.Combine(targetPath, fileName);
                    System.IO.File.Copy(s, destFile, true);
                }
            }
            else
            {
                Console.WriteLine("Source path does not exist!");
            }

            // Keep console window open in debug mode.
            Console.WriteLine("Press any key to exit.");
        }


    }

【讨论】:

  • 请不要将您的代码作为答案,而是在您的帖子中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-07-30
  • 1970-01-01
  • 2014-09-17
  • 2018-03-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多