/// <summary>
        /// Add a component to this Camera Controller.
        /// </summary>
        /// <param name="component">The component to add.</param>
        public void AddCameraComponent(CameraComponent component)
        {
            if (ComponentsAdded)
            {
                throw new InvalidOperationException("You cannot add a component to the CameraController after components have been added.");
            }

            if (IsInitialized)
            {
                throw new InvalidOperationException("You cannot add a component to the CameraController after it has been initialized.");
            }

            if (component != null)
            {
                Type type = component.GetType();

                if (type != null)
                {
                    if (_components.ContainsKey(type))
                    {
                        throw new ArgumentException(string.Format("The component of type '{0}' has already been added to this Camera Controller.", type));
                    }

                    _components.Add(type, component);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Sets the public fields of the matching attached component on this Camera Controller to the fields of the given component.
        /// This throws if the given component's type is not attached to the Camera Controller.
        /// This does not replace this controller's component with the given component.
        /// </summary>
        /// <param name="component">The given component whose public fields you want.</param>
        protected void CopyPublicFields(CameraComponent component)
        {
            Type type = component.GetType();

            if (!_components.ContainsKey(type))
            {
                throw new ArgumentException(string.Format("The component of type '{0}' has not yet been added to this Camera Controller.", type));
            }

            _components[type].CopyPublicFields(component);
        }
Пример #3
0
        public override void BindToEntity(Entity source)
        {
            base.BindToEntity(source);
            if (!source.TryGetComponent(out camera))
            {
                throw new InvalidOperationException(string.Format("'{0}' does not contain a {1}", source.Name, camera.GetType()));
            }

            keyboardService = Services.GetService <IKeyboardService>();

            if (CameraBindings == null)
            {
                CameraBindings = new[]
                {
                    new KeyBinding(Keys.W, CameraAction.MoveForward, ButtonStateFlags.Down),
                    new KeyBinding(Keys.S, CameraAction.MoveBackward, ButtonStateFlags.Down),
                    new KeyBinding(Keys.A, CameraAction.StrafeLeft, ButtonStateFlags.Down),
                    new KeyBinding(Keys.D, CameraAction.StrafeRight, ButtonStateFlags.Down),
                    new KeyBinding(Keys.Q, CameraAction.HoverDown, ButtonStateFlags.Down),
                    new KeyBinding(Keys.E, CameraAction.HoverUp, ButtonStateFlags.Down),
                    new KeyBinding(Keys.Z, CameraAction.YawLeft, ButtonStateFlags.Down),
                    new KeyBinding(Keys.C, CameraAction.YawRight, ButtonStateFlags.Down)
                }
            }
            ;
        }