private GameObject CheckClickInput() // sending clicking and hovering messages // I'm assuing there's only one object in contact with player { RaycastHit hit; bool isClicking = Input.GetMouseButton(0); if (Physics.Raycast(myCamera.transform.position, myCamera.transform.forward, out hit, Mathf.Infinity, runeLayer)) { // if it's in "touching range" if (hit.distance <= interactRange) { Clickable hovered = hit.collider.gameObject.GetComponent <Clickable>(); if (isClicking) { hovered.Click(); } else { hovered.Hover(); } return(hit.collider.gameObject); } } else { Debug.Log("no hit"); } return(null); }
protected virtual Clickable GetClickableFromClick() { Ray ray = targetCamera.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo = new RaycastHit(); if (Physics.Raycast(ray, out hitInfo)) { Clickable co = null; Clickable[] cos = hitInfo.collider.GetComponents <Clickable>(); for (int i = 0; i < cos.Length; i++) { if (cos[i].enabled) { co = cos[i]; break; } } if (co) { co.Click(); return(co); } } return(null); }
public void CheckForClick() { if (Input.GetButtonDown("Fire1") && clickable != null) { clickable.Click(); } }
void PNode_Click(object sender, PInputEventArgs e) { if (PreventEvent(e)) { return; } //prevent click when mouse was dragged if (Cursor.Position.GetDistanceTo(FMouseDownPos) < 3) { Clickable.Click(e.Position, GetButton(e)); } }
void Update() { if (active) { if (nextSpawnIncrease < Time.time) { nextSpawnIncrease = Time.time + spawnIncreaseRate; spawnRate *= 1.01f; } if (Random.value < spawnRate) { spaceRocks.Add(Instantiate(comet, new Vector3(Random.value - 0.5f, Random.value - 0.5f, 0).normalized * 10f, Quaternion.identity)); } if (Random.value < spawnRate) { spaceRocks.Add(Instantiate(asteroid, new Vector3(Random.value - 0.5f, Random.value - 0.5f, 0).normalized * 10f, Quaternion.identity)); } } RaycastHit hit; Ray ray = camera.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { if (Input.GetMouseButton(0)) { Planet p = hit.transform.GetComponent <Planet>(); if (p) { p.Hold(); } } if (Input.GetMouseButtonDown(0)) { Planet p = hit.transform.GetComponent <Planet>(); if (p) { p.Click(); return; } SpaceRock sr = hit.transform.GetComponent <SpaceRock>(); if (sr) { sr.Click(); return; } Clickable c = hit.transform.GetComponent <Clickable>(); if (c) { c.Click(); return; } } else { Clickable c = hit.transform.GetComponent <Clickable>(); if (c) { c.Hover(); return; } } } if (Input.GetKeyDown(KeyCode.DownArrow)) { LowerHeat(); } if (Input.GetKeyDown(KeyCode.UpArrow)) { RaiseHeat(); } }
void Update() { if (provider == null) { return; } if (placingArea) { BoundedPlane plane; if (provider.GetPlane(out plane)) { playArea.transform.position = plane.Center; playArea.transform.rotation = plane.Pose.rotation; float scale = Mathf.Min(1f, plane.Size.x, plane.Size.y); playArea.transform.localScale = Vector3.one * scale; playArea.gameObject.SetActive(true); Vector3 forword = -playArea.transform.forward; forword.y = 0f; Vector3 look = Camera.main.transform.position - playArea.transform.position; look.y = 0f; float angle = Vector3.SignedAngle(look, forword, Vector3.up); if (angle > 135f || angle < -135f) { playArea.transform.Rotate(playArea.transform.up, 180f); } else if (angle > 45f) { playArea.transform.Rotate(playArea.transform.up, -90f); } else if (angle < -45f) { playArea.transform.Rotate(playArea.transform.up, 90f); } HelpUI.ShowPlace(); if (provider.GetClickDown()) { placingArea = false; provider.holdAttachPoint.localPosition = provider.holdAttachPoint.localPosition * scale; provider.holdAttachPoint.localScale = Vector3.one * scale; //UIManager.Instance.GoBackToUI(MainUI); LoadingUI.SetActive(false); HelpUI.gameObject.SetActive(false); playArea.SetArea(); provider.FinishInit(); } } else { playArea.gameObject.SetActive(false); HelpUI.ShowLooking(); } } else if (heldBook != null) { if (provider.GetClickUp()) { heldBook.transform.SetParent(playArea.transform); heldBook.PlaceBook(); heldBook = null; HelpUI.gameObject.SetActive(false); } } else if (currentPlacing == null) { if (currentClickable == null) { #if UNITY_EDITOR || UNITY_STANDALONE if (provider.GetClickDown()) #else if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began && !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId)) #endif { RaycastHit hit; if (Physics.Raycast(provider.GetClickRay(), out hit, Mathf.Infinity, (1 << LayerMask.NameToLayer("Placable")) | (1 << LayerMask.NameToLayer("UI")))) { if (hit.collider.gameObject.layer == LayerMask.NameToLayer("Placable")) { currentClickable = hit.transform.GetComponentInParent <Clickable>(); if (currentClickable != null) { currentClickable.ClickDown(hit); } else if (currentArea.AllowMovement) { currentPlacing = hit.transform.GetComponentInParent <Placable>(); lastPos = currentPlacing.transform.localPosition; placingDown = true; } } } } } else { if (provider.GetClickUp()) { RaycastHit hit; if (Physics.Raycast(provider.GetClickRay(), out hit, Mathf.Infinity, 1 << LayerMask.NameToLayer("Placable"))) { Clickable upClickable = hit.transform.GetComponentInParent <Clickable>(); if (upClickable == currentClickable) { currentClickable.Click(hit); } } currentClickable.ClickUp(hit); currentClickable = null; } } } else { PlaceCurrent(); if (provider.GetClickDown()) { placingDown = true; } else if (placingDown && provider.GetClickUp()) { if (placed) { if (lastPos.HasValue) { if (currentArea != null) { currentArea.MoveInArea(currentPlacing); } } else { if (currentArea != null) { currentArea.AddToArea(currentPlacing); PlayerManager.Instance.RemoveInventory(currentPlacing.Data); } } currentPlacing = null; HelpUI.gameObject.SetActive(false); playArea.ShowPlacing(false); if (HelpManager.Instance.CurrentStep == TutorialStep.PlaceTreat) { HelpManager.Instance.CompleteTutorialStep(TutorialStep.PlaceTreat); } else if (HelpManager.Instance.CurrentStep == TutorialStep.PlaceToy) { HelpManager.Instance.CompleteTutorialStep(TutorialStep.PlaceToy); } placingDown = false; SoundManager.Instance.PlayGroup("PlaceItem"); if (IsNonXR) { GrabBook(BookController.Instance); } } /*else * { * /*if (lastPos.HasValue) * currentPlacing.transform.localPosition = lastPos.Value; * else* * if (currentArea != null) * currentArea.RemoveFromArea(currentPlacing); * PlayerManager.Instance.AddInventory(currentPlacing.Data); * Destroy(currentPlacing.gameObject); * }*/ } } if (currentClickable == null) { #if UNITY_EDITOR || UNITY_STANDALONE if (provider.GetClickDown()) #else if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began && !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId)) #endif { RaycastHit hit; if (Physics.Raycast(provider.GetClickRay(), out hit, Mathf.Infinity)) { if (hit.collider.gameObject.layer == LayerMask.NameToLayer("Base")) { BookController.Instance.ReturnBook(); } } } } }
public override void Click(RaycastHit hit) { ParentClickable.Click(hit); }