/// <summary>This will transform the current slicer between the input positions.</summary> public void SetTransform(Vector2 positionA, Vector2 positionB) { var scale = Vector2.Distance(positionB, positionA); var angle = D2dHelper.Atan2(positionB - positionA) * Mathf.Rad2Deg; // Transform the indicator so it lines up with the slice transform.position = positionA; transform.rotation = Quaternion.Euler(0.0f, 0.0f, -angle); transform.localScale = new Vector3(Thickness, scale, scale); }
protected virtual void Update() { // Update input inputManager.Update(Requires); // Make sure the camera exists var camera = D2dHelper.GetCamera(null); if (camera != null) { // Loop through all non-gui fingers foreach (var finger in inputManager.Fingers) { if (finger.StartedOverGui == false) { // Grab extra finger data and position var link = D2dInputManager.Link.FindOrCreate(ref links, finger); var position = D2dHelper.ScreenToWorldPosition(finger.PositionA, Intercept, camera); // Create indiactor? if (finger.Down == true) { link.Start = position; if (IndicatorPrefab != null) { link.Visual = Instantiate(IndicatorPrefab); link.Visual.SetActive(true); } } // Update indicator? if (finger.Set == true && link.Visual != null) { var scale = Vector3.Distance(position, link.Start); var angle = D2dHelper.Atan2(position - link.Start) * Mathf.Rad2Deg; link.Visual.transform.position = link.Start; link.Visual.transform.rotation = Quaternion.Euler(0.0f, 0.0f, -angle); link.Visual.transform.localScale = new Vector3(Thickness, scale, scale); } // Slice scene then clear link? if (finger.Up == true) { D2dSlice.All(Paint, link.Start, position, Thickness, Shape, Color, Layers); link.Clear(); } } } } }
protected virtual void Update() { // Get the main camera var mainCamera = Camera.main; // Begin dragging if (Input.GetKey(Requires) == true && down == false) { down = true; startMousePosition = Input.mousePosition; } // End dragging if (Input.GetKey(Requires) == false && down == true) { down = false; // Main camera exists? if (mainCamera != null) { var endMousePosition = Input.mousePosition; var startPos = D2dHelper.ScreenToWorldPosition(startMousePosition, Intercept, mainCamera); var endPos = D2dHelper.ScreenToWorldPosition(endMousePosition, Intercept, mainCamera); D2dSlice.All(Paint, startPos, endPos, Thickness, Shape, Color, Layers); } } // Update indicator? if (down == true && mainCamera != null && IndicatorPrefab != null) { if (indicatorInstance == null) { indicatorInstance = Instantiate(IndicatorPrefab); } var startPos = D2dHelper.ScreenToWorldPosition(startMousePosition, Intercept, mainCamera); var currentPos = D2dHelper.ScreenToWorldPosition(Input.mousePosition, Intercept, mainCamera); var scale = Vector3.Distance(currentPos, startPos); var angle = D2dHelper.Atan2(currentPos - startPos) * Mathf.Rad2Deg; // Transform the indicator so it lines up with the slice indicatorInstance.transform.position = startPos; indicatorInstance.transform.rotation = Quaternion.Euler(0.0f, 0.0f, -angle); indicatorInstance.transform.localScale = new Vector3(Thickness, scale, scale); } // Destroy indicator? else if (indicatorInstance != null) { Destroy(indicatorInstance.gameObject); } }
private float GetAngleAndClampCurrentPos(Vector3 startPos, ref Vector3 currentPos) { if (startPos != currentPos) { var distance = Vector3.Distance(currentPos, startPos); if (DistanceMin > 0.0f && distance < DistanceMin) { distance = DistanceMin; } if (DistanceMax > 0.0f && distance > DistanceMax) { distance = DistanceMax; } currentPos = startPos + (currentPos - startPos).normalized * distance; } return(D2dHelper.Atan2(currentPos - startPos) * Mathf.Rad2Deg); }