LittleCodingFox / Unity-CSharp-Mod

Native C# Modding support for Unity
MIT License
13 stars 4 forks source link

Non Monobehaviour scripts #2

Open z3t0 opened 8 years ago

z3t0 commented 8 years ago

I seem to have hit a wall, if we only use MonoBehaviour scripts (Moddable) then how would we go about creating classes and we want to create multiple instances of?

For example,

public class Block{
  string name;
  public Block(string name)
{
 this.name = name;
}
}

And then in another script:

Block block = new Block();

This would fail if Block inherited MonoBehaviour as monobehaviour scripts cannot be "instantiated". I think the limitation for this lies within System.Activator.CreateInstance, but haven't figured out a work around yet.

z3t0 commented 8 years ago

This seems to be a common issue and I have also created a similar issue

z3t0 commented 8 years ago
System.Activator.CreateInstance(type, param1, param2, param3 ...)

Seems to be work, now just need to find a nice way to integrate this solution in an intuitive way!

z3t0 commented 8 years ago

This is just a thought but it might work by simply removing the MonoBehaviour on Moddable

z3t0 commented 8 years ago

Hmm actually nevermind, I think it should work if we just ignore the non mono scripts...