纳金网

标题: 设定unity3d执行程序运行后的屏幕大小和屏幕坐标 [打印本页]

作者: 驰骋的风    时间: 2011-11-24 09:45
标题: 设定unity3d执行程序运行后的屏幕大小和屏幕坐标

          算不是一篇完整的教程了,其实就是一段功能实现代码,平时大家可能也不怎么会用到,但如果是用unity3d来做一些投影项目的话,此段代码就是非常的有用了。此段代码主要的功能就是可以精确方便的设定发布后的unity3d文件执行时在显示屏幕上的坐标和大小,且可以以无边框非全屏的模式显示。下面是C#代码:
         
           using System;
         

           using System.Collections;
         

           using System.Runtime.InteropServices;
         

           using System.Diagnostics;
         

           using UnityEngine;
         

           public class WindowMod: MonoBehaviour
         

           {
         

           public Rect screenPosition;
         

           [DllImport("user32.dll")]
         

           static extern IntPtr SetWindowLong (IntPtr hwnd,int  
           


            _
           
           nIndex ,int  dwNewLong);
         

           [DllImport("user32.dll")]
         

           static extern bool SetWindowPos (IntPtr hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
         

           [DllImport("user32.dll")]
         

           static extern IntPtr GetForegroundWindow ();
         

           // not used rigth now
         

           //const uint SWP
           
            _
           
           NOMOVE = 0x2;
         

           //const uint SWP
           
            _
           
           NOSIZE = 1;
         

           //const uint SWP
           
            _
           
           NOZORDER = 0x4;
         

           //const uint SWP
           
            _
           
           HIDEWINDOW = 0x0080;
         

           const uint SWP
           
            _
           
           SHOWWINDOW = 0x0040;
         

           const int GWL
           
            _
           
           STYLE = -16;
         

           const int WS
           
            _
           
           BORDER = 1;
         

           void Start ()
         

           {
         

           SetWindowLong(GetForegroundWindow (), GWL
           
            _
           
           STYLE, WS
           
            _
           
           BORDER);
         

           bool result = SetWindowPos (GetForegroundWindow (), 0,(int)screenPosition.x,(int)screenPosition.y, (int)screenPosition.width,(int) screenPosition.height, SWP
           
            _
           
           SHOWWINDOW);
         

           }
         

           }
           

           注意的一点是要记着把此代码文件命名为WindowMod.cs
           

           本代码转自:http://www.pixelstudio.nl/?p=204#more-204,unity3d8.com整理发布!
           


            http://www.unity3d8.com/content/%E8%AE%BE%E5%AE%9Aunity3d%E6%89%A7%E8%A1%8C%E7%A8%8B%E5%BA%8F%E8%BF%90%E8%A1%8C%E5%90%8E%E7%9A%84%E5%B1%8F%E5%B9%95%E5%A4%A7%E5%B0%8F%E5%92%8C%E5%B1%8F%E5%B9%95%E5%9D%90%E6%A0%87
           


作者: C.R.CAN    时间: 2012-1-19 23:03
年年岁岁,岁岁年年,春去春来,转眼间又过了一年,小年到,祝福到,愿你在新的一年事业节节高,生活红火火,拜个早年,提前祝你新年好!

作者: 晃晃    时间: 2012-4-7 23:19
“再次路过……”我造一个-----特别路过

作者: 奇    时间: 2012-4-13 23:20
我也来支持下

作者: 菜刀吻电线    时间: 2012-4-16 23:20
其实楼主所说的这些,俺支很少用!

作者: 奇    时间: 2012-4-22 23:26
我是老实人,我来也!

作者: 晃晃    时间: 2012-5-22 23:25
呵呵,真得不错哦!!

作者: C.R.CAN    时间: 2012-8-2 01:46
不会吧,太恐怖了

作者: 晃晃    时间: 2012-8-3 01:51
好可爱的字,学习了

作者: C.R.CAN    时间: 2012-9-4 23:23
已阵亡的 蝶 随 风 舞 说过  偶尔按一下 CTRL A 会发现 世界还有另一面

作者: C.R.CAN    时间: 2012-9-28 23:19
好铁多多发,感激分享

作者: tc    时间: 2012-10-21 23:39
路过、路过、快到鸟,列位请继续...ing

作者: tc    时间: 2012-10-30 23:23
很经典,很实用,学习了!

作者: 奇    时间: 2012-12-2 23:23
心中有爱,爱咋咋地

作者: 奇    时间: 2012-12-4 23:21
凡系斑竹滴话要听;凡系朋友滴帖要顶

作者: 晃晃    时间: 2013-2-5 23:30
谢谢楼主,真是太实用了

作者: 奇    时间: 2013-2-14 23:27
很有心,部分已收录自用,谢谢

作者: 奇    时间: 2013-3-6 23:27
很有心,部分已收录自用,谢谢

作者: 菜刀吻电线    时间: 2013-3-17 23:33
不会吧,太恐怖了





欢迎光临 纳金网 (http://c-www.narkii.com/club/) Powered by Discuz! X2.5