public void OnMouseMoved() { if (scrollEnabled == false) return; if(userTouching) { //get the overall translation Vector2 userTouchPosition = PlanetUnityGameObject.MousePosition(); Vector2 avgPrevTouchLoc = previousMousePosition; //calculate the touch velocity Vector2 dLoc = new Vector2(userTouchPosition.x-avgPrevTouchLoc.x, userTouchPosition.y-avgPrevTouchLoc.y); if(((int)scrollDirection & (int)scrollLockDirection & (int)PlanetScrollDirection.Horizontal) != 0) velocity.x = dLoc.x / Time.deltaTime; else velocity.x = 0.0f; if(((int)scrollDirection & (int)scrollLockDirection & (int)PlanetScrollDirection.Vertical) != 0) velocity.y = dLoc.y / Time.deltaTime; else velocity.y = 0.0f; previousMousePosition = userTouchPosition; absScroll.x += Mathf.Abs (velocity.x); absScroll.y += Mathf.Abs (velocity.y); if (absScroll.x >= kMinCancelTouchesVelocity || absScroll.y >= kMinCancelTouchesVelocity) { shouldCancelTouches = true; } if (shouldCancelTouches) { NotificationCenter.postNotification (entity.scope (), "PlanetUnityCancelMouse"); } //we might need to cancel touches on inner nodes when we start a scroll, which is expensive. avoid this if we can by not cancelling when the user touches, but doesn't actually scroll if(Mathf.Abs(velocity.x) < kMinCancelTouchesVelocity && Mathf.Abs(velocity.y) < kMinCancelTouchesVelocity) return; if(directionalLockEnabled && !directionalLockIsSet) { if(Mathf.Abs(dLoc.x) > Mathf.Abs(dLoc.y)) { scrollLockDirection = PlanetScrollDirection.Horizontal; velocity.y = 0.0f; } else { scrollLockDirection = PlanetScrollDirection.Vertical; velocity.x = 0.0f; } directionalLockIsSet = true; } //update the scroll if(((int)scrollDirection & (int)scrollLockDirection & (int)PlanetScrollDirection.Horizontal) != 0) scroll.x += dLoc.x; if(((int)scrollDirection & (int)scrollLockDirection & (int)PlanetScrollDirection.Vertical) != 0) scroll.y += dLoc.y; // TODO: what to do for this? I dunno //cancel the touch for any targeted delegates (PlanetX normally wouldn't use any of these) //CCDirector::sharedDirector()->getTouchDispatcher()->cancelTouches(relevantTouches, this); /* //cancel touches for PlanetX stuff if(pcEntity) { //find the touch node PlanetCore_ObservableObject* scopeObj = [pcEntity scope]; CCPlanetTouchNode* touchNode = NULL; while(scopeObj) { if([scopeObj isKindOfClass:[PlanetCore_Scene class]] && [(PlanetCore_Scene*)scopeObj touchNode]) { touchNode = [(PlanetCore_Scene*)scopeObj touchNode]; break; } scopeObj = [[scopeObj parent] scope]; } if(scopeObj) { //we have our PlanetX touch node, cancel the children of the scroll view for(int i = 0; i < innerNode->getChildrenCount(); i++) { touchNode->cancelTouchesForNode((CCNode*)innerNode->getChildren()->objectAtIndex(i)); } } }*/ } }
public void OnMouseDown() { if (scrollEnabled == false) return; if (userTouching == false) { userTouching = true; shouldCancelTouches = false; previousMousePosition = PlanetUnityGameObject.MousePosition(); //we have some touches that will stop this scroll view in it's tracks velocity.x = 0; velocity.y = 0; absScroll.x = 0; absScroll.y = 0; scrollLockDirection = PlanetScrollDirection.Both; //check if the view was rubber banding when we touched down if (scroll.x > 0) { touchEdgeOffset.x = scroll.x; } else { float minScroll = calcMinScrollX(); if(scroll.x < minScroll) touchEdgeOffset.x = scroll.x - minScroll; else touchEdgeOffset.x = 0; } if (scroll.y < 0) { touchEdgeOffset.y = scroll.y; } else { float minScroll = calcMaxScrollY(); if(scroll.y > minScroll) touchEdgeOffset.y = scroll.y - minScroll; else touchEdgeOffset.y = 0; } //update state setScrollState(PlanetScrollState.UserDragging); } }