Timed Gazing

CODE

Assets -> AndroidVRWebview -> Scripts -> AndroidWebview.cs

一樣只寫出有修改的部分

void Update () {
    /*中略*/
    HandleGaze ();
}

/*中略*/

void HandleGaze() {
    Vector3 position = Camera.main.ViewportToScreenPoint(new Vector3(0.5f, 0.5f, Camera.main.nearClipPlane));
    Ray cast = Camera.main.ScreenPointToRay (position);
    RaycastHit hit;
    if (Physics.Raycast (cast, out hit)) {
        Vector2 local = CalculatePositionFrom (hit);
        HandleTimedGazing (local);
    }
}

Vector2 lastGaze = new Vector2(0, 0);
float gazeTiming = 0;
void HandleTimedGazing (Vector2 local) {
    if(isScrolling)    //之後會用到
        gazeTiming = 0;
    else {
        if(Vector2.Distance(lastGaze, local) <= 5) {
            gazeTiming += Time.deltaTime;
            if(gazeTiming > 2) {
                SendEvent (local, ActionEvent.Down);
                SendEvent (local, ActionEvent.Up);
                gazeTiming = 0;
            }
        }
    }
    lastGaze = local;
}

Ray的起點和終點座標都要是ScreenPoint,被StackOverflow上一個錯的答案誤導一個下午

你的時間到底都是怎麼消失的

Unity的document也沒寫清楚啊乾!

DEMO

results matching ""

    No results matching ""