Beispiel #1
0
 /// <summary>
 /// set mouserect to current virtual screen
 /// </summary>
 static void UpdateMouseRect()
 {
             #if !UNITY_EDITOR
     Rect aRectWindow = KGFUtility.GetWindowRect();
     KGFUtility.SetMouseRect(new Rect(aRectWindow.x, aRectWindow.y + aRectWindow.height - GetResolution2D().height, GetResolution2D().width, GetResolution2D().height));
     print("new rect:" + aRectWindow);
             #endif
 }
Beispiel #2
0
    /// <summary>
    /// Keep mouse inside rect, so virtual mouse does not leave the screen
    /// </summary>
    void CorrectMousePosition()
    {
                #if !UNITY_EDITOR && UNITY_STANDALONE_WIN
        Rect aRectWindow = KGFUtility.GetWindowRect();
        if (aRectWindow.width == 0 || aRectWindow.height == 0)
        {
            return;
        }
        Rect aRestrictedRect = new Rect(aRectWindow.x, aRectWindow.y + aRectWindow.height - GetResolution2D().height, GetResolution2D().width, GetResolution2D().height);
        if (aRestrictedRect.width == 0 || aRestrictedRect.height == 0)
        {
            return;
        }

        KGFUtility.Point aMousePosition;
        bool             aPositionChanged = false;
        KGFUtility.GetCursorPos(out aMousePosition);
        if (aMousePosition.X > aRestrictedRect.xMax)
        {
            aMousePosition.X = (int)aRestrictedRect.xMax;
            aPositionChanged = true;
        }
        if (aMousePosition.Y < aRestrictedRect.yMin)
        {
            aMousePosition.Y = (int)aRestrictedRect.yMin;
            aPositionChanged = true;
        }
        if (aMousePosition.Y > aRestrictedRect.yMax)
        {
            aMousePosition.Y = (int)aRestrictedRect.yMax;
            aPositionChanged = true;
        }

        if (aPositionChanged)
        {
            KGFUtility.SetCursorPos((int)aMousePosition.X, (int)aMousePosition.Y);
        }
                #endif
    }