Search Unity

IL2CPP: Can Reflection find Interfaces for DLC power-ups?

Discussion in 'Scripting' started by bluefoxicy, Mar 17, 2016.

  1. bluefoxicy

    bluefoxicy

    Joined:
    Jan 2, 2015
    Posts:
    15
    I'm unclear on the state of IL2CPP. Simple question: does the normal System.Reflection facility work as expected?

    I'm structuring my game to use decorators to implement a lot of functionality. Notably:
    • Enemies have Behavior and Controller. The Controller takes actual action (jump, attack, etc.); Behavior decides what action to take (AI, player input, etc.); and
    • Player power-ups are essentially Decorators which act as a Behavior and a Controller. The Decorator attaches to the Controller as a behavior, and the Behavior attaches to the Decorator as if the Decorator were a Controller.
    Among other things, this allows me to enable things like new weapons by putting them in line with the player's input Behavior. Essentially, GamepadBehavior->PlayerBehaviorInterpreter->PlayerController; you get a new missile upgrade, GampadBehavior->PlayerBehaviorInterpreter->PlayerMissileUpgrade->PlayerController.

    There are other ways to do this (e.g. stack a set of interpreters in a List<T> and iterate through them, rather than passing upwards through a call); each design has its merits.

    Point:
    • An enemy is an entity with movement and attacks
    • A player is an entity with movement and attacks
    • The real difference is whether Input or AI is hooked up as the Behavior (e.g. in a Megaman-style game, you could let the player play as any type of enemy or Robot Master by swapping in an input controller)
    • You can add enemies by providing a class with an interface
    • You can add power-ups by providing a class with an interface
    So DLC can add power-ups and new enemies by providing a class with an interface located by reflection!

    I assume this should still work as IL2CPP rolls out.
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    @bluefoxicy

    Yes, I would expect all of this to work with IL2CPP. It supports System.Reflection, just not System.Reflection.Emit. I would keep in mind that code stripping might become a problem though, as the IL2CPP toolchain will pretty aggressively strip out any code it cannot prove is called at compile time.

    Code stripping is only applied to assemblies in your project, not to anything created from script files. But if you are using assemblies along with reflection, you may want to consider using a link.xml file as described here: http://docs.unity3d.com/Manual/iphone-playerSizeOptimization.html.