1313using System . Reflection ;
1414using Object = UnityEngine . Object ;
1515using UnityEditor . Experimental . AssetImporters ;
16+ using UnityEditorInternal ;
17+ using Unity . CodeEditor ;
1618
1719namespace UnityEditor
1820{
@@ -86,8 +88,16 @@ static void PostprocessAllAssets(string[] importedAssets, string[] addedAssets,
8688 }
8789
8890 Profiler . BeginSample ( "SyncVS.PostprocessSyncProject" ) ;
89- ///@TODO: we need addedAssets for SyncVS. Make this into a proper API and write tests
90- CodeEditorProjectSync . PostprocessSyncProject ( importedAssets , addedAssets , deletedAssets , movedAssets , movedFromPathAssets ) ;
91+ #pragma warning disable 618
92+ if ( ScriptEditorUtility . GetScriptEditorFromPath ( CodeEditor . CurrentEditorInstallation ) == ScriptEditorUtility . ScriptEditor . Other )
93+ {
94+ CodeEditorProjectSync . PostprocessSyncProject ( importedAssets , addedAssets , deletedAssets , movedAssets , movedFromPathAssets ) ;
95+ }
96+ else
97+ {
98+ ///@TODO: we need addedAssets for SyncVS. Make this into a proper API and write tests
99+ SyncVS . PostprocessSyncProject ( importedAssets , addedAssets , deletedAssets , movedAssets , movedFromPathAssets ) ;
100+ }
91101 Profiler . EndSample ( ) ;
92102 }
93103
@@ -100,6 +110,67 @@ static void PreprocessAssembly(string pathName)
100110 }
101111 }
102112
113+ //This is undocumented, and a "safeguard" for when visualstudio gets a new release that is incompatible with ours, so that users can postprocess our csproj to fix it.
114+ //(or just completely replace them). Hopefully we'll never need this.
115+ static internal void CallOnGeneratedCSProjectFiles ( )
116+ {
117+ object [ ] args = { } ;
118+ foreach ( var method in AllPostProcessorMethodsNamed ( "OnGeneratedCSProjectFiles" ) )
119+ {
120+ InvokeMethod ( method , args ) ;
121+ }
122+ }
123+
124+ //This callback is used by C# code editors to modify the .sln file.
125+ static internal string CallOnGeneratedSlnSolution ( string path , string content )
126+ {
127+ foreach ( var method in AllPostProcessorMethodsNamed ( "OnGeneratedSlnSolution" ) )
128+ {
129+ object [ ] args = { path , content } ;
130+ object returnValue = InvokeMethod ( method , args ) ;
131+
132+ if ( method . ReturnType == typeof ( string ) )
133+ content = ( string ) returnValue ;
134+ }
135+
136+ return content ;
137+ }
138+
139+ // This callback is used by C# code editors to modify the .csproj files.
140+ static internal string CallOnGeneratedCSProject ( string path , string content )
141+ {
142+ foreach ( var method in AllPostProcessorMethodsNamed ( "OnGeneratedCSProject" ) )
143+ {
144+ object [ ] args = { path , content } ;
145+ object returnValue = InvokeMethod ( method , args ) ;
146+
147+ if ( method . ReturnType == typeof ( string ) )
148+ content = ( string ) returnValue ;
149+ }
150+
151+ return content ;
152+ }
153+
154+ //This callback is used by UnityVS to take over project generation from unity
155+ static internal bool OnPreGeneratingCSProjectFiles ( )
156+ {
157+ object [ ] args = { } ;
158+ bool result = false ;
159+ foreach ( var method in AllPostProcessorMethodsNamed ( "OnPreGeneratingCSProjectFiles" ) )
160+ {
161+ object returnValue = InvokeMethod ( method , args ) ;
162+
163+ if ( method . ReturnType == typeof ( bool ) )
164+ result = result | ( bool ) returnValue ;
165+ }
166+ return result ;
167+ }
168+
169+ private static IEnumerable < MethodInfo > AllPostProcessorMethodsNamed ( string callbackName )
170+ {
171+ return GetCachedAssetPostprocessorClasses ( ) . Select ( assetPostprocessorClass => assetPostprocessorClass . GetMethod ( callbackName , BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Static ) ) . Where ( method => method != null ) ;
172+ }
173+
103174 internal class CompareAssetImportPriority : IComparer
104175 {
105176 int IComparer . Compare ( System . Object xo , System . Object yo )
@@ -193,6 +264,16 @@ static void CleanupPostprocessors()
193264 }
194265 }
195266
267+ static bool ImplementsAnyOfTheses ( Type type , string [ ] methods )
268+ {
269+ foreach ( var method in methods )
270+ {
271+ if ( type . GetMethod ( method , BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) != null )
272+ return true ;
273+ }
274+ return false ;
275+ }
276+
196277 [ RequiredByNativeCode ]
197278 static string GetMeshProcessorsHashString ( )
198279 {
@@ -207,11 +288,20 @@ static string GetMeshProcessorsHashString()
207288 {
208289 var inst = Activator . CreateInstance ( assetPostprocessorClass ) as AssetPostprocessor ;
209290 var type = inst . GetType ( ) ;
210- bool hasPreProcessMethod = type . GetMethod ( "OnPreprocessModel" , BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) != null ;
211- bool hasPostprocessMeshHierarchy = type . GetMethod ( "OnPostprocessMeshHierarchy" , BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) != null ;
212- bool hasPostProcessMethod = type . GetMethod ( "OnPostprocessModel" , BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) != null ;
291+ bool hasAnyPostprocessMethod = ImplementsAnyOfTheses ( type , new [ ]
292+ {
293+ "OnPreprocessModel" ,
294+ "OnPostprocessMeshHierarchy" ,
295+ "OnPostprocessModel" ,
296+ "OnPreprocessAnimation" ,
297+ "OnPostprocessAnimation" ,
298+ "OnPostprocessGameObjectWithAnimatedUserProperties" ,
299+ "OnPostprocessGameObjectWithUserProperties" ,
300+ "OnPostprocessMaterial" ,
301+ "OnAssignMaterialModel"
302+ } ) ;
213303 uint version = inst . GetVersion ( ) ;
214- if ( version != 0 && ( hasPreProcessMethod || hasPostprocessMeshHierarchy || hasPostProcessMethod ) )
304+ if ( version != 0 && hasAnyPostprocessMethod )
215305 {
216306 versionsByType . Add ( type . FullName , version ) ;
217307 }
0 commit comments