Task <byte[]> TakeAsync() { var window = UIApplication.SharedApplication.KeyWindow; if (window == null) { throw new InvalidOperationException("No hay una ventana activa"); } if (navigationController == null) { throw new InvalidOperationException("No hay un controlador de navegacion en la aplicación"); } var id = GetRequestId(); var ntcs = new TaskCompletionSource <byte[]>(id); if (Interlocked.CompareExchange(ref completionSource, ntcs, null) != null) { throw new InvalidOperationException("Sólo se puede hacer una operación a la vez"); } cameraController = new CameraContoller(id); navigationController.PresentModalViewController(cameraController, true); EventHandler <PhotoEventArgs> handler = null; handler = (s, e) => { var tcs = Interlocked.Exchange(ref completionSource, null); cameraController.PhotoRead -= handler; if (e.RequestId != id) { navigationController.DismissModalViewController(true); } if (e.IsCancelled) { navigationController.DismissModalViewController(true); tcs.SetResult(null); } else if (e.Error != null) { navigationController.DismissModalViewController(true); tcs.SetException(e.Error); } else { navigationController.DismissModalViewController(true); tcs.SetResult(e.Photo); } }; cameraController.PhotoRead += handler; return(completionSource.Task); }
private void Start() { GameObject sphere = GameObject.Instantiate(ballPrefab); sphere.name = "sphere"; sphere.transform.position = transform.position + Vector3.up * 5f; Camera camera = GameObject.Instantiate(cameraPrefab); CameraContoller cameraContoller = camera.GetComponent <CameraContoller>(); cameraContoller.sphere = sphere.transform; Light light = GameObject.Instantiate(lightPrefab); light.color = Color.white; light.intensity = 0.5f; RenderSettings.ambientLight = Color.white * 0.7f; GameObject.Instantiate(gameOverBase); GameObject.Instantiate(levelName); }
public virtual void ManualStart(List<Bullet> p_bullet, GameObject p_panel, GuiManager p_gui, GameObject p_aim, AudioSource p_musicSource, AudioClip p_musicLevel) { _rigidbody = GetComponent<Rigidbody>(); _audioSource = GetComponent<AudioSource>(); _anim = GetComponent<Animator>(); _flightController = GetComponent<Flight>(); _collisionManager = GetComponent<AircraftCollisionManager>(); _flightController.ManualStart(); TPSCameraController.ManualStart(_rigidbody); FPSCameraController.ManualStart(_rigidbody); _currentCameraController = TPSCameraController; soundController.musicSound = p_musicSource; _bullets = p_bullet; _instPanel = p_panel; _guiManager = p_gui; _aimHUD = p_aim; _guiManager.energySlider.maxValue = energy; _guiManager.energySlider.value = energy; _guiManager.heatSlider.maxValue = normalWeaponHeatTime; _guiManager.heatSlider.value = _normalWeaponHeatCount; _guiManager.armorSlider.maxValue = armorEnergy; _guiManager.armorSlider.value = armorEnergy; _instPanel.SetActive(false); _initialEmissionStartSpeed = fireEmission[0].startSpeed; _emissionLightNormalIntensity = lightEmission[0].intensity; _animIDBarrelLeft = Animator.StringToHash("BarrelRollLeft"); _animIDBarrelRight = Animator.StringToHash("BarrelRollRight"); _animIDShake = Animator.StringToHash("ShakeThird"); if (currentType != type.AIRCRAFT_3) { _animIDAcc = Animator.StringToHash("Accelerate"); _animIDBoost = Animator.StringToHash("Boost"); } if (currentType == type.AIRCRAFT_1) _anim.SetBool(_animIDAcc, true); _collisionManager.ManualStart(); _collisionManager.onHitGround += delegate (Vector3 p_point) { DecreaseEnergy(5f); _flightController.ApplyImpactForce(p_point); _anim.SetTrigger(_animIDShake); Invoke("CancelAnim", 0.5f); }; _collisionManager.onHitStaticObject += delegate (Vector3 p_point) { DecreaseEnergy(5f); _flightController.ApplyImpactForce(p_point); _anim.SetTrigger(_animIDShake); Invoke("CancelAnim", 0.5f); }; _collisionManager.onHitEnemy += delegate (Vector3 p_point, float p_damage) { DecreaseEnergy(p_damage); //_flightController.ApplyImpactForceMonster(p_point); _anim.SetTrigger(_animIDShake); Invoke("CancelAnim", 0.8f); }; _collisionManager.onHitEnemyLittle += delegate (Vector3 p_point, float p_damage) { if (!_inBarrelRoll) { DecreaseEnergy(p_damage); _anim.SetTrigger(_animIDShake); Invoke("CancelAnim", 0.5f); } }; soundController.PlaySound(SoundController.source.MUSIC, p_musicLevel); soundController.PlaySound(SoundController.source.ENGINE, engineSound); // Change camera soundController.InsideCockpit(false); this.enabled = true; }
// Check Rotations control input public virtual void InputControl() { float __accelerator = Input.GetAxis("Accelerate"); float __breaker = Input.GetAxis("Break"); // Joystick Aim if (Input.GetAxis("MouseH") != 0 || Input.GetAxis("MouseV") != 0) { Vector2 __dir = new Vector2(Input.GetAxis("MouseH"), Input.GetAxis("MouseV")); _currentCameraController.aimFollowMouse = false; _currentCameraController._mousePos = __dir; } else { _currentCameraController._mousePos = new Vector2(0f, 0f); } if (_guiManager.inGame) { // Boost if (__accelerator > 0f && !_flightController.accelerating) { ChangeSpeed("boost"); _flightController.acceleratorValue = 1f; _flightController.accelerating = true; soundController.PlaySound(SoundController.source.BOOST, boostSound); for (int i = 0; i < lightEmission.Length; i++) { int __num = i; lightEmission[__num].color = Color.blue; } for (int i = 0; i < fireEmission.Length; i++) { int __num = i; fireEmission[__num].enableEmission = false; } for (int i = 0; i < fireEmissionBoost.Length; i++) { int __num = i; fireEmissionBoost[__num].enableEmission = true; } } else if (__accelerator == 0f && _flightController.accelerating) { ChangeSpeed("normal"); soundController.StopSound(SoundController.source.BOOST); _flightController.accelerating = false; _flightController.acceleratorValue = 0f; for (int i = 0; i < lightEmission.Length; i++) { int __num = i; lightEmission[__num].color = Color.yellow; } for (int i = 0; i < fireEmission.Length; i++) { int __num = i; fireEmission[__num].enableEmission = true; } for (int i = 0; i < fireEmissionBoost.Length; i++) { int __num = i; fireEmissionBoost[__num].enableEmission = false; } } // Break if (__breaker > 0f && !_flightController.breaking) { ChangeSpeed("break"); for (int i = 0; i < fireEmission.Length; i++) { int __num = i; fireEmission[__num].startSpeed = 0f; } for (int i = 0; i < lightEmission.Length; i++) { int __num = i; lightEmission[__num].intensity = 0.5f; } _flightController.breakValue = 1; _flightController.breaking = true; } else if (__breaker == 0f && _flightController.breaking) { ChangeSpeed("normal"); for (int i = 0; i < fireEmission.Length; i++) { int __num = i; fireEmission[__num].startSpeed = _initialEmissionStartSpeed; } for (int i = 0; i < lightEmission.Length; i++) { int __num = i; lightEmission[__num].intensity = _emissionLightNormalIntensity; } _flightController.breaking = false; _flightController.breakValue = 0f; } _flightController.rotationDirection = Input.GetAxis("Horizontal"); _flightController.pitchDirection = Input.GetAxis("Vertical"); if (_flightController.rotationDirection != 0f && !_flightController.rotating) { _flightController.rotating = true; } else if (_flightController.rotating && _flightController.rotationDirection == 0f) { _flightController.rotating = false; } /* if (_currentCameraController.type == CameraContoller.cameraType.THIRD_PERSON_VSION) { _currentCameraController.roll = _flightController.roll; Debug.Log(_flightController.roll); }*/ if (_flightController.pitchDirection != 0f && !_flightController.pitching) { _flightController.pitching = true; } else if (_flightController.pitching && _flightController.pitchDirection == 0f) { _flightController.pitching = false; } // Cameras if (Input.GetButtonDown("Camera")) { if (_currentCameraController.type == CameraContoller.cameraType.FIRST_PERSON_VISION) { _currentCameraController = TPSCameraController; TPSCameraController.mainCam.enabled = true; FPSCameraController.mainCam.enabled = false; soundController.InsideCockpit(false); //EnableExternal(true); } else { _currentCameraController = FPSCameraController; FPSCameraController.mainCam.enabled = true; TPSCameraController.mainCam.enabled = false; soundController.InsideCockpit(true); //EnableExternal(false); } } // Camera Back if (Input.GetButtonDown("Camera Back")) { cameraBack.enabled = true; TPSCameraController.mainCam.enabled = false; FPSCameraController.mainCam.enabled = false; } if (Input.GetButtonUp("Camera Back")) { cameraBack.enabled = false; if (_currentCameraController.type == CameraContoller.cameraType.FIRST_PERSON_VISION) { TPSCameraController.mainCam.enabled = false; FPSCameraController.mainCam.enabled = true; } else { TPSCameraController.mainCam.enabled = true; FPSCameraController.mainCam.enabled = false; } } // Fire if (Input.GetButtonDown("Fire2") && !_specialGunLocked) { _specialWeaponHeatCount = specialWeaponRepairTime; _specialGunLocked = true; _guiManager.ChangeValue("special", 1f); Fire("special"); FireSound(true, "special"); } if (Input.GetButtonDown("Fire1")) { _normalGunFiring = true; _currentCameraController.StartFiring(true); if (!_normalGunLocked) { for (int i = 0; i < normalGunTrail.Length; i++) { int __num = i; normalGunTrail[__num].Play(); normalGunTrail[__num].startSpeed = _speed * 0.01f + 500; } InvokeRepeating("NormalFireCaller", 0f, normalWeaponTime); FireSound(true, "normal"); } } if (Input.GetButtonUp("Fire1")) { for (int i = 0; i < normalGunTrail.Length; i++) { int __num = i; normalGunTrail[__num].Stop(); } _normalGunFiring = false; _currentCameraController.StartFiring(false); FireSound(false, "normal"); CancelInvoke("NormalFireCaller"); DisableAllFire(); } // Joystick Firing Normal if (Input.GetButtonDown("Fire1Joystick") && !_normalGunFiring) { _normalGunFiring = true; _currentCameraController.StartFiring(true); if (!_normalGunLocked) { for (int i = 0; i < normalGunTrail.Length; i++) { int __num = i; normalGunTrail[__num].Play(); normalGunTrail[__num].startSpeed = _speed*0.01f + 500; } InvokeRepeating("NormalFireCaller", 0f, normalWeaponTime); FireSound(true, "normal"); } } if (Input.GetButtonUp("Fire1Joystick")) { for (int i = 0; i < normalGunTrail.Length; i++) { int __num = i; normalGunTrail[__num].Stop(); } _currentCameraController.StartFiring(false); _normalGunFiring = false; FireSound(false, "normal"); CancelInvoke("NormalFireCaller"); DisableAllFire(); } // Fire Special if (Input.GetButtonDown("Fire2Joystick") && !_specialGunFiring && !_specialGunLocked) { _specialWeaponHeatCount = specialWeaponRepairTime; _specialGunLocked = true; _guiManager.ChangeValue("special", 1f); _specialGunFiring = true; _currentCameraController.StartFiring(true); Fire("special"); FireSound(true, "special"); } if (Input.GetButtonUp("Fire2Joystick")) { _specialGunFiring = false; _currentCameraController.StartFiring(false); } // BarrelRoll if (Input.GetButtonDown("Barrel Roll Left") && !_flightController.barrelRollActive) { //BarrelRollForce(); _inBarrelRoll = true; soundController.PlaySound(SoundController.source.BARREL, barrelRoll); _anim.SetTrigger(_animIDBarrelLeft); _flightController.barrelRollActive = true; } if (Input.GetButtonDown("Barrel Roll Right") && !_flightController.barrelRollActive) { //BarrelRollForce(); _inBarrelRoll = true; soundController.PlaySound(SoundController.source.BARREL, barrelRoll); _anim.SetTrigger(_animIDBarrelRight); _flightController.barrelRollActive = true; } } }
private void Awake() { CameraContoller.instance = this; }