Example #1
0
        /// <summary>
        /// Removes a component by type.
        /// </summary>
        public void RemoveComponent(Type type)
        {
            SceneComponent c = GetComponent(type);

            if (c != null)
            {
                componentContainer.RemoveService(type);
                components.Remove(c);
                c.SetScene(null);
            }
        }
Example #2
0
        /// <summary>
        /// Adds a component to this scene.
        /// </summary>
        public void AddComponent(SceneComponent component)
        {
            Type type = component.GetType();

            if (HasComponent(type))
            {
                throw new InvalidOperationException("GameObject already contains a component of type " + type.FullName);
            }

            if (component.Scene != null && component.Scene != this)
            {
                component.Scene.RemoveComponent(type);
            }

            componentContainer.AddService(type, component);
            components.Add(component);
            component.SetScene(this);
        }