Hi all!, i made an editor script which allows players to snap objects together and creating a new object all together Now i want them to allow to save their creation in a folder as a loadable item like a prefab. What is the best way of doing so. I believe LoadAssetAtPath and PrefabUtility can only be used within unity’s editor is there another way of doing this?
Sae your data in an object you derive from ScriptableObject.
You can save your data with:
AssetDatabase.CreateAsset(asset, "Assets/MyData.asset");
AssetDatabase.SaveAssets();
And if you click on your asset file, you can see the Editor for it in the Inspector… which you can customize of course like for other Types.
Then you can drag those assets directly onto a
public YourClass data;
field or you can load it from the AssedDatabase like other Assets or from Resourcs-Folders during runtime.
The following may not be the best answer, but it is one answer.
This kind of stuff can usually done by sending raw data (although it is more work).
You’d save out the data then use this to rebuild the assets on load.
Obviously you could access “PlayerPrefs” to within limits, and in standalone mode possibly System.IO stuff:
public static bool WriteTextFile(string nData, string nAddress){
System.IO.File.WriteAllText(Application.dataPath + nAddress, nData);
AssetDatabase.ImportAsset (nAddress);
return(true);
}//nData is the string data, nAddress is the address of the file
I’m not sure how well this System.IO stuff works in exes/apps etc though. I know it flunks in web players for what I guess is security reasons (Web apps that write files are frowned upon), and it seems unreliable in the editor at this end (saved assets need manually re-imported). On the web, PHP would probably be your friend (you’d post your data and retrieve it from a server).
I hope that this is helpful, and would love to know if you found a more elegant solution.