Guest User

Untitled

a guest
Jan 19th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. public Dictionary<string, MonoBehaviour> registry;
  2. public MonoBehaviour testComponent;
  3.  
  4. void Start(){
  5. registry = new Dictionary<string, MonoBehaviour> ();
  6. registry.Add ("TestComponent", testComponent);
  7. }
  8.  
  9. public MonoBehaviour GetScript(string name)
  10. {
  11. return registry[name];
  12. }
  13.  
  14. foreach (string comp in blockInfo.components) {
  15.  
  16. //For each of the components that need to be added
  17.  
  18. gameObject.AddComponent(ScriptMaster.compReg.GetScript(comp));
  19.  
  20. //I know this is incorrect, but the idea is there
  21. }
  22.  
  23. //you should be able to get the correct name by typeof(T).FullName
  24. // or instance.GetType().FullName
  25. foreach (string compTypeName in blockInfo.components)
  26. gameObject.AddComponent(Activator.CreateInstance(null, compTypeName ).Unwrap());
Add Comment
Please, Sign In to add comment