Пример #1
0
        /// <summary>
        /// Attempts to retrieve the attached component by type.
        /// </summary>
        public bool TryGetComponent <T>(out T component)
            where T : SceneComponent
        {
            SceneComponent c = FindComponent(typeof(T));

            if (c != null)
            {
                component = (T)c;
                return(true);
            }
            else
            {
                component = null;
                return(false);
            }
        }
Пример #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);
        }