Sorry for bumping this but I have a question regarding saving a file to Resources folder.
Currently it only works if you run the game inside the editor. Is it possible to run ES2.Save to the Resources folder without clicking the Play button? I'm working on an editor window that process files, encrypt them and save them into Resources folder. It isn't convenient having to press play in order to do that.
You can use Easy Save in Editor scripts in the same way you can use it from Game scripts. So you can write your save code in an Editor script and run that, or even call the save code in your game scripts from an editor script.
sry for bumping this again as I don't think this is working? when I try to save using editor window, an error message pops out saying "Destroy may not be called from edit mode! Use DestroyImmediate instead." and the function aborted. Am I doing anything wrong?
public void RefreshWindow()
Debug.Log("RefreshWindow called for ItemGenreEditor window.");
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
if (Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.OSXPlayer)
path = path+ "/GameProjData/Item/GenreList.txt";
else if (Application.platform == RuntimePlatform.WindowsPlayer)
path = path + @"\GameProjData\Item\GenreList.txt";
Debug.Log("Error: unexpected platform.");
string pathWithTag = path + "?tag=allGenreNames";
Debug.Log("file and tag exist.");
allGenres = ES2.LoadList<string>(pathWithTag);
Debug.Log("Error: file found but no data in it. creating one.");
ES2.Save(new List<string>(), path);
all problem is pointing to this line:
allGenres = ES2.LoadList<string>(pathWithTag); (allGenres is a List<string> declared outside of the function.)
if I don't click play, error message would be ""Destroy may not be called from edit mode! Use DestroyImmediate instead.". if I do press play, a different error message would say "EndOfStreamException: Failed to read past end of stream.".
ah sorry its my other script messed it up. its all been solve now.
actually, after some more testing I was able to recreate the problem: if I open Unity and refresh the editor window (using the script i posted above) before pressing the play button, the error message about "destroy" would pop up. but once I press the play button, even if I press it again to stop playing, there won't be any errors using ES.Load functions.
Destroy may not be called from edit mode! Use DestroyImmediate instead.
Also think twice if you really want to destroy something in edit mode. Since this will destroy objects permanently.
BlockManager:WriteData() (at Assets/Editor/Code/BlockManager.cs:241)
BlockManager:AddBlock() (at Assets/Editor/Code/BlockManager.cs:179)
BlockManager:OnGUI() (at Assets/Editor/Code/BlockManager.cs:134)
And it is fixed when I hit play and then exit play mode, but it's still an inconvenience.
As a note, when this error occurs it creates an ES2Init(Clone) object in my hierarchy.
Had another bash at this and I've managed to replicate your error. Looks like the initialisation isn't getting called in Editor under certain circumstances, so it's necessary to initialise it yourself before calling ES2 methods.
Currently the easiest way to do this is to call this before using ES2 in the Editor:
GameObject init = new GameObject();
But I'll change it so that in v2.54 you'll simply be able to do: