public void ResetLandscape() { LandscapeEGyroType = EGyroType.NoRotate; SetLandScapeValue(); mLastLandscapeGyroValue = mCurrentLandscapeGyroValue; LandscapeGyroDifference = 0; }
//解析当前手机状态 public void GetEGyroType() { SetLandScapeValue(); //Landscape if (IsEquals(mCurrentLandscapeGyroValue.x, mLastLandscapeGyroValue.x, true)) { LandscapeEGyroType = EGyroType.NoRotate; LandscapeGyroDifference = 0; } else { LandscapeGyroDifference = (int)(Mathf.Abs(mCurrentLandscapeGyroValue.x - mLastLandscapeGyroValue.x) * 60); if (mCurrentLandscapeGyroValue.y < 0 && mLastLandscapeGyroValue.y < 0) { //当 z < 0,x的值变小则为ToLeft,变大则为ToRight if (mCurrentLandscapeGyroValue.x < mLastLandscapeGyroValue.x) { LandscapeEGyroType = EGyroType.ToLeft; } else { LandscapeEGyroType = EGyroType.ToRight; } } else if (mCurrentLandscapeGyroValue.y > 0 && mLastLandscapeGyroValue.y > 0) { //当 z > 0,x的值变大则为ToLeft,变小则为ToRight if (mCurrentLandscapeGyroValue.x < mLastLandscapeGyroValue.x) { LandscapeEGyroType = EGyroType.ToRight; } else { LandscapeEGyroType = EGyroType.ToLeft; } } else { if (mCurrentLandscapeGyroValue.y < mLastLandscapeGyroValue.y) { //当 z < 0 变为 z > 0,若 x < 0 则为ToLeft,否则则为ToRight if (mCurrentLandscapeGyroValue.x > 0) { LandscapeEGyroType = EGyroType.ToLeft; } else { LandscapeEGyroType = EGyroType.ToRight; } } else { //当 z > 0 变为 z<0,若 x< 0 则为ToRight,否则则为ToLeft if (mCurrentLandscapeGyroValue.x < 0) { LandscapeEGyroType = EGyroType.ToLeft; } else { LandscapeEGyroType = EGyroType.ToRight; } } } } mLastLandscapeGyroValue = mCurrentLandscapeGyroValue; SetPortraitValue(); //Portrait if (IsEquals(mCurrentPortraitGyroValue.x, mLastPortraitGyroValue.x, false)) { PortraitEGyroType = EGyroType.NoRotate; PortraitGyroDifference = 0; } else { PortraitGyroDifference = (int)(Mathf.Abs(mCurrentPortraitGyroValue.x - mLastPortraitGyroValue.x) * 60); if (mCurrentPortraitGyroValue.y < 0 && mLastPortraitGyroValue.y < 0) { //当 z< 0,y的值变大则为ToUp,变小则为ToDown if (mCurrentPortraitGyroValue.x < mLastPortraitGyroValue.x) { PortraitEGyroType = EGyroType.ToDown; } else { PortraitEGyroType = EGyroType.ToUp; } } else if (mCurrentPortraitGyroValue.y > 0 && mLastPortraitGyroValue.y > 0) { //当 z > 0,y的值变大则为ToDown,变小则为ToUp if (mCurrentPortraitGyroValue.x < mLastPortraitGyroValue.x) { PortraitEGyroType = EGyroType.ToUp; } else { PortraitEGyroType = EGyroType.ToDown; } } else { //当 z<0 变为 z > 0,则为ToDown,反之则为ToUp if (mCurrentPortraitGyroValue.y < mLastPortraitGyroValue.y) { //>0 变 <0 PortraitEGyroType = EGyroType.ToUp; } else { PortraitEGyroType = EGyroType.ToDown; } } } mLastPortraitGyroValue = mCurrentPortraitGyroValue; }