I'm writing an editor script which needs to save values to a text file, and I need the path of that script so that I can save the text file in the same folder.
I have tried the following with no luck:
Now Unity already shows me the path of this script in the Debug window, when the Debug.Log() appears, telling me where the Log came from, so it knows where it is, but I can't access it...I feel like a complete idiot right now!
Thanks for your time guys, any help will be very appreciated as always! Stephane
asked May 19 '12 at 09:55 PM
You tried to get an asset path from an instance of a normal .NET / Mono class which of course doesn't work ;) The class / type that is represented by a MonoScript is not an asset, it's just a mono class. You need to use MonoScript.FromScriptableObject to get the MonoScript asset that contains your desired type. Note that the types Editor (for custom inspectors) and EditorWindow are derived from ScriptableObject.
To get the MonoScript of a "normal" MonoBehaviour class, you would use MonoScript.FromMonoBehaviour
As final hint: The type MonoScript is derived from TextAsset, so your script is just a text file from Unity's point of view. However when the MonoScript asset is compiled, you can get the System.Type object for the class that is represented by this script with MonoScript.GetClass.