public CameraController(string cameraName) { this.cameraName = cameraName; windowShowing = false; image = new VisionImage(); state = CameraState.FREE; }
public void PossessPlayer(GameObject player) { if (state == CameraState.FREE_FLOW) { if (player.CompareTag("Salesman")) { character = CharacterClass.SALESMAN; } else if (player.CompareTag("Shopper")) { character = CharacterClass.SHOPPER; } else if (player.CompareTag("Guard")) { character = CharacterClass.GUARD; } else if (player.CompareTag("Thief")) { character = CharacterClass.THIEF; } else return; PossessionScript ps = player.GetComponent<PossessionScript>(); ps.Possess(); possessedCharacter = player; attachedRotation = player.transform.rotation; attachedLocation = player.transform.position + attachedRotation * new Vector3(0, 1.85f, -2); freeFlyLocation = transform.position; freeFlyRotation = transform.rotation; state = CameraState.ATTACHING; tick = 0; } }
IEnumerator switchCameraRutine( CameraState from ) { float t = 0.0f; Vector3 fromPos, toPos; fromPos = quadForeground.transform.position; toPos = (from == CameraState.AR) ? vrPos : arPos; while (t < 1.0f) { quadForeground.transform.position = Vector3.Lerp (fromPos, toPos, t); t = t + 0.1f; yield return new WaitForSeconds(0.02f); } if (from == CameraState.VR) { Debug.Log("change camera to AR"); state = CameraState.AR; } else if (from == CameraState.AR) { Debug.Log("change camera to VR"); state = CameraState.VR; } yield return 0; }
//=================================================================================================================o // Remember the last camera state when climbing void DoClimb(string s) { if (s != "None") // While climbing { if (camState == CameraState.FirstPerson) { camState = CameraState.ThirdPerson; } else if (camState == CameraState.Orbit) { camState = CameraState.ThirdPerson; } else if (camState == CameraState.ThirdPerson) { return; } } else // Leaving climb modus { if (lastState == "FirstPerson") { camState = CameraState.FirstPerson; } else if (lastState == "ThirdPerson") { camState = CameraState.ThirdPerson; } else if (lastState == "Orbit") { camState = CameraState.Orbit; } } }
public override void Reset() { base.Reset(); m_Tween = m_StartTween; m_CameraState = CameraState.Enter; }
// Use this for initialization void Start () { combat = new CameraState(localCombatPosition,localCombatRotation); inventory = new CameraState(localInventoryPosition,localInventoryRotation); currentState = combat; desiredState = combat; }
// Update is called once per frame void Update () { //If the user turns left or right, change the enum if (Input.GetKey (KeyCode.D)) { direction = CameraState.Right; } else if (Input.GetKey (KeyCode.A)) { direction = CameraState.Left; } //call the method to handle moving the camera over time shiftSlow (direction); //Add shiftIndex to the X-value of the camera to move it transform.position = new Vector3 (toFollow.position.x + shiftIndex, toFollow.position.y, transform.position.z); //This code is for zooming the camera if((Input.GetAxis ("Mouse ScrollWheel") < 0f || Input.GetKey(KeyCode.PageDown))&& //If the user scrolls down this.GetComponent<Camera>().orthographicSize < 15f) //And the camera isn't zoomed too far out already { this.GetComponent<Camera>().orthographicSize += 0.5f; //Zoom out } if ((Input.GetAxis("Mouse ScrollWheel") > 0f|| Input.GetKey(KeyCode.PageUp)) && //If the user scrolls up this.GetComponent<Camera>().orthographicSize > 6.5) //And the camera isn't zoomed in too far already { this.GetComponent<Camera>().orthographicSize -= 0.5f; //Zoom in } }
// Update is called once per frame void Update() { _cameraState = _camera.CameraState; CalculateSpeed(); _animator.SetFloat(AnimatorConditions.AirVelocity, _airVelocity); switch (_cameraState) { case CameraState.Normal: // Allow player to rotate their character if (Input.GetAxis(PlayerInput.Horizontal) > 0.1f || Input.GetAxis(PlayerInput.Horizontal) < -0.1f) { _myTransform.Rotate(0f, Input.GetAxis(PlayerInput.Horizontal) * _rotationSpeed * Time.deltaTime, 0f); } // Check if character is grounded if (_controller.isGrounded == true) { _moveDirection = Vector3.zero; _airVelocity = 0f; _animator.SetBool(AnimatorConditions.IsGrounded, true); // Cache user input into variables _horizontal = Input.GetAxis(PlayerInput.Horizontal); _vertical = Input.GetAxis(PlayerInput.Vertical); // Set values in animator conditions _animator.SetFloat(AnimatorConditions.Direction, _horizontal); _animator.SetFloat(AnimatorConditions.Speed, _vertical); if (Input.GetButtonDown(PlayerInput.Jump)) { Jump(); } } else { // Allow player to move while in air _moveDirection.x = Input.GetAxis(PlayerInput.Horizontal) * _moveSpeed; _moveDirection.z = Input.GetAxis(PlayerInput.Vertical) * _moveSpeed; _moveDirection = _myTransform.TransformDirection(_moveDirection); _animator.SetBool(AnimatorConditions.IsGrounded, false); } break; case CameraState.Target: break; } // Apply gravity to character _moveDirection.y -= gravity * Time.deltaTime; //Move character withthe _moveDirection Vector3 calculated above. _controller.Move(_moveDirection * Time.deltaTime); }
public CarSoundManager(CarActor car, CameraController camera, Game game) : base(game) { cueArray = new Cue[CarSoundEmitters.AudioEmitters.Count]; car_ = car; listener_ = camera.Listener; camera_ = camera; state_ = camera.CurrentCamera.State; }
IEnumerator changeCameraState(CameraState start, CameraState end, float timeInterval) { isTransitioning = true; for(float t = 0F; t < timeInterval; t += Time.deltaTime) { transform.localPosition = Vector3.Lerp(start.position, end.position, t/timeInterval); transform.localRotation = Quaternion.Lerp(start.rotation, end.rotation, t/timeInterval); yield return null; } isTransitioning = false; currentState = end; }
//Take into account the player's direction and shift the camera void shiftSlow(CameraState heading) { if (heading == CameraState.Right && shiftIndex < 5f) { shiftIndex += 0.2f; } else if (heading == CameraState.Left && shiftIndex > -5f) { shiftIndex -= 0.2f; } }
// Use this for initialization void Start () { if (_target == null) { Debug.Log ("no target"); } state = CameraState.VR; arPos = new Vector3(_target.transform.position.x, _target.transform.position.y , _target.transform.transform.position.z + 0.5f); vrPos = new Vector3(_target.transform.position.x, _target.transform.position.y - 0.8f, _target.transform.transform.position.z + 0.5f); plane = GameObject.Find ("Plane"); plane.transform.position = vrPos; plane.GetComponent<Renderer>().enabled = true; }
public GameObject ReleasePlayer() { GameObject retval = possessedCharacter; possessedCharacter = null; PossessionScript ps = retval.GetComponent<PossessionScript>(); ps.Depossess(); attachedLocation = transform.position; attachedRotation = transform.rotation; state = CameraState.DETACHING; tick = 0; return retval; }
void Start(){ foreach (Transform tran in transform) { switch(tran.name) { case "SystemCamera": systemCamera = tran.gameObject; break; case "LC": leftCamera = tran.gameObject; break; case "RC": rightCamera = tran.gameObject; break; case "ZeroParallaxPlane": zeroParallaxPlane = tran.gameObject; break; } } if(Application.platform == RuntimePlatform.Android) { state = CameraState.AndroidRunTimeState; systemCamera.SetActive(false); leftCamera.SetActive(true); rightCamera.SetActive(true); zeroParallaxPlane.SetActive(true); } switch(state) { case CameraState.WindowsEditorState: { break; } case CameraState.WindowsStereoState: { initLRCameras (); break; } case CameraState.AndroidRunTimeState: { initCameras (); break; } } zeroParallaxPlane.GetComponent<MeshRenderer> ().enabled = false; }
// Use this for initialization void Start() { if (_target == null) { Debug.Log ("no target"); return; } quadForeground = GameObject.Find ("QuadForeground"); state = CameraState.VR; vrPos = new Vector3 (0.0f, 1.0f, 0.137f); arPos = new Vector3 (0.0f, 0.0f, 0.137f); }
// Use this for initialization void Start () { if (_target == null) { Debug.Log ("no target"); } state = CameraState.VR; vrPos = new Vector3(_target.transform.position.x, _target.transform.position.y +1.0f, _target.transform.transform.position.z + 0.137f); arPos = new Vector3(_target.transform.position.x, _target.transform.position.y, _target.transform.transform.position.z + 0.137f); quadForeground = GameObject.Find ("QuadForeground"); quadForeground.transform.position = vrPos; }
public GamepadController() { //TODO: Detect new controllers after start ? var controllers = new[] { new Controller(UserIndex.One), new Controller(UserIndex.Two) }; StartPollingAndSendingCommands(controllers); cameraStates = new Dictionary<int, CameraState>(5); for (int i = 0; i < 5; i++) { CameraState cs = new CameraState(); cs.Active = false; cs.Pan = "100"; cs.Tilt = 0; cameraStates[i] = cs; } }
void Awake() { //Cursor.lockState = CursorLockMode.Locked; //Cursor.visible = false; cam = Camera.main; _lockTarget = null; _center = new Vector2(Screen.width / 2, Screen.height / 2); _focusPoint = transform.position; _circleOffset = _focusPoint; _focusOffset = cam.transform.position - _focusPoint; camState = CameraState.DEFAULT; }
void ChangeState(CameraState newState){ currentState = newState; switch (currentState) { case CameraState.CAMERA_MOVEMENT: SSL.enabled = false; ShouldChange = true; break; case CameraState.CAMERA_SHOOTING: CJ.enabled = false; ShouldChange = true; break; default: Debug.Log("NO DEBERIA LLEGAR ACA"); break; } }
public BaseCamera(float FOV, float AspectRatio, float NearPlane, float FarPlane, Vector3 Position, Vector3 Target, Vector3 CameraUp) { fov_ = FOV; currentFov_ = fov_; aspectRatio_ = AspectRatio; nearPlane_ = NearPlane; farPlane_ = FarPlane; position_ = Position; target_ = Target; cameraUp_ = CameraUp; //switching_ = false; cameraState_ = CameraState.Chase; // calculate Projection and view Matricies. updateProjectionMatrix(); updateViewMatrix(); }
public override void Update(GameTime gameTime) { if (state_ != camera_.CurrentCamera.State) { state_ = camera_.CurrentCamera.State; defaultCategory.SetVolume(50); switch (state_) { case CameraState.Chase: cameraCue = soundBank.GetCue("chase"); cameraCue.Play(); break; case CameraState.Reverse: cameraCue = soundBank.GetCue("reverse"); cameraCue.Play(); break; case CameraState.Dynamic: cameraCue = soundBank.GetCue("dynamic"); cameraCue.Play(); break; case CameraState.TopDown: cameraCue = soundBank.GetCue("top_down"); cameraCue.Play(); break; } } for (int i = 0; i < cueArray.Length; i++) cueArray[i].Apply3D(listener_, CarSoundEmitters.AudioEmitters[i]); if (car_.LinearVelocity.LengthSquared() <= 400) musicCategory.SetVolume(car_.LinearVelocity.LengthSquared() / 16); else if (car_.LinearVelocity.LengthSquared() > 1650) musicCategory.SetVolume(0); else musicCategory.SetVolume(25); base.Update(gameTime); }
public void onEnterDoor(int x) { lastState = state; state = CameraState.TRANSITION; doorsXList.Sort(); if (scrollingRight) { minDoor = x + 1; maxDoor = int.MaxValue; int index = doorsXList.FindIndex((doorX) => doorX == minDoor); if (index + 1 < numDoors) { maxDoor = doorsXList[index + 1]; } } else { maxDoor = x - 1; minDoor = int.MinValue; int index = doorsXList.FindIndex((doorX) => doorX == maxDoor); if (index - 1 >= 0) { minDoor = doorsXList[index - 1]; } } if (lastState == CameraState.HORIZONTAL) { doorsXList.Clear(); numDoors = 0; doorsXList.Add(minDoor); doorsXList.Add(minDoor - 1); doorsXList.Add(maxDoor); doorsXList.Add(maxDoor + 1); } transitionX = scrollingRight ? minDoor + screenWidth / 2 : maxDoor - screenWidth / 2; }
private void Start() { cs = CameraState.TopDown; offset = 0; }
/*****/ void Update() { if (Camera.main.GetComponent<UnityStandardAssets.ImageEffects.GlobalFog>()) { Camera.main.GetComponent<UnityStandardAssets.ImageEffects.GlobalFog>().startDistance = Vector3.Distance(Camera.main.transform.position, TargetPosition) - 100; } if (Camera == null && Camera.main == null) return; if (Camera == null && Camera.main != null) Camera = Camera.main; _deltaTime = Time.realtimeSinceStartup - _lastUpdateTime; _lastUpdateTime = Time.realtimeSinceStartup; if (FollowTarget && TargetTransform != null) { TargetPosition = TargetTransform.position; } if (_forward) { TargetPosition += transform.forward * TranslationSpeed * _deltaTime; transform.position += transform.forward * TranslationSpeed * _deltaTime; } if (_backward) { TargetPosition -= transform.forward * TranslationSpeed * _deltaTime; transform.position -= transform.forward * TranslationSpeed * _deltaTime; } if (_right) { TargetPosition += transform.right * TranslationSpeed * _deltaTime; transform.position += transform.right * TranslationSpeed * _deltaTime; } if (_left) { TargetPosition -= transform.right * TranslationSpeed * _deltaTime; transform.position -= transform.right * TranslationSpeed * _deltaTime; } if (_cameraState == CameraState.ArcBall) { _currentAngleX = Mathf.Lerp(_currentAngleX, AngleX, Smoothing); _currentAngleY = Mathf.Lerp(_currentAngleY, AngleY, Smoothing); transform.rotation = Quaternion.Euler(_currentAngleX, _currentAngleY, 0.0f); transform.position = TargetPosition + transform.rotation*Vector3.back*Distance; Camera.transform.position = transform.position; Camera.transform.rotation = transform.rotation; } else if (_cameraState == CameraState.Focus) { Camera.transform.position = Vector3.Lerp(Camera.transform.position, transform.position, 0.1f); Camera.transform.rotation = Quaternion.Lerp(Camera.transform.rotation, transform.rotation, 0.1f); var d = Vector3.Distance(Camera.main.transform.position, TargetPosition); if (d <= DefaultDistance + 0.15f) { _cameraState = CameraState.Normal; Camera.transform.position = Camera.transform.position; Camera.transform.rotation = Camera.transform.rotation; } //_cameraState = CameraState.Normal; } else { _currentAngleX = AngleX; _currentAngleY = AngleY; transform.position = TargetPosition - transform.forward * Distance; transform.rotation = Quaternion.Euler(AngleX, AngleY, 0.0f); TargetPosition = transform.position + transform.forward * Distance; Camera.transform.position = Vector3.Lerp(Camera.transform.position, transform.position, Smoothing); Camera.transform.rotation = Quaternion.Lerp(Camera.transform.rotation, transform.rotation, Smoothing); } }
private void OnGUI() { #if UNITY_EDITOR if (Event.current.type == EventType.Layout || Event.current.type == EventType.Repaint) { EditorUtility.SetDirty(this); // this is important, if omitted, "Mouse down" will not be display } #endif if (_cameraState == CameraState.Focus) return; if (Event.current.alt) { _cameraState = CameraState.ArcBall; } else { if (_cameraState == CameraState.ArcBall) { AngleX = _currentAngleX; AngleY = _currentAngleY; transform.rotation = Quaternion.Euler(_currentAngleX, _currentAngleY, 0.0f); transform.position = TargetPosition + transform.rotation * Vector3.back * Distance; Camera.transform.position = transform.position; Camera.transform.rotation = transform.rotation; _cameraState = CameraState.Normal; } } if (Event.current.alt && Event.current.type == EventType.mouseDrag && Event.current.button == 0) { AngleY += Event.current.delta.x * AcrBallRotationSpeed; AngleX += Event.current.delta.y * AcrBallRotationSpeed; } else if (Event.current.type == EventType.mouseDrag && Event.current.button == 1) { AngleY += Event.current.delta.x * FpsRotationSpeed; AngleX += Event.current.delta.y * FpsRotationSpeed; } else if (Event.current.type == EventType.mouseDrag && Event.current.button == 2) { DoPanning(Event.current.delta.x * PannigSpeed, Event.current.delta.y * PannigSpeed); } else if (Event.current.type == EventType.ScrollWheel) { DoScrolling(Event.current.delta.y * ScrollingSpeed); } if (Event.current.keyCode == KeyCode.F) { if (TargetTransform != null) { TargetPosition = TargetTransform.position; } Distance = DefaultDistance; transform.position = TargetPosition - transform.forward * Distance; _cameraState = CameraState.Focus; } if (Event.current.keyCode == KeyCode.R) { Distance = DefaultDistance; TargetPosition = Vector3.zero; transform.position = TargetPosition - transform.forward * Distance; } if (Event.current.keyCode == KeyCode.W) { _forward = Event.current.type == EventType.KeyDown; } if (Event.current.keyCode == KeyCode.S) { _backward = Event.current.type == EventType.KeyDown; } if (Event.current.keyCode == KeyCode.A) { _left = Event.current.type == EventType.KeyDown; } if (Event.current.keyCode == KeyCode.D) { _right = Event.current.type == EventType.KeyDown; } }
//=================================================================================================================o void LateUpdate() { // 1,2,3 buttons for switching camera modi if ( Input.GetKeyDown (hKey.firstPersonCameraKey) ) { // FirstPerson lastState = "FirstPerson"; cam.camera.fieldOfView = 80.0f; camState = CameraState.FirstPerson; } else if ( Input.GetKeyDown (hKey.orbitCameraKey) ) { // Orbit lastState = "Orbit"; cam.camera.fieldOfView = 70.0f; camState = CameraState.Orbit; } else if ( Input.GetKeyDown (hKey.thirdPersonCameraKey) ) { // ThirdPerson lastState = "ThirdPerson"; cam.camera.fieldOfView = 70.0f; curDist = heroDistance; desDist = heroDistance; finalDist = heroDistance; camState = CameraState.ThirdPerson; } // Camera states switch (camState) { case CameraState.FirstPerson: FirstPerson(); break; case CameraState.ThirdPerson: ThirdPerson(); break; case CameraState.Orbit: Orbit(); break; } }
void OnGUI() { //zoom button if(GUILayout.Button(zoomText) && !transitioning) { if(camState == CameraState.zoomedIn) { zoomText = "Zoom In"; camState = CameraState.zoomedOut; StartCoroutine(SmoothChangeSize(zoomedOutSize)); } else { zoomText = "Zoom Out"; StartCoroutine(SmoothChangeSize(zoomedInSize)); camState = CameraState.zoomedIn; } } }
/// <summary> /// On receive a camera exception. /// </summary> /// <param name="CameraException">The receive camera exception.</param> private static void OnReceiveCameraStateChanged(CameraState CameraState, CameraCapture CameraCapture) { if (OnCameraStateChanged != null) { OnCameraStateChanged(CameraState, CameraCapture); } }
IEnumerator switchCameraRutine( CameraState from ) { float time = 0.0f; Vector3 startPos, endPos; startPos = quadForeground.transform.position; endPos = (from == CameraState.AR) ? vrPos : arPos; while (time < 1.0f) { quadForeground.transform.position = Vector3.Lerp (startPos, endPos, time); time = time + 0.1f; yield return new WaitForSeconds(0.02f); } if (from == CameraState.VR) { Debug.Log("change camera to AR"); isPlaying = false; state = CameraState.AR; } else if (from == CameraState.AR) { Debug.Log("change camera to VR"); isPlaying = false; state = CameraState.VR; } yield return 0; }
public void updateCamera(GameTime time, Vector2 heroPosition) { //this.Move(viewportWidth * 0.25f - Mouse.GetState().X, viewportHeight * 0.25f - Mouse.GetState().Y); //Vector2 mouseVec = new Vector2(Mouse.GetState().X, Mouse.GetState().Y); //Console.WriteLine(mouseVec.ToString()); if (GameStateHandler.CurrentState == GameState.STARTING) { //Vector2 lookPos = new Vector2(350, 385); //moveCameraTo(lookPos); //this.Zoom = 1f; } else if (GameStateHandler.CurrentState == GameState.RUNNING) { int currentSeconds = (int)time.TotalGameTime.TotalSeconds; if (this.CurrentState == CameraState.IDLE) { if (currentSeconds - lastZoom > zoomIntervals) { if (debug) { Console.WriteLine("Zooming in"); } lastZoom = currentSeconds; this.Zoom = defaultZoom; this.CurrentState = CameraState.ZOOMING_IN; } } else if (this.CurrentState == CameraState.ZOOMING_IN) { if (this.Zoom < maxZoom) { this.Move(this.Position.X - xZoom * zoomIncremental, this.Position.Y + yZoom * zoomIncremental); this.Zoom += zoomIncremental; } else { if (debug) { Console.WriteLine("Zooming out"); } this.CurrentState = CameraState.ZOOMING_OUT; } } else if (this.CurrentState == CameraState.ZOOMING_OUT) { if (this.Zoom > defaultZoom) { this.Move(this.Position.X + xZoom * zoomIncremental, this.Position.Y - yZoom * zoomIncremental); this.Zoom -= zoomIncremental; } else { //this.Move(defaultCameraPosition); if (debug) { Console.WriteLine("Done zooming, back at default"); } this.CurrentState = CameraState.IDLE; } } } }