private void Update() { if (GazeTransform == null) { return; } UpdateGazeInfo(); // Perform raycast to determine gazed object GameObject previousFocusObject = RaycastPhysics(); // If we have a unity event system, perform graphics raycasts as well to support Unity UI interactions if (EventSystem.current != null) { // NOTE: We need to do this AFTER we set the HitPosition and HitObject since we need to use HitPosition to perform the correct 2D UI Raycast. RaycastUnityUI(); } // Dispatch changed event if focus is different if (previousFocusObject != HitObject && FocusedObjectChanged != null) { FocusedObjectChanged(previousFocusObject, HitObject); } if (logging) { float a = (hitboxZPlane - GazeOrigin.z) / GazeNormal.z; if (HitObject != null) { Vector3 WorldSpacePosition = GazeOrigin + (GazeNormal * a); if (HitObject.GetComponent <Renderer>() != null) { float xOff = HitObject.GetComponent <Renderer>().bounds.center.x; float yOff = HitObject.GetComponent <Renderer>().bounds.center.y; float zOff = HitObject.GetComponent <Renderer>().bounds.center.z; Debug.Log("Gaze: " + HitObject.name + HitObject.GetComponent <Renderer>().bounds.size + ": Offset from center (" + (HitPosition.x - xOff) + "," + (HitPosition.y - yOff) + "," + (HitPosition.z - zOff) + ") World space (" + WorldSpacePosition.x + "," + WorldSpacePosition.y + "," + WorldSpacePosition.z + ") at " + Time.time + " seconds"); } else if (HitObject.GetComponent <RectTransform>() != null) { float xOff = HitObject.GetComponent <RectTransform>().rect.center.x; float yOff = HitObject.GetComponent <RectTransform>().rect.center.y; Debug.Log("Gaze: " + HitObject.name + HitObject.GetComponent <RectTransform>().rect.size *HitObject.GetComponent <RectTransform>().localScale.x + ": Offset from center (" + (HitPosition.x - xOff) + ", " + (HitPosition.y - yOff) + ", " + hitboxZPlane + ") World space (" + WorldSpacePosition.x + "," + WorldSpacePosition.y + "," + WorldSpacePosition.z + ") at " + Time.time + " seconds"); } } else { // Rather than HitPosition, figure out where the cursor intersects with the z-plane we calculated at the beginning Vector3 NonHitPosition = GazeOrigin + (GazeNormal * a); Debug.Log("Gaze: Whiff " + NonHitPosition.x + ", " + NonHitPosition.y + ", " + NonHitPosition.z + " at " + Time.time + " seconds"); } } }
void FixedUpdate() { Vector3 playerPos = GameObject.FindWithTag("Player").transform.position; Vector3 direction = (playerPos - transform.position); Ray ray = new Ray(transform.position, direction); RaycastHit hit; GameObject HitObject; if (topCamera.isActiveAndEnabled) { if (Physics.Raycast(ray, out hit)) { Debug.DrawRay(transform.position, direction, Color.blue); HitObject = hit.collider.gameObject; if (!hit.collider.CompareTag("Player")) { if (HitObject.CompareTag("VariableTransparency")) { if (HitObject.GetComponent <Renderer>() != null) { Debug.Log(previousHit); if (hit.collider.gameObject != previousHit) { previousHit.GetComponent <Renderer>().material = opaqueMaterial; //Debug.Log("Applied Opaque"); } else { HitObject.GetComponent <Renderer>().material = transparentMaterial; //Debug.Log("Applied Transparent"); } previousHit = HitObject; Debug.Log(previousHit); } } } if (hit.collider.tag == "Player") { //Debug.Log("Hit Player! Call Amberlamps"); Debug.DrawLine(transform.position, playerPos, Color.black); previousHit.GetComponent <Renderer>().material = opaqueMaterial; } } } }
private void Update() { if (GazeTransform == null) { return; } UpdateGazeInfo(); // Perform raycast to determine gazed object GameObject previousFocusObject = RaycastPhysics(); // If we have a unity event system, perform graphics raycasts as well to support Unity UI interactions if (EventSystem.current != null) { // NOTE: We need to do this AFTER we set the HitPosition and HitObject since we need to use HitPosition to perform the correct 2D UI Raycast. RaycastUnityUI(); } // Dispatch changed event if focus is different if (previousFocusObject != HitObject && FocusedObjectChanged != null) { FocusedObjectChanged(previousFocusObject, HitObject); if (HitObject != null && HitObject.tag == "Bar") { float value = PlotBars.instance.getUpdatedValue(HitObject); string text = titles[0] + " : " + HitObject.name + "\n" + titles[1] + " : " + value.ToString("0.00"); barText.GetComponent <TextMesh>().text = text; HitObject.GetComponent <Renderer>().material = onFocus; } if (previousFocusObject != null && previousFocusObject.tag == "Bar") { barText.GetComponent <TextMesh>().text = ""; previousFocusObject.GetComponent <Renderer>().material = offFocus; } } }
private void KeyboardContro() { //BEGIN Управление движением камеры с помощью кнопок if (Input.GetKey(KeyCode.D)) { float bonusSpeed = 0; if (Input.GetKey(KeyCode.LeftShift)) { bonusSpeed = Speed * 2; } X = X + ((Speed + bonusSpeed) * Time.deltaTime); transform.position = new Vector3(X, Y, Z); } if (Input.GetKey(KeyCode.A)) { float bonusSpeed = 0; if (Input.GetKey(KeyCode.LeftShift)) { bonusSpeed = Speed * 2; } X = X - ((Speed + bonusSpeed) * Time.deltaTime); transform.position = new Vector3(X, Y, Z); } if (Input.GetKey(KeyCode.S)) { float bonusSpeed = 0; if (Input.GetKey(KeyCode.LeftShift)) { bonusSpeed = Speed * 2; } Y = Y - ((Speed + bonusSpeed) * Time.deltaTime); transform.position = new Vector3(X, Y, Z); } if (Input.GetKey(KeyCode.W)) { float bonusSpeed = 0; if (Input.GetKey(KeyCode.LeftShift)) { bonusSpeed = Speed * 2; } Y = Y + ((Speed + bonusSpeed) * Time.deltaTime); transform.position = new Vector3(X, Y, Z); } //END Управление движением камеры с помощью кнопок //BEGIN Управление зумом с помощью клавиши float CurrentZoomLevel = Camera.main.orthographicSize; if (Input.GetKey(KeyCode.PageUp)) { //if (!(CurrentZoomLevel - 5 < 5)) // Camera.main.orthographicSize = CurrentZoomLevel - 5; // else Camera.main.orthographicSize = 5; } if (Input.GetKey(KeyCode.PageDown)) { //if (!(CurrentZoomLevel + 5 > 40)) // Camera.main.orthographicSize = CurrentZoomLevel + 5; //else Camera.main.orthographicSize = 40; } if (Input.GetKey(KeyCode.Keypad5)) { Camera.main.orthographicSize = 20; } //END Управление зумом с помощью клавиши //BEGIN Нажатие по клетки левой кнопки мышки if (Input.GetMouseButtonDown(0)) { Vector2 origin = new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y); RaycastHit2D hit = Physics2D.Raycast(origin, Vector2.zero, 0f); if (hit) { HitObject = hit.transform.gameObject; //int x = hitObject.GetComponent<MG_hexagonCell>().GameCoordinate_x; //int y = hitObject.GetComponent<MG_hexagonCell>().GameCoordinate_y; //print(hit.transform.gameObject.tag + " Coordinates: " + x + ", " + y); if (SelectedObject) { //BEGIN Если предыдущая кликнутая клетка не совпадает с текущей, то задаем Кликнуто и перекрашиваем в другой цвет if (!GameObject.ReferenceEquals(HitObject, SelectedObject)) { //selectedObject.GetComponent<MG_hexagonCell>().CancelSelect(); //УБРАНО НА ВРЕМЯ, ТЕСТИРУЮ ПОКА PATHFINDING //hitObject.GetComponent<MG_hexagonCell>().SelectedByMouse(); //УБРАНО НА ВРЕМЯ, ТЕСТИРУЮ ПОКА PATHFINDING SelectedObject = HitObject; } //END Если предыдущая кликнутая клетка не совпадает с текущей, то задаем Кликнуто и перекрашиваем в другой цвет } else { //**Если предыдущей клетки не было кликнуто, то задаем ее и перекрашиваем //hitObject.GetComponent<MG_hexagonCell>().SelectedByMouse(); //УБРАНО НА ВРЕМЯ, ТЕСТИРУЮ ПОКА PATHFINDING SelectedObject = HitObject; } Obj_Pathfinding.GetComponent <MG_PathfindingCells>().InitCellForPathfinding(HitObject.GetComponent <MG_hexagonCell>()); //для Pathfinding, проверяем из GUI что нужно поставить в данной клетки (Цель или Старт, перекрасить в воду или землю) } } //END Нажатие по клетки левой кнопки мышки }