void Update() { if (!Input.GetMouseButtonDown(0)) { return; } var results = new CubismRaycastHit[4]; var ray = Camera.main.ScreenPointToRay(Input.mousePosition); var hitCount = raycaster.Raycast(ray, results); for (int i = 0; i < hitCount; i++) { string hitID = results[i].Drawable.name; Debug.Log("クリックしたアートメッシュIDは" + hitID + "です。"); if (hitID == "HitAreaBody") { anim.SetTrigger("touchBody"); } if (hitID == "HitAreaHead") { anim.SetTrigger("touchHead"); } } }
private void Update() { if (!Input.GetMouseButtonDown(0)) { return; } for (int i = 0; i < raycastHits.Length; i++) { raycastHits[i] = default; } var ray = cameraManager.Camera.ScreenPointToRay(Input.mousePosition); var count = cubismRaycaster.Raycast(ray, raycastHits); if (count == 0) { return; } var resultText = string.Join(",", raycastHits .Where(h => h.Drawable) .Select(h => h.Drawable.name)); Debug.Log(resultText); }
/// <summary> /// Update. /// </summary> private void Update() { // Play if animation is specified. SpecifiedAnimationCheck(); if (!Input.GetMouseButtonDown(0)) { return; } // Cast ray from pointer position. var ray = Camera.main.ScreenPointToRay(Input.mousePosition); var hitCount = _raycaster.Raycast(ray, _raycastResults); // Motion playback according to the hit location. for (var i = 0; i < hitCount; i++) { var hitDrawable = _raycastResults[i].Drawable; for (var j = 0; j < _hasHitDrawables.Count; j++) { if (hitDrawable == _hasHitDrawables[j].drawable) { var hitArea = _hasHitDrawables[j].hitArea; // Tap body. if (hitArea == HitArea.Body) { // Decide motion to play at random. var motionIndex = UnityEngine.Random.Range(0, _tapBodyMotions.Length); Debug.Log("Tap body : Play : " + _tapBodyMotions[motionIndex].name); _motionController.PlayAnimation(_tapBodyMotions[motionIndex], isLoop: false, priority: CubismMotionPriority.PriorityNormal); } // Tap head. else if (hitArea == HitArea.Head) { // Decide expression motion to play at random. var expressionNum = _expressionController.ExpressionsList.CubismExpressionObjects.Length; var expressionIndex = UnityEngine.Random.Range(0, expressionNum); _expressionController.CurrentExpressionIndex = expressionIndex; Debug.Log("Tap head : Play : " + _expressionController.ExpressionsList.CubismExpressionObjects[expressionIndex].name); } break; } } } }
protected override void Raycast(Ray ray) { var hit = new CubismRaycastHit[4]; var hitCount = raycaster.Raycast(ray, hit); for (var index = 0; index < hitCount; index++) { if (onRaycastHit != null) { onRaycastHit.OnNext(hit[index].Drawable); } } }