- Home /
Working with Unity Editor
I need help copying files that are inside Unity's folder to where our executable is being created. I went online and found exactly what I was looking for but when I go ahead and implement it, the files are not being copied correctly. Here is what I have:
using UnityEngine;
using UnityEditor;
using System.Diagnostics;
public class UnityEditorClass {
[MenuItem("MyTools/Windows Build With Postprocess")]
public static void BuildGame()
{
// Get filename.
string path = EditorUtility.SaveFolderPanel("../Desktop/", "", ""); //The executable (for now) is created in the desktop
// Copy a file from the project folder to the build folder, alongside the built game.
FileUtil.CopyFileOrDirectory("C:/SchoolProjects/GSP2190/FirstGame", path + "vector2.dll");
FileUtil.CopyFileOrDirectory("C:/SchoolProjects/GSP2190/FirstGame", path + "mathHelper.dll");
// Run the game (Process class from System.Diagnostics).
Process proc = new Process();
proc.StartInfo.FileName = path + "Test.exe";
proc.Start();
}
}
And yes, this script is stashed within the Editor folder. My questions are:
Is the file name path correct
Am I copying the files correctly?
How come my files are not being copied correctly?
Thank you so much in advance!
Answer by HappyMoo · Jan 14, 2014 at 02:40 PM
Pleas lookup EditorUtility.SaveFolderPanel - The first parameter is supposed to be the title of the dialog, not the folder. If you're not sure, try to Debug.Log() stuff out.
And only you can tell if the paths are right, but it looks like you are trying to copy the folder "JAI" onto a file... that doesn't work.
You probably mean: FileUtil.CopyFileOrDirectory("C:/Projects/SBIR/sbir-phaseii/JAI/agility_input_win32.dll", path + "agility_input_win32.dll");
if the path includes a / at the end already.
Other than that, you need to know if these are the right files and if Test.exe really exists at the destination
Test.exe doesn't technically exists, not until I hit the build button and name my executable Test.exe
Thank you for the reply but it still does not copy the files over. The EditorUtility.SaveFolderPanel says that the first parameter should be where the game is built according to this page:
The script you mention also calls BuildPipeline.BuildPlayer to actually build the game...
You didn't mention you want to build the game - I assumed the Game is already built. The function EditorUtility.SaveFolderPanel just asks you for a folder, if you want to do more, you need to script more.
The only thing I want is just to copy the dlls over. The reason as to why I didnt add the build game is because I figured I didnt need it since I have to go to build settings and create the executable there.
Please Debug.Log(path) and check if all paths and files are there. Investigate.