Exemplo n.º 1
0
 /// <summary>
 /// Adds a GameoObjectComponent to this GameObject.
 /// </summary>
 /// <param name="component"></param>
 public GameObject AddComponent(GameObjectComponent component)
 {
     EnforceSingleComponent <Transform>(component);
     EnforceSingleComponent <Renderer>(component);
     component.AttachGameObject(this);
     _components.Add(component);
     return(this);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Checks for more than one of the provided component type and throws and exception if one already exists on this GameObject.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="component"></param>
        private void EnforceSingleComponent <T>(GameObjectComponent component) where T : GameObjectComponent
        {
            if (!(component is T))
            {
                return;
            }

            if (this.GetComponent <T>() == null)
            {
                return;
            }

            throw new InvalidOperationException(String.Format("GameObject my only have 1 {0} component", typeof(T).Name));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Removes a GameObjectComponent from this GameObject.
        /// </summary>
        /// <param name="component"></param>
        /// <remarks>Currently only removes behaviors TODO: remove any</remarks>
        public void RemoveGameObjectComponent(GameObjectComponent component)
        {
            if (component is Behavior)
            {
                _behaviors.Remove(component as Behavior);
                component.GameObject = null;
            }
            if (component is Renderer)
            {
                this.Renderer = null;
            }

            if (component is Collider)
            {
                this.Collider = null;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Adds or updates a component for this GameObject.
        /// </summary>
        /// <param name="component"></param>
        internal void AddGameObjectComponent(GameObjectComponent component)
        {
            component.GameObject = this;

            this.Transform       = component as Transform ?? Transform;
            this.Renderer        = component as Renderer ?? Renderer;
            this.Collider        = component as Collider ?? Collider;
            this.RigidBody       = component as RigidBody ?? RigidBody;
            this.AudioSource     = component as AudioSource ?? AudioSource;
            this.ParticleEmitter = component as ParticleEmitter ?? ParticleEmitter;
            this.StateMachine    = component as BehaviorStateMachine ?? StateMachine;
            if (component is Behavior)
            {
                _behaviors.Add(component as Behavior);
            }

            component.Initialize();
        }
Exemplo n.º 5
0
 /// <summary>
 /// Removes a GameObjectComponent from this GameObject.
 /// </summary>
 /// <param name="component"></param>
 /// <remarks>Currently only removes behaviors TODO: remove any</remarks>
 public void RemoveGameObjectComponent(GameObjectComponent component)
 {
     if (component is Behavior)
     {
         _behaviors.Remove(component as Behavior);
         component.GameObject = null;
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Adds or updates a component for this GameObject.
        /// </summary>
        /// <param name="component"></param>
        internal void AddGameObjectComponent(GameObjectComponent component)
        {
            component.GameObject = this;

            this.Transform = component as Transform ?? Transform;
            this.Renderer = component as Renderer ?? Renderer;
            this.Collider = component as Collider ?? Collider;
            this.RigidBody = component as RigidBody ?? RigidBody;
            this.AudioSource = component as AudioSource ?? AudioSource;
            this.ParticleEmitter = component as ParticleEmitter ?? ParticleEmitter;
            this.StateMachine = component as StateMachine ?? StateMachine;
            this.Animations = component as AnimationManager ?? Animations;
            if (component is Behavior)
                _behaviors.Add(component as Behavior);

            component.Initialize();
        }
Exemplo n.º 7
0
 /// <summary>
 /// Removes a GameObjectComponent from this GameObject.
 /// </summary>
 /// <param name="component"></param>
 public void RemoveComponent(GameObjectComponent component)
 {
     _components.Remove(component);
     component.DetachGameObject(this);
 }
Exemplo n.º 8
0
 public GameObject Component(GameObjectComponent component)
 {
     _gameObject.AddGameObjectComponent(component);
     return(_gameObject);
 }
 public GameObject Component(GameObjectComponent component)
 {
     _gameObject.AddGameObjectComponent(component);
     return _gameObject;
 }