public NebulaBehaviour AddComponentNoAwake(Type type, NebulaBehaviour behaviour) { MethodInfo method = typeof(NebulaBehaviour).GetMethod("SetNebulaObject", BindingFlags.NonPublic | BindingFlags.Instance); method.Invoke(behaviour, new object[] { this }); behaviours.AddBehaviour(type, behaviour); return(behaviour); }
/// <summary> /// Not templated version of adding component to object /// </summary> /// <param name="type">Type of component to added</param> /// <returns>Newly created component</returns> public NebulaBehaviour AddComponent(Type type) { NebulaBehaviour behaviour = Activator.CreateInstance(type) as NebulaBehaviour; MethodInfo method = typeof(NebulaBehaviour).GetMethod("SetNebulaObject", BindingFlags.NonPublic | BindingFlags.Instance); method.Invoke(behaviour, new object[] { this }); behaviours.AddBehaviour(type, behaviour); behaviour.Awake(); return(behaviour); }
public object SetComponentAsNew(Type type, NebulaBehaviour component) { object oldComponent = null; if (behaviours.ContainsBehaviour(type)) { oldComponent = behaviours.GetBehaviour(type); } MethodInfo method = typeof(NebulaBehaviour).GetMethod("SetNebulaObject", BindingFlags.NonPublic | BindingFlags.Instance); method.Invoke(component, new object[] { this }); //replace to collection behaviours.SetBehaviour(type, component); if (type == typeof(NebulaTransform)) { transform = component as NebulaTransform; } if (type == typeof(NebulaObjectProperties)) { properties = component as NebulaObjectProperties; } return(oldComponent); }