I'm trying to start a process from unity. It should sync the streaming assets folder with a folder present in an http server.
Everything works well but it creates a streaming assets folder outside the "projectName_Data" folder.
I'm using this script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class refreshVideo : MonoBehaviour {
public string processName;
public void startRefresh(string ipServer)
{
// Create a process
System.Diagnostics.Process process = new System.Diagnostics.Process();
// Set the StartInfo of process
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
process.StartInfo.FileName = Application.dataPath + "/" + processName;
process.StartInfo.Arguments = ipServer;
path = Application.dataPath;
// Start the process
process.Start();
process.WaitForExit();
}
}
The process is inside the dataPath and if I start it manually it sync the streaming assets folder without problems. If unity starts it, it seams to start it from outside the dataPath.
Can I tell to Unity to open the exteral exe from the dataPath folder?
Related
I have a problem with building Unity Project on WebGL target. This only appeares when I'm trying to build from script. When I build it from Unity project builds fine.
I think it can also be important, I'm running this methot from powershell script
PS Script:
$unityPath = "C:\Program Files\Unity\Editor\Unity.exe"
$unityParameters = "-batchmode -projectPath `"$($repo)\`" -username USERNAME -password PASS -executeMethod `"BuildScript.PerformBuild`""
$buildProcess = Start-Process -FilePath $unityPath -ArgumentList $unityParameters -Wait -PassThru
My code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.Build.Reporting;
public class BuildScript
{
public static void PerformBuild()
{
var projectName = "scene_1";
Debug.Log("### BUILDING ###");
EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.WebGL, BuildTarget.WebGL);
var report = BuildPipeline.BuildPlayer(
new[] {$"Assets/Scenes/{projectName}.unity"},
$"Build/Win/{projectName}.exe",
BuildTarget.WebGL,
BuildOptions.None);
Debug.Log("### DONE ###");
Debug.Log(report);
EditorApplication.Exit(1);
}
}
Error I get in report:
Switching to WebGL:WebGLSupport is disabled
...
DisplayProgressNotification: Build Failed Error building player
Error building player because build target was unsupported
Please check if you have WebGL support installed at eg: C:\Program Files\Unity\2020.1.5f1\Editor\Data\PlaybackEngines\WebGLSupport
This error Switching to WebGL:WebGLSupport is disabled says that WebGLSupport is probably missing from you Unity installation.
Please double check that you are using the same installation of Unity in the script and in the Editor. You can check your path in UnityHub via Show in Explorer option
I load images from my local destination to unity the code is:
Texture2D imgTexture;
using (UnityWebRequest req = UnityWebRequestTexture.GetTexture(filePath))
{
yield return req.SendWebRequest();
if (req.isNetworkError)
{
Debug.Log(req.error);
}
else
{
imgTexture = DownloadHandlerTexture.GetContent(req);
}
}
it works on pc but when I run on android emulator I get an error
Cannot connect to destination host
the local file directory comes from simple file browsing plugin so I am thinking directory cannot be wrong.
is it a permission problem how can I fix this?
I have a package which runs uses Gtk and written in vala.A dialog box or a gui opens after selecting a file.I want this dialog box or gui to run as root so as to open and read the files which don't open with normal users.I have this code
static void open_file(string filename) {
selected_file = filename;
stdout.printf(selected_file);
new ProgressWindow(selected_file, {});
}
I want to run ProgressWindow to run as root.Is it possible?
No. To run as root, it must be in a separate process and you must run that process using pkexec via PolicyKit. Here's a tutorial on PolicyKit in Vala.
I am writing a application that will run inside JBoss EAP 6.3.1 on a CentOS 6.5
During this application i have to save a file to the disk and when restarting the application i have to read it back into the application.
All this is working.
The problem is that i want to save to file in the working directory of the application.
What is happening right now is that the file: foo.bar will be saved at the location where i run the standalone.sh (or .bat on Windows).
public void saveToFile() throws IOException {
String foo = "bar";
Writer out = new OutputStreamWriter(new FileOutputStream("/foo.bar"), "UTF-8");
try {
out.write(foo);
} finally {
out.close();
}
}
You could try to use an absolute path to save your file:
String yourSystemPath = System.getProperty("jboss.home.url") /*OPTIONAL*/ + "/want/to/save/here";
File fileToSave = new File(yourSystemPath,"foo.bar");
Writer out = new OutputStreamWriter(new FileOutputStream(fileToSave), "UTF-8");
Basically here, I'm creating a File object using a yourSystemPath variable where I stored the path to save the file in, then I'm creating the new FileOutputStream(fileToSave) using the previously created object File
Please ensure that your JBoss server has write permissions for yourSystemPath
I would like to ask if anyone create Assetbundle in Unity on cloud? I would like to generate the AssetBundle dynamically on cloud and the client app will download it accordingly.
Could you let me know your idea? Is there any cloud service for hosting Unity ?
The accepted answer is spot on but there are slight changes as Unity5.6 now supports every other feature in the free version too. I've been working on a similar project that required building asset bundles dynamically. I'll post my code snippet for the same so that the process of identifying this gets simpler for everyone else in future.
But before that, there are some limitations for this process that you may need to consider. Building asset bundles dynamically on cloud requires (Command line) batchmode which runs Unity on commandline (Unity should be installed to build bundles). This asset building process works only on Windows and OSX (No Linux). The command to invoke Unity in batch mode is given below and has to be executed from Unity executable's location,
this command creates an empty project,
Unity -batchmode -quit -createProject <path/to/create a project>
After creating a project, you can save a script to build assets in the Assets/Editor folder, I have a written a script to automate the process of building assetbundle for all assets in the Assets/Models folder.
//BuildAssets.cs
using System.Collections;
using System.Collections.Generic;
public class BuildAssets : UnityEngine.MonoBehaviour
{
static void BuildAssetBundle()
{
int i = 0;
string log = "log.txt";
string[] assetN;
int N_Files;
UnityEditor.AssetBundleBuild[] AssetMap = new UnityEditor.AssetBundleBuild[2];
AssetMap[0].assetBundleName = "res";
// Adding to path /Models
string path = UnityEngine.Application.dataPath + "/Models";
//log
System.IO.File.AppendAllText(log, System.DateTime.Now.ToString() + "\n\n");
System.IO.File.AppendAllText(log, path + "\n");
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(path);
System.IO.FileInfo[] files = dir.GetFiles();
// Number of files in "/Models" folder
N_Files = files.Length;
//log
System.IO.File.AppendAllText(log, "Num assets: "+N_Files + " \n");
assetN = new string[N_Files];
foreach (System.IO.FileInfo file in files)
{
if (file.Exists)
{
if (!file.Extension.Equals(".meta"))
{
assetN[i] = "Assets/Resources/" + file.Name;
System.IO.File.AppendAllText(log, assetN[i] + " \n");
i += 1;
}
}
}
AssetMap[0].assetNames = assetN;
UnityEditor.BuildPipeline.BuildAssetBundles("Assets/AssetBundles", AssetMap, UnityEditor.BuildAssetBundleOptions.None, UnityEditor.BuildTarget.Android);
System.IO.File.AppendAllText(log, "\t----X----\n"); //log
}
}
This is the command for building the asset bundle through command line.
Unity -batchmode -quit -projectPath path/to/UnityProjects/Projectname -executeMethod BuildAssets.BuildAssetBundle -logFile <Log file location>
I've tested this and it works for our project.
AssetBundles require unity pro to build. There is a command line batch mode that you can use to build your asset bundles automaticly and host it on virtualy any host (a simple HTTP get).
Remember that you might not need asset bundles (or unity pro) - you can easily download textures and audio from the web using the WWW class. For textures you can use png, jpeg and tiff, for audio wav, ogg (only desktop and webplayer), mp3 (only mobile). Mesh loading should be also possible but that will require additional tools.