查看: 549|回复: 0
打印 上一主题 下一主题

[其他] Unity3d 控制鼠标的移动范围

[复制链接]

9903

主题

126

听众

7万

积分

首席设计师

Rank: 8Rank: 8

纳金币
53464
精华
316

最佳新人 热心会员 灌水之王 活跃会员 突出贡献 荣誉管理 论坛元老

跳转到指定楼层
楼主
发表于 2015-9-29 00:53:32 |只看该作者 |倒序浏览

有二种方法,一个是调用windows 系统的 user32.dll的ClipCursor函数。再一种就是 通过Cursor.SetCursor函数。


[DllImport( “user32.dll”, CharSet = CharSet.Auto, ExactSpelling = true )]

[return: MarshalAs( UnmanagedType.Bool )]

public static extern bool ClipCursor( ref RECT rcClip );

[DllImport( “user32.dll” )]

[return: MarshalAs( UnmanagedType.Bool )]

public static extern bool GetClipCursor( out RECT rcClip );

[DllImport( “user32.dll” )]

static extern int GetForegroundWindow( );

[DllImport(“user32.dll”)]

[return: MarshalAs( UnmanagedType.Bool )]

static extern bool GetWindowRect( int hWnd, ref RECT lpRect );

[StructLayout( LayoutKind.Sequential )]

public struct RECT

{

public int Left;

public int Top;

public int Right;

public int Bottom;

public RECT( int left, int top, int right, int bottom )

{

Left = left;

Top = top;

Right = right;

Bottom = bottom;

}

}

RECT currentClippingRect;

RECT originalClippingRect = new RECT( );

void Start()

{

hndl = GetForegroundWindow( );

GetWindowRect( hndl, ref currentClippingRect );

GetClipCursor( out originalClippingRect );

ClipCursor( ref currentClippingRect);

}

void OnApplicationQuit()

{

ClipCursor( ref originalClippingRect );

}
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-5-6 17:38 , Processed in 0.081962 second(s), 29 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部