Пример #1
0
        //-------------------------------------------------
        // Called every Update() while a Hand is hovering over this object
        //-------------------------------------------------
        private void HandHoverUpdate(Hand hand)
        {
            //Debug.DrawLine(transform.position, transform.position + transform.forward, Color.blue);
            //Debug.DrawLine(transform.position, transform.position + transform.up, Color.green);
            //Debug.DrawLine(transform.position, transform.position + transform.right, Color.red);
            GrabTypes startingGrabType = hand.GetGrabStarting();
            GrabTypes endingGrabType   = hand.GetGrabEnding();
            bool      isGrabEnding     = hand.IsGrabEnding(this.gameObject);

            if (interactable.attachedToHand == null)
            {
                if (startingGrabType != GrabTypes.None)
                {
                    hand.HoverLock(interactable);
                    hand.AttachObject(gameObject, startingGrabType, attachmentFlags);
                }
            }
            else
            {
                if (startingGrabType == GrabTypes.Pinch)
                {
                    magicCircle = Instantiate(magicCirclePrefab, transform.position + transform.up * 3, Quaternion.identity);
                    magicCircle.transform.LookAt(transform.position);

                    point = Instantiate(pointPrefab, magicCircle.transform.position, Quaternion.identity);
                }
                if (hand.IsGrabbingWithType(GrabTypes.Pinch))
                {
                    // 마법 발동? 그리기
                    // holy 12365416851651561651456561561shit
                    magicEffect.SetActive(true);

                    if (Physics.Raycast(transform.position, transform.up, out RaycastHit hit, Mathf.Infinity))
                    {
                        Debug.Log(hit.transform.name);
                        if (hit.transform.CompareTag("paint") || hit.transform.CompareTag("paintTrigger"))
                        {
                            point.transform.position = hit.point;
                            if (hit.transform.CompareTag("paintTrigger") && !isPointTrigger)
                            {
                                isPointTrigger = true;
                                hand.hapticAction.Execute(0, 0.1f, 1, 30, hand.handType);
                                line.positionCount++;
                                line.SetPosition(line.positionCount - 1, hit.transform.position + hit.transform.forward * 0.1f);
                            }
                            else if (hit.transform.CompareTag("paint") && isPointTrigger)
                            {
                                isPointTrigger = false;
                            }
                        }
                    }
                }
                if (endingGrabType == GrabTypes.Pinch)
                {
                    magicEffect.SetActive(false);
                    Destroy(magicCircle.gameObject);
                    Destroy(point.gameObject);
                    line.positionCount = 0;
                }
                if (startingGrabType == GrabTypes.Grip)
                {
                    // 내려놓기
                    // 굳이 없어도 될듯?
                    hand.DetachObject(gameObject);
                    hand.HoverUnlock(interactable);
                }
            }
        }