public override void Action(int instanceId, string pathName, string resourceFile) { // https://github.com/Unity-Technologies/UnityCsReference/blob/master/Editor/Mono/ProjectWindow/ProjectWindowUtil.cs#L146 // https://github.com/Unity-Technologies/UnityCsReference/blob/master/Editor/Mono/ProjectWindow/ProjectWindowUtil.cs#L473 string className = Path.GetFileNameWithoutExtension(pathName); string code = generator.GenerateCode(className); string fullPath = Path.GetFullPath(pathName); File.WriteAllText(fullPath, code); AssetDatabase.ImportAsset(pathName); generator.genScript = AssetDatabase.LoadAssetAtPath <MonoScript>(pathName); }