private void OnUnloaded(object sender, RoutedEventArgs e) { Dispose(); BackgroundPanel.RemoveFromVisualTree(); Viewfinder.RemoveFromVisualTree(); }
/// <summary> /// Enables or disables viewfinder /// </summary> /// <param name="enableViewfinder">true to enable viewfinder, false to disable</param> private void EnableViewfinder(bool enableViewfinder) { if (enableViewfinder) { this.viewfinder = this.control.StartViewfinder(); if (this.viewfinder.GetCapability(Viewfinder.ViewfinderCapability.OutputTypeVideoOut)) { this.viewfinder.Output = Viewfinder.OutputType.Off; } this.viewfinder.AvailViewfinderImage += this.OnAvailViewfinderImage; } else { if (this.viewfinder != null) { this.viewfinder.AvailViewfinderImage -= this.OnAvailViewfinderImage; this.viewfinder.Close(); this.viewfinder.Dispose(); this.viewfinder = null; } } }
private void Viewfinder_PointerPressed(object sender, PointerRoutedEventArgs e) { _viewfinderPressed = true; Viewfinder.CapturePointer(e.Pointer); var pointer = e.GetCurrentPoint(this); var point = pointer.Position.ToVector2(); _viewfinderDelta = new Vector2(_viewfinder.Offset.X - point.X, _viewfinder.Offset.Y - point.Y); }
/// <summary> /// The <see cref="FrameworkElement.Loaded"/> event handler. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private void OnLoaded(object sender, RoutedEventArgs e) { this.viewfinder = (Viewfinder)this.MediaViewer.FindName("Viewfinder"); this.SubscribeToViewfinderEvents(); this.previewAreaSize = new Size(this.viewfinder.ActualWidth, this.viewfinder.ActualHeight); // Ensure the page is fully loaded before handling orientation changes for this page. this.OrientationChanged += this.OnOrientationChanged; // Apply current orientation. this.OnOrientationChanged(this, new OrientationChangedEventArgs(this.Orientation)); }
private void Viewfinder_PointerReleased(object sender, PointerRoutedEventArgs e) { _viewfinderPressed = false; Viewfinder.ReleasePointerCapture(e.Pointer); var pointer = e.GetCurrentPoint(this); var offset = _viewfinderDelta + pointer.Position.ToVector2(); // Padding maybe var p = 8; var w = (float)ActualWidth - 146 - p * 2; var h = (float)ActualHeight - 110 - p * 2; _viewfinderOffset = new Vector2((offset.X - p) / w, (offset.Y - p) / h); CheckConstraints(); }
private void infectedUpdate() { playerPos = GameController.instance.playerPos; //spawn viewfinders if they are not spawned yet if (spawnViewfinders) { followV = Instantiate(followDetection, transform.position, transform.rotation); followA = Instantiate(attackDetection, transform.position, transform.rotation); followViewfinderScript = followV.GetComponent <Viewfinder>(); attackViewfinderScript = followA.GetComponent <Viewfinder>(); spawnViewfinders = false; } //update viewfinder position followV.transform.position = new Vector2(transform.position.x, transform.position.y + 4.2f); followA.transform.position = new Vector2(transform.position.x, transform.position.y + 3.1f); //update script values if (followViewfinderScript.playerInFrame == true) { follow = true; } else { follow = false; } if (attackViewfinderScript.playerInFrame == true) { attack = true; } else { attack = false; } //set new speed of enemy if (!setSpeed) { movementVec = new Vector2(runningSpeed / 2, 0); setSpeed = !setSpeed; } //check to see if the enemy is moving to update animation if (trans.position.x != xPositionChange) { anim.SetBool("isMoving", true); xPositionChange = trans.position.x; } else { anim.SetBool("isMoving", false); } //actual movement if (chargeCompleted) { attackFunctionsTimer += Time.fixedDeltaTime; if (!executeAttack) { if (attackFunctionsTimer >= attackWaitTime * GameController.instance.attackSpeed) { executeAttack = true; anim.SetBool("Attack", true); attackVines = Instantiate(attackVinesObj, new Vector3(transform.position.x + .2f, transform.position.y + 2.6f, transform.position.z), transform.rotation); } } else { if (attackFunctionsTimer >= attackTime * GameController.instance.attackSpeed) { anim.SetBool("Attack", false); executeAttack = false; chargeCompleted = false; attackFunctionsTimer = 0; Destroy(attackVines); } } } else if (attack) { anim.SetBool("Charge", true); attackFunctionsTimer += Time.fixedDeltaTime; if (attackFunctionsTimer >= attackChargeTime * GameController.instance.attackSpeed) { chargeCompleted = true; attackFunctionsTimer = 0; } } else if (follow) { anim.SetBool("Charge", false); attackFunctionsTimer = 0; if (playerPos.position.x < transform.position.x) { movementVec = new Vector2(-runningSpeed / 2, 0); transform.localScale = new Vector3(-1, 1, 1); } else { movementVec = new Vector2(runningSpeed / 2, 0); transform.localScale = new Vector3(1, 1, 1); } rb2d.velocity = movementVec * timeSpeed; } else { anim.SetBool("Charge", false); attackFunctionsTimer = 0; if (currentTime >= runTime) { runTime = TimeChange(); currentTime = 0; movementVec = -movementVec; } else { if (movementVec.x / -1 < 0) { transform.localScale = new Vector3(1, 1, 1); } else { transform.localScale = new Vector3(-1, 1, 1); } rb2d.velocity = movementVec * timeSpeed; } } }