// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.LeftShift)) { currentEditorMode = (EditorMode)(((int)currentEditorMode + 1) % (int)EditorMode.E_LENGTH); if (previewTileTransform != null) { previewTileTransform.gameObject.SetActive(!(currentEditorMode > 0)); } } if (Input.GetKeyDown(KeyCode.Minus)) { brushHeight--; } else if (Input.GetKeyDown(KeyCode.Equals)) { brushHeight++; } currentMouseTilePos = Isometric.GetOwnedTilePos( Isometric.GetIsometicBasePositionByWorldRay(Camera.main.ScreenToWorldPoint(Input.mousePosition), Camera.main.transform.forward)); currentMouseTilePos.y = brushHeight * Isometric.IsometricTileSize.y; if (previewTileTransform != null) { previewTileTransform.position = currentMouseTilePos; } if (Input.GetKey(KeyCode.Mouse0)) { if (EventSystem.current.IsPointerOverGameObject()) { return; } switch (currentEditorMode) { case EditorMode.E_PLACE: { if (currentTile != null) { tileManager.AddTile(currentMouseTilePos, currentTile); } } break; case EditorMode.E_DELETE: { tileManager.RemoveTile(currentMouseTilePos); } break; default: break; } } if (Input.GetKey(KeyCode.Mouse1)) { GameObject tile = tileManager.GetTile(currentMouseTilePos); if (tile != null) { CurrentTile = tile; } } }
private void OnPostRender() { if (!lineMat) { Debug.LogError("Please Assign a material on the inspector"); return; } GL.Begin(GL.LINES); lineMat.SetPass(0); Vector3 currentCameraCenterTilePos = Isometric.GetOwnedTilePos( Isometric.GetIsometicBasePositionByWorldRay(Camera.main.transform.position, Camera.main.transform.forward)); Vector3 currentMouseTilePos = Isometric.GetOwnedTilePos( Isometric.GetIsometicBasePositionByWorldRay(Camera.main.ScreenToWorldPoint(Input.mousePosition), Camera.main.transform.forward)); if (activateGrid) { GL.Color(Color.white); for (int x = -10; x < 10; ++x) { Vector3 left = new Vector3((x + 0.5f) * Isometric.IsometricTileSize.x, 0f , -9.5f * Isometric.IsometricTileSize.z), right = new Vector3((x + 0.5f) * Isometric.IsometricTileSize.x, 0f, 9.5f * Isometric.IsometricTileSize.z); GL.Vertex(Isometric.TranslationIsometricToScreen(left + currentCameraCenterTilePos)); GL.Vertex(Isometric.TranslationIsometricToScreen(right + currentCameraCenterTilePos)); } for (int z = -10; z < 10; ++z) { Vector3 down = new Vector3(-9.5f * Isometric.IsometricTileSize.x, 0f, (z + 0.5f) * Isometric.IsometricTileSize.z), top = new Vector3(9.5f * Isometric.IsometricTileSize.x, 0f, (z + 0.5f) * Isometric.IsometricTileSize.z); GL.Vertex(Isometric.TranslationIsometricToScreen(down + currentCameraCenterTilePos)); GL.Vertex(Isometric.TranslationIsometricToScreen(top + currentCameraCenterTilePos)); } } if (activateHoverGuideLine) { GL.Color(Color.red); Vector3 leftBottom = currentMouseTilePos - 0.5f * new Vector3(Isometric.IsometricTileSize.x, 0f, Isometric.IsometricTileSize.z);; Vector3 leftTop = currentMouseTilePos + 0.5f * new Vector3(-Isometric.IsometricTileSize.x, 0f, Isometric.IsometricTileSize.z); Vector3 rightBottom = currentMouseTilePos + 0.5f * new Vector3(Isometric.IsometricTileSize.x, 0f, -Isometric.IsometricTileSize.z); Vector3 rightTop = currentMouseTilePos + 0.5f * new Vector3(Isometric.IsometricTileSize.x, 0f, Isometric.IsometricTileSize.z);; GL.Vertex(Isometric.TranslationIsometricToScreen(leftBottom)); GL.Vertex(Isometric.TranslationIsometricToScreen(leftTop)); GL.Vertex(Isometric.TranslationIsometricToScreen(leftBottom)); GL.Vertex(Isometric.TranslationIsometricToScreen(rightBottom)); GL.Vertex(Isometric.TranslationIsometricToScreen(leftTop)); GL.Vertex(Isometric.TranslationIsometricToScreen(rightTop)); GL.Vertex(Isometric.TranslationIsometricToScreen(rightBottom)); GL.Vertex(Isometric.TranslationIsometricToScreen(rightTop)); } GL.End(); }
public override void OnDrag(PointerEventData eventData) { base.OnDrag(eventData); Vector3 deltaVector3 = new Vector3(eventData.delta.x, eventData.delta.y); RectTransformUtility.ScreenPointToLocalPointInRectangle(CanvasHelper.Main.transform as RectTransform, Input.mousePosition, CanvasHelper.Main.worldCamera, out Vector2 mousePosition); _targetPosition = mousePosition; Quaternion velocityRotation = Quaternion.LookRotation(deltaVector3); Vector3 rotationAxis = velocityRotation * Vector3.up; _destRotation = Quaternion.AngleAxis(eventData.delta.magnitude * 5f, rotationAxis); if (Owner.CardData.TargetType != CardTargetType.E_NonTarget) { if (RectTransformUtility.RectangleContainsScreenPoint(InGameInterface.Instance.HandField, Input.mousePosition)) { if (!IsVisible) { ((RectTransform)Owner.transform).anchoredPosition = _targetPosition; } SetUseEffect(false); IsVisible = true; CardRangeInterface.Instance.IsVisible = false; InGameInterface.Instance.ArrowBody.SetActive(false); } else { CardRangeInterface.Instance.IsVisible = true; InGameInterface.Instance.ArrowBody.SetActive(true); if (IsVisible) { SetUseEffect(true); } Vector3 basePos = InGameInterface.Instance.GetCardLocationInHand(Owner.HandIndex); Vector3 target = new Vector3(_targetPosition.x, _targetPosition.y, 0f); InGameInterface.Instance.ArrowBody.transform.localPosition = basePos; Vector2 arrowSize = ((RectTransform)InGameInterface.Instance.ArrowBody.transform).sizeDelta; arrowSize.y = (target - basePos).magnitude - 100f; ((RectTransform)InGameInterface.Instance.ArrowBody.transform).sizeDelta = arrowSize; Quaternion arrowRotation = Quaternion.FromToRotation(Vector3.up, (target - basePos).normalized); InGameInterface.Instance.ArrowBody.transform.localRotation = arrowRotation; if (Owner.CardData.TargetType == CardTargetType.E_Target) { RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); if (hit.collider != null) { _target.SetTarget(hit.collider.GetComponentInParent <Character>()); if (_target.Target is Player) { _target.SetTarget(null); } } else { _target.SetTarget(null); } InGameInterface.Instance.CollectCircle.SetActive(_target.Target != null); } else { Vector3 point = Isometric.GetIsometicBasePositionByWorldRay(Camera.main.ScreenToWorldPoint(Input.mousePosition), Camera.main.transform.forward); _target.SetTarget(point); CardRangeInterface.Instance.CurrentPoint = point; } } } else { if (RectTransformUtility.RectangleContainsScreenPoint(InGameInterface.Instance.HandField, Input.mousePosition)) { CardRangeInterface.Instance.IsVisible = false; } else { CardRangeInterface.Instance.IsVisible = true; } } }