コード例 #1
0
        } // AddComponent

        #endregion

        #region Remove Component

        /// <summary>
        /// Removes a component to the game object.
        /// </summary>
        /// <remarks>
        /// A component is not really destroyed, is recycled, it returns to the component pool.
        /// </remarks>
        /// <typeparam name="TComponentType">Component Type</typeparam>
        public override void RemoveComponent <TComponentType>()
        {
            #region Transform

            if (typeof(TComponentType) == typeof(Transform2D))
            {
                throw new ArgumentException("Game Object 2D: Unable to remove the 2D transform component. The transform component can’t be replaced or removed.");
            }
            if (typeof(TComponentType) == typeof(Transform3D))
            {
                throw new ArgumentException("Game Object 2D: Unable to remove the 3D transform component. A 2D Game Object does not work in 3D.");
            }

            #endregion

            #region HUD Text

            if (typeof(TComponentType) == typeof(HudText))
            {
                if (hudTextAccessor == null)
                {
                    throw new InvalidOperationException("Game Object 2D: Unable to remove the HUD text component. There is not one.");
                }
                HudText.Uninitialize();
                Components.Remove(HudText);
                HudText.ComponentPool2D.Release(hudTextAccessor);
                HudText         = null;
                hudTextAccessor = null;
            }

            #endregion

            #region HUD Texture

            if (typeof(TComponentType) == typeof(HudTexture))
            {
                if (hudTextureAccessor == null)
                {
                    throw new InvalidOperationException("Game Object 2D: Unable to remove the HUD texture component. There is not one.");
                }
                HudTexture.Uninitialize();
                Components.Remove(HudTexture);
                HudTexture.ComponentPool2D.Release(hudTextureAccessor);
                HudTexture         = null;
                hudTextureAccessor = null;
            }

            #endregion

            #region Video Renderer

            if (typeof(TComponentType) == typeof(VideoRenderer))
            {
                if (videoRendererAccessor == null)
                {
                    throw new InvalidOperationException("Game Object 2D: Unable to remove the video renderer component. There is not one.");
                }
                VideoRenderer.Uninitialize();
                Components.Remove(VideoRenderer);
                VideoRenderer.ComponentPool.Release(videoRendererAccessor);
                VideoRenderer         = null;
                videoRendererAccessor = null;
            }

            #endregion

            #region Line Renderer

            if (typeof(TComponentType) == typeof(LineRenderer))
            {
                if (lineRendererAccessor == null)
                {
                    throw new InvalidOperationException("Game Object 2D: Unable to remove the line renderer component. There is not one.");
                }
                LineRenderer.Uninitialize();
                Components.Remove(LineRenderer);
                LineRenderer.ComponentPool2D.Release(lineRendererAccessor);
                LineRenderer         = null;
                lineRendererAccessor = null;
            }

            #endregion

            #region Script

            if (typeof(Script).IsAssignableFrom(typeof(TComponentType)))
            {
                Component script = XNAFinalEngine.Components.Script.ContainScript <TComponentType>(this);
                if (script == null)
                {
                    throw new ArgumentException("Game Object 2D: Unable to remove the script component. There is not one.");
                }
                script.Uninitialize();
                Components.Remove(script);
                scripts.Remove((Script)script);
            }

            #endregion
        } // RemoveComponent