// Update is called once per frame void Update() { var fr = FocusRay.main; bool showMe = false; RaycastHit hitInfo; IsInputConsumer ic = null; if (Physics.Raycast(fr.CurrentRay, out hitInfo)) { if ((hitInfo.collider != null)) { ic = hitInfo.collider.gameObject.GetComponent <IsInputConsumer> (); if (ic != null) { showMe = ic.IsShowCursorOver; this.transform.position = hitInfo.point; } } } this.UpdateCurrentEntered(ic); if (UpdateIsClicking()) { if (this.CurrentEntered) { this.CurrentEntered.DoEvent_FocusSelected(this); } } this.IsShowing = showMe; this.MyRenderer.enabled = this.IsShowing; }
private bool UpdateIsClicking() { IsJustClicked = false; IsClickPossible = (!UnityEngine.XR.XRSettings.isDeviceActive); var curDown = (Input.GetMouseButton(0)); if (curDown) { if (!ClickDownIs) { // on start: ClickDownStartedOn = this.CurrentEntered; } } else { if (ClickDownIs) { // on release: if (this.CurrentEntered == this.ClickDownStartedOn) { IsJustClicked = true; } } ClickDownStartedOn = null; } ClickDownIs = curDown; return(IsJustClicked); }
public void EnsureSetup() { if (mIsSetup) { return; } mIsSetup = true; var ic = this.GetComponent <IsInputConsumer> (); if (!ic) { ic = this.gameObject.AddComponent <IsInputConsumer> (); } ic.IsShowCursorOver = true; Inputter = ic; if (ParentReciever == null) { ParentReciever = this.gameObject.GetComponentInParent <IButtonReciever> (); } var mr = this.GetComponent <MeshRenderer> (); if (mr) { mr.material.SetFloat("CreateInstance", 1.0f); this.MatInst = mr.material; this.DefaultColor = this.MatInst.GetColor("_DefaultColor"); this.Default2Color = this.MatInst.GetColor("_Default2Color"); this.BasicColor = this.DefaultColor; this.MatInst.SetColor("_BasicColor", this.BasicColor); } ic.FocusEntered += (FocusCursor ray) => { this.MatInst.SetFloat("_HighlightPct", 1.0f); this.TimeStarted = Time.time; SelectPct = 0.0f; if (ParentReciever != null) { ParentReciever.ButtonHoverChanged(this.Action, true); } }; ic.FocusExited += (FocusCursor ray) => { this.MatInst.SetFloat("_HighlightPct", 0.0f); this.MatInst.SetFloat("_SelectionPct", 0.0f); SelectPct = 0.0f; if (ParentReciever != null) { ParentReciever.ButtonHoverChanged(this.Action, false); } }; ic.FocusSelected += (FocusCursor ray) => { ButtonDoSelected(); }; }
private void UpdateCurrentEntered(IsInputConsumer ic) { if (this.CurrentEntered == ic) { return; } if (CurrentEntered) { CurrentEntered.DoEvent_FocusExited(this); CurrentEntered = null; } CurrentEntered = ic; if (CurrentEntered) { CurrentEntered.DoEvent_FocusEntered(this); } }