I have a version 4.x project that uses IronPython so I can make python scene building scripts and an interactive python console work for my game. All this was working fine (even as an .exe) until I came to try it in the new version 5 of Unity. My build scripts were able to add MonoBehaviour components to dynamically created GameObjects using AddComponent(“MyScriptComponent”) but this usage has now been removed from the Unity 5 API.
I can use IronPython’s generics syntax which looks like this: AddComponentMyScriptComponent but I have to import the reference for the relevant assembly containing my script at the top of my Python build files. This works fine for any DLLs I’ve made with script components in them. The problem comes when I try to import the Assembly-CSharp.dll file for any C# script component files that reside in Unity’s Assets folder. I can add the assembly reference at the top of my Python build script but then Python will not let me use: import Assembly-CSharp to load the module as it moans about the ‘-’ sign in the name.
No amount of Python hackery seems to work despite trawling the web and trying anything I could find. All I really need to do is to get Unity/MonoDevelop to use a different name for the assembly such as AssemblyCSharp and all should work fine but I cannot seem to make it do this. I did try changing the options for the assembly via MonoDevelop so it renamed it and built it as a differently named assembly and whilst this seemed to work for loading the assembly into the clr, Python said it could not find the module afterwards.
My alternative approach is to make an extension method so I can still use the older, deprecated syntax for AddComponent.
Any thoughts anyone?