- Home /
unexpected char: 'U'. when File.WriteAllBytes()
File.WriteAllBytes("C:\Users\koneo\Desktop\swagtest.unitypackage",www.bytes);
So I don't know what's wrong, if you wan't the whole script, here it it:
// UnityScript
@script ExecuteInEditMode()
import System.IO;
class MyWindow extends EditorWindow {
private var www : WWW;
var target : Renderer;
var texture : Texture2D;
var texture2 : Texture2D;
var texture3 : Texture2D;
var one : int = 1;
var done : boolean;
var loc : String;
var lo : String;
@MenuItem ("Window/My Window")
static function ShowWindow () {
EditorWindow.GetWindow (MyWindow);
}
function OnGUI () {
if(GUILayout.Button("Download")){
//LoadTexture("http://download.unity3d.com/webplayer/images/unity-icon-big.jpg");
LoadTexture("http://205.196.123.154/8tbwv4bmbj5g/49sddaa4vkxadr1/CtoJS.unitypackage");
}
texture = EditorGUI.ObjectField(Rect(3,60,200,20),"Add a Texture:",texture,Texture);
if(texture){
EditorGUI.DrawPreviewTexture(Rect(25,150,100,100),texture);
}
/*if(texture2){
EditorGUI.DrawPreviewTexture(Rect(25,252,100,100),texture2);
}
if(texture3){
EditorGUI.DrawPreviewTexture(Rect(25,353,100,100),texture3);
}*/
if(done){
if(GUI.Button(Rect(200,200,200,100),"Export")){
//loc = EditorUtility.OpenFolderPanel("Select animations folder...", "", "");
AssetDatabase.ExportPackage("Assets/Materials/Fade.mat", "Exported Test.unitypackage");
}
//
if(GUI.Button(Rect(200,400,200,100),"copy from")){
//lo = EditorUtility.OpenFolderPanel("Select animations folder...", "", "MAT");
lo = EditorUtility.OpenFilePanel("Hi","","png");
}
if(GUI.Button(Rect(500,300,50,30),"Start")){
FileUtil.CopyFileOrDirectoryFollowSymlinks(lo,loc);
}
if(GUI.Button(Rect(560,300,50,30),"To")){
//loc = EditorUtility.OpenFolderPanel("Select animations folder...", "","");
loc = EditorUtility.OpenFolderPanel("lol","","");
}
//
if(GUI.Button(Rect(500,200,200,100),"Create Asset")){
AssetDatabase.CreateAsset(www.texture, "Assets/MyMaterial.mat");
}
}
}
function OnEnable(){
// LoadTexture("http://download.unity3d.com/webplayer/images/unity-icon-big.jpg");
done = false;
}
function LoadTexture(url)
{
www = new WWW(url);
#if UNITY_EDITOR
if (!EditorApplication.isPlaying)
EditorApplication.update = MyUpdate;
else
WaitForDownload();
#else
WaitForDownload();
#endif
}
#if UNITY_EDITOR
function MyUpdate ()
{
if (www.isDone)
{
EditorApplication.update = null;
LoadCompleted();
}
}
#endif
function WaitForDownload(){
yield www;
LoadCompleted();
}
function LoadCompleted(){
//texture = www.texture;
//AssetDatabase.CreateAsset(www.assetBundle,"Assets/swag.unitypackage");
//Debug.Log("name = "+www.bytes.ToString);
File.WriteAllBytes("C:\Users\koneo\Desktop\swagtest.unitypackage",www.bytes);
done = true;
}
}
Answer by Bunny83 · Jan 23, 2013 at 11:35 AM
You have to escape the backslashes!. The backslash is the escape character in C# / UnityScript / C++ / ...
You need it like this:
"C:\\Users\\koneo\\Desktop\\swagtest.unitypackage"
Answer by DeveshPandey · Jan 23, 2013 at 11:19 AM
Hello, You have missed a back slash after C:...
try this:
File.WriteAllBytes("C:\\Users\koneo\Desktop\swagtest.unitypackage",www.bytes);
I still get the error, if you could copy my code above and make it work, it would be awesome! :)
oh sorry I'm still missing backslash, I want to say that :
File.WriteAllBytes("C:\\\\Users\\koneo\\Desktop\\swagtest.unitypackage",www.bytes);
It will be worked... :)
Your answer
Follow this Question
Related Questions
Using EditorUtility.OpenFilePanel outside editor? 1 Answer
Saving 3D color array to file 1 Answer
Save List in BinaryFormat 0 Answers
Save GUI List to my Text File 0 Answers
Saving GameObject to file 2 Answers