void RayPoint() { if(hit.collider != null) { target.transform.position = hit.transform.position; if(hit.collider.gameObject.tag == "Button") { pointed = hit.collider.gameObject.GetComponent<Button>(); if(pointed != null) { pointed.Pointed(); } } else if(hit.collider.gameObject.tag == "MainMenu") { MainMenu_pointed = hit.collider.gameObject.GetComponent<MainMenu>(); if(MainMenu_pointed != null) { // TODO : Mouse Enter (HJOOn) MainMenu_pointed.Pointed(); } } else if (hit.collider.gameObject.tag == "Information") //Information 버튼 구현(add Jin) { Information_pointed = hit.collider.gameObject.GetComponent<Information>(); if (Information_pointed != null) { Information_pointed.Pointed(); } } else if (hit.collider.gameObject.tag == "InformationButton") //Information 버튼 구현(add Jin) { InformationButton_pointed = hit.collider.gameObject.GetComponent<InformationButton>(); if (InformationButton_pointed != null) { InformationButton_pointed.Pointed(); } } else if (hit.collider.gameObject.tag == "InformationCanvas") //Information 버튼 구현(add Jin) { InfoCanvas_pointed = hit.collider.gameObject.GetComponent<InformationCanvas>(); if (InfoCanvas_pointed != null) { InfoCanvas_pointed.Pointed(); } } } }
// Update is called once per frame void Update() { Frame frame = controller.Frame(); //frame GestureList gestures = frame.Gestures(); //frame 안의 gesture 인식 HandList hands = frame.Hands; //frame 안의 hands 인식 int num_hands = hands.Count; //hand의 수 if (num_hands < 1) // 인식된 손이 없다면 { return; } else { Hand left = hands.Leftmost; //왼쪽손 Hand right = hands.Rightmost; //오른쪽 손 FingerList fingerList = left.Fingers; //왼쪽 손의 손가락들! Finger leftFinger = fingerList.Frontmost; //왼손에서 제일 앞에 있는 손가락 rigid = GameObject.Find("RigidHand(Clone)"); if (rigid == null) { Debug.LogWarning("RigidHand is null"); return; } cursorPointer = GameObject.Find("RigidHand(Clone)/index/bone3"); if (cursorPointer == null) { Debug.LogWarning("CursorPointer is null"); return; } //여기에서 립모션 손모양 오븥젝트의 Collision 을 해체하여 Raycast에 충돌 하지 않게 한다. Collider[] cols = rigid.GetComponentsInChildren<Collider>(); for (int i = 0; i < cols.Length; i++) { cols[i].enabled = false; } GameObject handController = GameObject.Find("HandController"); //HandCOnroller 오브젝트 접근 //팁핑 포지션으로 커서를 이동 if (rigid != null) { //Debug.Log ("Rigid finded"); Vector3 temp = Tipping(); cursorModel.transform.position = temp; } //손바닥을 UnityScale로 좌표 변환 , Handcontroller TransformPoint로 Transform 형식에 맞게 변환, 이후 왼쪽 카메라 기준으로 월드 스크린으로 변환 //Vector2 screenPoint=leftCamera.camera.WorldToScreenPoint (handController.transform.TransformPoint(left.PalmPosition.ToUnityScaled())); Vector2 screenPoint = leftCamera.camera.WorldToScreenPoint(cursorPointer.transform.position); Ray r = leftCamera.camera.ScreenPointToRay(screenPoint); // ScreentPoint로부터 Ray를 쏜다 Debug.DrawRay(r.origin, r.direction * 1000, Color.red); RaycastHit hit; //rayCast에서 부딛힌 객체 관리 if (Physics.Raycast(r, out hit, Mathf.Infinity)) { //Debug.Log("hit - ObjName : " + hit.collider.name + // ", Flag - " +hit.collider.gameObject.tag ); if(hit.collider != null) { target.transform.position = hit.transform.position; if(hit.collider.gameObject.tag == "Button") { pointed = hit.collider.gameObject.GetComponent<Button>(); if(pointed != null) { pointed.Pointed(); } } else if(hit.collider.gameObject.tag == "MainMenu") { MainMenu_pointed = hit.collider.gameObject.GetComponent<MainMenu>(); if(MainMenu_pointed != null) { // TODO : Mouse Enter (HJOOn) MainMenu_pointed.Pointed(); } } else if (hit.collider.gameObject.tag == "Information") //Information 버튼 구현(add Jin) { Information_pointed = hit.collider.gameObject.GetComponent<Information>(); if (Information_pointed != null) { Information_pointed.Pointed(); } } } } else { // TODO : Mouse Exit (SHJO) if(pointed != null) { //hit.collider.gameObject.renderer.material.color=Color.red; pointed.PointedOut(); pointed=null; } else if(MainMenu_pointed !=null) { MainMenu_pointed.PointedOut(); MainMenu_pointed = null; } else if (Information_pointed != null) //add Jin { Information_pointed.PointedOut(); Information_pointed = null; } } //립모션 제스쳐 감지 for (int i = 0; i < gestures.Count; i++) { Gesture gesture = gestures[i]; HandList handsForGesture = gesture.Hands; if (num_hands == 1) { // Key Tap if (gesture.Type == Gesture.GestureType.TYPE_KEY_TAP) { KeyTapGesture keyTap = new KeyTapGesture(gesture); Debug.Log ("TYPE_KEY_TAP"); cursorModel.renderer.material.color = Color.blue; GameObject particleObj = Instantiate(clickParticle, Tipping () , Quaternion.identity) as GameObject; Destroy (particleObj,2f); //if(pointed != null) if(hit.collider.gameObject.tag != null) { // TODO : Click (SHJO) if(hit.collider.gameObject.tag=="Button") { Debug.Log ("Button Touch"); pointed.Touch (); } else if(hit.collider.gameObject.tag=="MainMenu") { MainMenu_pointed.Clicked(); } else if (hit.collider.gameObject.tag == "Information") //add Jin { Information_pointed.Clicked(); } } } // Screen Tap else if (gesture.Type == Gesture.GestureType.TYPE_SCREEN_TAP) { ScreenTapGesture screenTap = new ScreenTapGesture(gesture); Debug.Log("TYPE_SCREEN_TAP"); cursorModel.renderer.material.color = Color.red; if(hit.collider.gameObject.tag=="Button") { pointed.Touch (); } } // Swipe else if (gesture.Type == Gesture.GestureType.TYPE_SWIPE) { } // Circle else if (gesture.Type == Gesture.GestureType.TYPE_CIRCLE) { } } // ZOOM IN OUT Motion if (num_hands == 2) { if (handsForGesture[0].IsLeft && gesture.Type == Gesture.GestureType.TYPESWIPE) { Debug.Log("left zoom"); SwipeGesture Swipe = new SwipeGesture(gesture); Vector swipeDirection = Swipe.Direction; if (swipeDirection.x < 0) { if (leftCamera.camera.fieldOfView < maxFov) { leftCamera.camera.fieldOfView += zoomScale; rightCamera.camera.fieldOfView += zoomScale; } } else if (swipeDirection.x > 0) { if (leftCamera.camera.fieldOfView > minFov) { leftCamera.camera.fieldOfView -= zoomScale; rightCamera.camera.fieldOfView -= zoomScale; } } } else if ((!handsForGesture[0].IsLeft) && gesture.Type == Gesture.GestureType.TYPESWIPE) { Debug.Log("right zoom"); SwipeGesture Swipe = new SwipeGesture(gesture); Vector swipeDirection = Swipe.Direction; if (swipeDirection.x > 0) { if (leftCamera.camera.fieldOfView < maxFov) { leftCamera.camera.fieldOfView += zoomScale; rightCamera.camera.fieldOfView += zoomScale; } } else if (swipeDirection.x < 0) { if (leftCamera.camera.fieldOfView > minFov) { leftCamera.camera.fieldOfView -= zoomScale; rightCamera.camera.fieldOfView -= zoomScale; } } } } // END OF ZOOM IN GESTURE } // END OF GESTURE RECOGNITION LOOP } // END OF IF }