Last active
August 29, 2015 14:14
-
-
Save uzzu/7062d25cf3021aa235e8 to your computer and use it in GitHub Desktop.
*-csharp.slnなソリューションを開くUnityEditor拡張
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Reflection; | |
using System.Linq; | |
using UnityEditor; | |
public static class SyncVsOnlyCSharp | |
{ | |
[MenuItem("Assets/Sync MonoDevelop Project (CSharp-Only)")] | |
public static void SyncMonoDevelopProject() | |
{ | |
AssetDatabase.Refresh(); | |
var editorAssembly = AppDomain.CurrentDomain.GetAssemblies() | |
.First(asm => asm.FullName.Contains("UnityEditor,")); | |
// SyncVS.Sync(); | |
var syncVsType = editorAssembly.GetType("UnityEditor.SyncVS"); | |
var synchronizerField = syncVsType.GetField( | |
"Synchronizer", | |
BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.GetField | |
); | |
var synchronizer = synchronizerField.GetValue(null); | |
var synchronizerType = synchronizer.GetType(); | |
var syncMethod = synchronizerType.GetMethod("Sync", BindingFlags.Instance | BindingFlags.Public); | |
syncMethod.Invoke(synchronizer, null); | |
// AssetPostprocessingInternal.CallOnGeneratedCSProjectFiles(); | |
var assetPostprocessingInternalType = editorAssembly.GetType("UnityEditor.AssetPostprocessingInternal"); | |
var callOnGeneratedCSProjectFilesMethod = assetPostprocessingInternalType.GetMethod( | |
"CallOnGeneratedCSProjectFiles", | |
BindingFlags.Static | BindingFlags.NonPublic | |
); | |
callOnGeneratedCSProjectFilesMethod.Invoke(null, null); | |
// if (InternalEditorUtility.inBatchMode) return; | |
var internalEditorUtilityType = editorAssembly.GetType("UnityEditorInternal.InternalEditorUtility"); | |
var inBatchModeProperty = internalEditorUtilityType.GetProperty( | |
"inBatchMode", | |
BindingFlags.Static | BindingFlags.Public | |
); | |
var inBatchMode = (bool) inBatchModeProperty.GetValue(null, null); | |
if (inBatchMode) | |
{ | |
return; | |
} | |
// InternalEditorUtility.OpenFileAtLineExternal(SyncVS.Synchronizer.SolutionFile(onlyCSharp), -1); | |
var openFileAtLineExternalMethod = internalEditorUtilityType.GetMethod( | |
"OpenFileAtLineExternal", | |
BindingFlags.Static | BindingFlags.Public | |
); | |
var solutionFileMethod = synchronizerType.GetMethod( | |
"SolutionFile", | |
BindingFlags.Instance | BindingFlags.NonPublic | |
); | |
var solutionFile = (string) solutionFileMethod.Invoke(synchronizer, new object[] { true }); | |
openFileAtLineExternalMethod.Invoke(null, new object[] { solutionFile, -1 }); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment