public override void Update(VrUpdateArgs args) { var session = args.Session; var input = session.SemanticInput(); Matrix4 pointer = PointerFilter(session.RightController.PointerTransform); var hitResult = GetClosestHit(pointer.Translation); //KNARK: Review Deletebutton usage (used to capture on down, execute on up) /*if(input.SelectClick || input.DeleteClick) * { * _pressedAt = pointer; * } * else */if (input.IsSelectPressed && !_dragging) { _dragging = true; _hitResult = hitResult; var eventArgs = new VrEventArgs(pointer, _hitResult); BeginDrag?.Invoke(eventArgs); if (eventArgs.CreatedObject != null) { _hitResult = eventArgs.CreatedObject(); } } else if (_dragging && input.IsSelectPressed) { DeltaDrag?.Invoke(new VrEventArgs(pointer, _hitResult)); } else if (!input.IsSelectPressed && _dragging) { _dragging = false; EndDrag?.Invoke(new VrEventArgs(pointer, _hitResult)); } //else if (_gripPressed && !session.RightController.InputState.GripPressed // && CloseEnough(_pressedAt, pointer)) else if (input.DeleteClick) { AlternateClick?.Invoke(new VrEventArgs(pointer, hitResult)); } else if (hitResult != null) { HoverObject?.Invoke(new VrEventArgs(pointer, hitResult)); } }
/// <summary> /// 初始化控件 /// </summary> /// <param name="holderNum">盒个数</param> /// <param name="cupNum">每个盒的杯个数</param> /// <param name="hoverObj">捕获对象类型</param> virtual public void Init(int holderNum, int cupNum, HoverObject hoverObj) { if (holderNum < 1 || cupNum < 0) { throw new Exception("Invalid groupNum or cupNum"); } if (hoverObj == HoverObject.CupHover) { _cupBtnArr = _gpBtnArr; _holderBtnArr = new List <GraphicButton>(); } else if (hoverObj == HoverObject.SlotHover) { _cupBtnArr = new List <GraphicButton>(); _holderBtnArr = _gpBtnArr; } else { _cupBtnArr = new List <GraphicButton>(); _holderBtnArr = new List <GraphicButton>(); } _slotNum = holderNum; _cupNum = cupNum; //int headerWidth = (this.Width - 2 * 5); //指示区域总宽度 int headerHeight = (this.Height - 2 * 5); //指示区域总宽度 int headerWidth = (int)(IndexHeightFactor * this.Width / 8); //指示区域高度 //int slotWidth = headerWidth / _slotNum; //每一槽的宽度 int slotWidth = this.Width - 20 * 2 - headerWidth; //每一槽的宽度 //int headerHeight = (int)(IndexHeightFactor * this.Height / 8); //指示区域高度 int topOffset = 5; //int slotTop = 2 * topOffset + headerHeight; int slotTop = topOffset; int slotHeight = (headerHeight - topOffset * holderNum) / holderNum; Rectangle indexRect = new Rectangle(10, topOffset, headerWidth, headerHeight); indexRect.Width = headerWidth; _titlePath = CommonGraphic.CreateRoundRectPath(indexRect, 10, 10); _indexBtn = new HolderButton[_slotNum]; float indexBtnSize = Math.Min(slotHeight, headerWidth) * IndexBtnSizeFactor; float indexOffsetX = (headerWidth - indexBtnSize) / 2.0f; float indexOffsetY = (slotHeight - indexBtnSize) / 2.0f; float flateVal = 0; if (slotHeight <= indexBtnSize) { flateVal = indexBtnSize / 10; } float roundSize = slotHeight * 24 / 42f; for (int i = 0; i < _slotNum; i++) { int slotLeft = indexRect.Left * 2 + headerWidth; int slotTopOffset = slotTop * (i + 1) + i * slotHeight; RectangleF rect = new RectangleF(indexRect.Left * 2, slotTopOffset, indexBtnSize, indexBtnSize); rect.Offset(indexOffsetX, indexOffsetY); rect.Inflate(-flateVal, -flateVal); HolderButton indexBtn = new HolderButton(); indexBtn.BtnRect = rect; indexBtn.BtnPath = new GraphicsPath(); indexBtn.BtnPath.AddEllipse(rect); indexBtn.BtnRegion = new Region(indexBtn.BtnRect); indexBtn.Text = "T" + (i + 1).ToString(); indexBtn.HeaderBtn = true; _indexBtn[i] = indexBtn; Rectangle slotRect = new Rectangle(slotLeft + 10, slotTopOffset, slotWidth, slotHeight); slotRect.Inflate(_slotOffsetX, 0); HolderButton holderBtn = new HolderButton(); holderBtn.BtnRect = slotRect; holderBtn.BtnPath = CommonGraphic.CreateRoundRectPath(slotRect, roundSize, roundSize); holderBtn.BtnRegion = new Region(holderBtn.BtnPath); _holderBtnArr.Add(holderBtn); if (_cupNum > 0) { int cupHeight = slotHeight; int offset = (slotHeight - cupHeight) / 2; int widthOffset = 0; for (int j = 0; j < _cupNum; j++) { int cupTop = widthOffset + slotTop * (i + 1) + i * slotHeight; int cupLeft = slotLeft + 10 + (slotWidth - cupHeight * _cupNum) / (_cupNum + 1) + ((slotWidth - 2 * ((slotWidth - cupHeight * _cupNum) / (_cupNum + 1)) - cupHeight) / (_cupNum - 1)) * j; RectangleF cupRect = new RectangleF(cupLeft, cupTop, slotHeight, cupHeight); if (offset > 0) { cupRect.Inflate(-widthOffset - offset, -widthOffset); } else { cupRect.Inflate(-widthOffset, -widthOffset + offset); } CupButton cupBtn = new CupButton(); cupBtn.BtnRect = cupRect; cupBtn.BtnPath = new GraphicsPath(); cupBtn.BtnPath.AddEllipse(cupRect); cupBtn.BtnRegion = new Region(cupBtn.BtnPath); _cupBtnArr.Add(cupBtn); } } } }
void Update() { RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); HoverObject ho = null; if (hit.transform != null) { ho = hit.transform.GetComponent <HoverObject>(); } if (ho != null) { hoverMessage = ho.message; hoverMessageImage = ho.messageImage; hoverMessage.gameObject.SetActive(true); } else { if (hoverMessage != null) { hoverMessage.gameObject.SetActive(false); hoverMessageImage = null; hoverMessage = null; } } if (hoverMessageImage) { Vector3 newPos = hoverMessageImage.anchoredPosition; //X if (Input.mousePosition.x > Screen.width * 0.75f) { newPos.x = -Mathf.Abs(newPos.x); } else if (Input.mousePosition.x < Screen.width * 0.25f) { newPos.x = Mathf.Abs(newPos.x); } //Y if (Input.mousePosition.y > Screen.height * 0.75f) { newPos.y = -Mathf.Abs(newPos.y); } else if (Input.mousePosition.y < Screen.height * 0.25f) { newPos.y = Mathf.Abs(newPos.y); } hoverMessageImage.anchoredPosition = newPos; hoverMessage.position = Input.mousePosition; } if (hoverMessage != null) { hoverMessage.position = Input.mousePosition; } }