In the following script how can I get the path to the script in the Assets folder?
using UnityEngine;
using System.Reflection;
using System.IO;
using UnityEditor;
[InitializeOnLoad]
public class MyWindow : ScriptableObject
{
static string pathToScript;
[MenuItem("Window/My Window")]
static void Open()
{
// Do something with `pathToScript`
}
// This function is NOT called when the object is loaded.
protected void OnEnable()
{
var script = MonoScript.FromScriptableObject( this );
pathToScript = AssetDatabase.GetAssetPath( script );
}
}
The problem is that OnEnabled it's not called, also it seems the only way to get a path to the script is through AssetDatabase.GetAssetPath which requires an instance.
The version in Unity is 5.5.0b3.
