コード例 #1
0
        public static void SetWindowTitle(string title)
        {
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
            // 1) get the current window handle.
            IntPtr windowHandle = WindowUtils.GetWindowHandle();
            // 2) set the window title, if we got something.
            if (windowHandle != IntPtr.Zero)
            {
                SetWindowText(windowHandle, title);
            }
#endif
        }
コード例 #2
0
        public static void SetPositionAndSize(int x, int y, int resX, int resY)
        {
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
            // 1) get the current window handle.
            IntPtr windowHandle = WindowUtils.GetWindowHandle();

            // 2) offset and position the window, if we got something.
            if (windowHandle != IntPtr.Zero)
            {
                SetWindowPos(windowHandle, 0 /*HWND_TOP*/, x, y, resX, resY, 0 /*No extra flags*/);
            }
#endif
        }
コード例 #3
0
        public static void RemoveBorder()
        {
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
            // 1) get the current window handle.
            IntPtr windowHandle = WindowUtils.GetWindowHandle();

            // 2) clear out the window style flags by setting style to visible only
            if (windowHandle != IntPtr.Zero)
            {
                SetWindowLong(windowHandle, (int)WindowLongFlags.GWL_STYLE, (uint)WindowStyles.WS_VISIBLE);
            }
#endif
        }
コード例 #4
0
        private void Initialize()
        {
            // 1. FIGURE OUT WHICH VRDEVICE TO START

            // start with a null device
            vrDevice = null;

            // If a VRDevice to start is specified on the command line, then that is the one we will use.
            try {
                // process command line args
                string[] args = System.Environment.GetCommandLineArgs();
#if UNITY_EDITOR
                // if running in the editor add the editor command line args
                string[] sysArgs    = args;
                string[] editorArgs = editorCmdLineArgs.Split(' ');
                args = new string[sysArgs.Length + editorArgs.Length];
                Array.Copy(sysArgs, args, sysArgs.Length);
                Array.Copy(editorArgs, 0, args, sysArgs.Length, editorArgs.Length);
#endif

                int i = 1;
                while (i < args.Length)
                {
                    // help command
                    if ((args[i] == "-h") || (args[i] == "-help") || (args[i] == "--help"))
                    {
                        Debug.Log("Command Line Arguments:\n" +
                                  "-help\n" +
                                  "     Display this message.\n" +
                                  "-vrdevice [name of a GameObject tagged with 'VRDevice']\n" +
                                  "     Activates the specified GameObject and deactivates all others tagged as a VRDevice."
                                  );
                        i++;
                    }

                    // vrdevice
                    else if (args[i] == "-vrdevice")
                    {
                        if (args.Length <= i)
                        {
                            throw new Exception("Missing command line parameter for -vrdevice.");
                        }
                        string vrDeviceName = args[i + 1];

                        // Find all GameObjects (even inactive ones) with a VRDevice component attached
                        // and see if there is one that matches the name provided on the command line
                        foreach (VRDevice dev in Resources.FindObjectsOfTypeAll(typeof(VRDevice)) as VRDevice[])
                        {
                            if (dev.name == vrDeviceName)
                            {
                                vrDevice = dev;
                            }
                        }
                        if (vrDevice == null)
                        {
                            throw new Exception("Got a '-vrdevice GameObject' command line argument, but cannot find a VRDevice named: " + vrDeviceName);
                        }
                        i += 2;
                    }

                    // ignore all other arguments
                    else
                    {
                        //Debug.Log("Ignoring command line argument: " + args[i]);
                        i++;
                    }
                }
            }
            catch (Exception e) {
                Debug.LogException(e, this);
            }

            // If vrDevice is still null after parsing the command line, then see if a defaultDevice was
            // provided to VRMain in the inspector
            if (vrDevice == null)
            {
                vrDevice = defaultVRDevice;
            }

            // If vrDevice is still null, then see if there is a VRDevice component attached to VRMain
            if (vrDevice == null)
            {
                VRDevice dev = this.GetComponent(typeof(VRDevice)) as VRDevice;
                if (dev != null)
                {
                    vrDevice = dev;
                }
            }

            // If vrDevice is still null, then  proceed with default settings provided by the VRDevice constructor
            if (vrDevice == null)
            {
                Debug.Log("No VRDevice specified, adding a default one to VRMain.");
                vrDevice = gameObject.AddComponent(typeof(VRDevice)) as VRDevice;
            }



            // 2. ACTIVATE THE SPECIFIED VRDEVICE AND DEACTIVATE ALL OTHERS

            // Activate this vrdevice
            vrDevice.gameObject.SetActive(true);

            // and deactivate all others
            foreach (VRDevice dev in Resources.FindObjectsOfTypeAll(typeof(VRDevice)) as VRDevice[])
            {
                if ((dev != vrDevice) && (dev != this))
                {
                    dev.gameObject.SetActive(false);
                }
            }



            // 3. INITIALIZE VRMAIN WITH SETTINGS FROM THE VRDEVICE
            WindowUtils.RemoveBorder();
            WindowUtils.SetPositionAndSize(vrDevice.windowXPos, vrDevice.windowYPos, vrDevice.windowWidth, vrDevice.windowHeight);
            WindowUtils.SetWindowTitle("MinVRUnity " + vrDevice.name);

            if (vrDevice.vrNodeType == VRDevice.VRNodeType.NetClient)
            {
                _netInterface = new VRNetClient(vrDevice.serverIPAddress, vrDevice.serverPort);

                foreach (VRPNInput vrpn in Resources.FindObjectsOfTypeAll(typeof(VRPNInput)) as VRPNInput[])
                {
                    vrpn.gameObject.SetActive(false);
                }
            }
            else if (vrDevice.vrNodeType == VRDevice.VRNodeType.NetServer)
            {
                _netInterface = new VRNetServer(vrDevice.serverPort, vrDevice.numClients);

                foreach (VRPNInput vrpn in Resources.FindObjectsOfTypeAll(typeof(VRPNInput)) as VRPNInput[])
                {
                    vrpn.gameObject.SetActive(true);
                }
            }
            else if (vrDevice.vrNodeType == VRDevice.VRNodeType.StandAlone)
            {
                if (vrDevice.activateVRPNInputObjects)
                {
                    foreach (VRPNInput vrpn in Resources.FindObjectsOfTypeAll(typeof(VRPNInput)) as VRPNInput[])
                    {
                        vrpn.gameObject.SetActive(true);
                    }
                }
                else
                {
                    foreach (VRPNInput vrpn in Resources.FindObjectsOfTypeAll(typeof(VRPNInput)) as VRPNInput[])
                    {
                        vrpn.gameObject.SetActive(false);
                    }
                }
            }

            _initialized = true;
        }