I’m working on an asset that creates a text file and I don’t want to force the user to change the platform to standalone, so I wouldn’t want to use System.IO.File.CreateText which is only available on Standalone.
I thought AssetDatabase would be the solution but I couldn’t find any tool to edit a TextAsset and every solution I found suggested editing the file using System.IO.File.
Is there a way to edit a text file in editor that is independent of the current build platform?
I found the answer!
I needed to encode it as bytedata and write it that way into the file, here is my code:
UTF8Encoding tEncod = new UTF8Encoding();
byte tByteData = tEncod.GetBytes(aContent);
FileStream tFileStream = null;
tFileStream = new FileStream(aPath, FileMode.Open);
tFileStream = new FileStream(aPath, FileMode.Create);
tFileStream.Write(tByteData, 0, tByteData.Length);
This will work independently of the build platform.
I hope it helps someone.