示例#1
0
        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);
        }
示例#2
0
        /// <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);
        }
示例#3
0
        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);
        }