Search Unity

Create a C# class at runtime in Unity

Discussion in 'Scripting' started by dotSnipe, Dec 19, 2012.

  1. dotSnipe

    dotSnipe

    Joined:
    Nov 9, 2011
    Posts:
    20
    Hello,

    I was wondering how could I create a C# class during runtime either from a Xml or a String or any other method.

    I am aware of some of the risks, and I am aware of the posibillity to include the class properties in a dictionary of a predefined class.
    The Dictionary aproach is not what I am looking for.

    I am literally looking for a C# class generated dynamically at runtime.

    Thank you.
     
  2. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
  3. dotSnipe

    dotSnipe

    Joined:
    Nov 9, 2011
    Posts:
    20
    Thank you. I will check it out and try it.

    I assume I can apply the example in Unity ?

    Will it work if I deploy to iOS and Android ?
     
  4. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,657
    Definitely not iOS; it'd be a breach of Apple's developer agreement.
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Reflection doesn't really work on iOS because of the AOT compilation.

    --Eric
     
  6. dotSnipe

    dotSnipe

    Joined:
    Nov 9, 2011
    Posts:
    20
    Thank you all for a prompt reply.