Auto Scrolling Part I
CODE
Assets -> AndroidVRWebview -> Scripts -> AndroidWebview.cs
一樣只寫出有修改的部分
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);
HandleAutoScrolling (local);
}
}
/*中略*/
bool autoScrolling = false;
void HandleAutoScrolling (Vector2 local) {
if(local.y > websiteHeight * 0.875) // scroll down
StartCoroutine (Scroll (-5));
else if(local.y < websiteHeight * 0.125) // scroll up
StartCoroutine (Scroll (5));
else
isScrolling = false;
}
IEnumerator Scroll (int dir) {
if(!autoScrolling) {
autoScrolling = true;
float x = websiteWidth / 2, y = websiteHeight / 2;
SendEvent (new Vector2(x, y), ActionEvent.Down);
for(int i = 0; i < 10; i++) {
SendEvent (new Vector2(x, y += dir), ActionEvent.Move);
yield return new WaitForEndOfFrame ();
}
SendEvent (new Vector2(x, y), ActionEvent.Up);
autoScrolling = false;
}
}