Part 19 of this series started to allow our C++ game code to derive from C# classes and implement C# interfaces. The first step was to override methods as they’re the most common. Today we’ll tackle the second-most common: properties. We’ll also handle indexers, which are like properties with more parameters. Read on to see how to use this and how it works behind the scenes.
Posts Tagged P/Invoke
The last time we looked at performance was way back in part four of the series. Ever since then we’ve been relentlessly adding more and more features to the C++ scripting system. So today we’ll take a break from feature additions to improve the system’s performance in a couple of key areas.
This week’s article adds another major feature to the C++ scripting system: delegates. These are vital so C++ game code can use features like Unity’s UI system (a.k.a. UGUI). Without them, we wouldn’t be able to handle button clicks or other UI events. So read on to learn how these were implemented in the GitHub project.
The series continues by adding support for a major feature: arrays. These are used very frequently throughout the Unity and .NET APIs and the lack of support for them has been a big missing piece of the puzzle for most games. The GitHub project has been updated to support single- and multi-dimensional arrays. Read on to learn how this support was implemented!
Today’s article continues the series by adding support for C++ to call the various overloaded operators and indexers that are written in C#. This includes support for all 24 overloadable operators in C# plus the
implicit type conversion operators. Indexers aren’t quite overloaded operators, but they allow for array-like indexing into C# types so they’re included today. Read on to learn how all this support was implemented in the GitHub project!
Like them or not, exceptions are the standard way of handling programming errors in C#. We need to be able to catch C# exceptions in our C++ code so we can gracefully recover from them. Likewise, we need uncaught C++ exceptions to behave like unhandled C# exceptions: display an error and move on instead of crashing. Today’s article continues the series by implementing both those features in the GitHub project and explaining how that implementation was done.
The series to build a viable system to write Unity scripts in C++ continues! While these 11 articles have covered a lot of ground toward making a usable C++ scripting system, there’s still a lot to do. Writing the code for these articles takes quite a lot of time, so today I’m officially calling for collaborators on the GitHub project. If you’d like to join in, please leave a comment, send an e-mail, or submit a pull request. There’s plenty to do and your help would be greatly appreciated! Aside from that, today’s article is all about adding support for struct and enum types so we can use types like
TextureFormat from our C++ scripts.
The series continues this week by addressing a pretty important issue. Previously, we were limited to doing all our work in just two C++ functions:
PluginUpdate. This isn’t at all the normal way to work in Unity. It’d be a lot more natural to write our code in
MonoBehaviour classes. So today we’ll come up with some tricks to allow us to write our
MonoBehaviour code in C++ so we are truly scripting in C++.
Last week in the series we took a step back to verify that the C++ plugin’s performance was acceptable. With that confirmed, we’ll continue this week by making our programming lives easier. One pain point so far has been with exposing new Unity APIs to C++. It’s not that it’s difficult to do this, but there’s a lot of boilerplate required. That boilerplate takes time to write and it’s easy to make mistakes copying and pasting existing functions. So this week’s article introduces a code generator that will write the boilerplate for us! We’ll also reorganize the project a little so the code that supports C++ scripting is separated away from our game code. That’ll make it easy to add support for C++ scripting to any Unity project.