private void Update()
        {
            if (Input.GetKeyDown(KeyCode.V))
            {
                //启动投屏窗口
                FARStartRenderingView(WorkMode._DoubleTexture);
            }
            if (Input.GetKeyDown(KeyCode.Q))
            {
                //关闭投屏窗口
                FARDll.CloseDown();
            }
            if (_lastWorkingType != workingMode)
            {
                //切换到2D画面
                FARStartRenderingView(workingMode);
                _lastWorkingType = workingMode;
            }

            ///切换投影方式
            if (Input.GetKeyDown(KeyCode.K))
            {
                FARDll.SwitchProjector(FARDll.ProjectorType._2D);
            }
            if (Input.GetKeyDown(KeyCode.J))
            {
                FARDll.SwitchProjector(FARDll.ProjectorType.LeftRight);
            }
        }
Beispiel #2
0
        private void OnGUI()
        {
            if (SceneManager.GetActiveScene().name == "VRSample" || SceneManager.GetActiveScene().name == "All")
            {
                if (GUI.Button(new Rect(20, 20, 160, 60), "2D"))
                {
                    FARStartRenderingView(WorkMode._DoubleTexture);
                    FARDll.SwitchProjector(FARDll.ProjectorType._2D);
                }

                if (GUI.Button(new Rect(200, 20, 160, 60), "3D"))
                {
                    FARStartRenderingView(WorkMode._DoubleTexture);
                    FARDll.SwitchProjector(FARDll.ProjectorType.LeftRight);
                }
            }

            if (SceneManager.GetActiveScene().name == "F-ARSample" || SceneManager.GetActiveScene().name == "All")
            {
                if (GUI.Button(new Rect(20, 100, 160, 60), "AR"))
                {
                    FARStartRenderingView(WorkMode._SingleTexture);
                    //FARDll.SwitchProjector(FARDll.ProjectorType.LeftRight);
                }
            }

            if (SceneManager.GetActiveScene().name == "UIInter_Switch23D")
            {
                return;
            }
            if (GUI.Button(new Rect(200, 100, 160, 60), "关闭"))
            {
                FARDll.CloseDown();
            }
        }
 private void OnApplicationQuit()
 {
     //安全关闭投屏窗口,可根据需求调用
     FARDll.CloseDown();
 }
        ///启动投屏窗口进程
        private IEnumerator CreateFARWindow(WorkMode _workmode)
        {
            int temp_MonitorCount = FARDll.fmARUpdatePhysicalMonitor();

            if (temp_MonitorCount < 2)
            {
                UnityEngine.Debug.LogError("Direct3DWin.CreateFARWindow() failed with error : Monitor count less than 2");
            }
            //为了与主渲染进程不产生冲突,等待下一帧结束
            yield return(new WaitForEndOfFrame());

            if (FARDll.FindWindow(null, "ClientWinCpp") == IntPtr.Zero)
            {
                string           _path     = Path.Combine(Application.streamingAssetsPath, "ClientWin.exe");
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.FileName    = _path;
                viewProcess           = new Process();
                viewProcess.StartInfo = startInfo;
                viewProcess.Start();
                _hViewClient = IntPtr.Zero;
            }
            while (true)
            {
                _hViewClient = FARDll.FindWindow(null, "ClientWinCpp");
                if (_hViewClient != IntPtr.Zero)
                {
                    UnityEngine.Debug.Log("FAR.CreateFARWindow():找到了窗口句柄!");
                    //全屏到非GC显示器
                    UpdateWindowPos(_hViewClient);
                    int pid = 0;
                    FARDll.GetWindowThreadProcessId(_hViewClient, out pid);
                    if (pid == viewProcess.Id)
                    {
                        //设置当前的色彩空间,u3d默认是Gama空间
                        FARDll.SetColorSpace(FARDll.U3DColorSpace.Gama);
                        //开始绘制同屏窗口,如目标纹理指针变更可随时调用
                        switch (_workmode)
                        {
                        case WorkMode._SingleTexture:
                            status = (FAR_Status)FARDll.StartView(_hViewClient, renderTexture.GetNativeTexturePtr(), IntPtr.Zero);
                            break;

                        case WorkMode._DoubleTexture:
                            status = (FAR_Status)FARDll.StartView(_hViewClient, renderTextureL.GetNativeTexturePtr(), renderTextureR.GetNativeTexturePtr());
                            break;

                        default:
                            status = (FAR_Status)FARDll.StartView(_hViewClient, renderTexture.GetNativeTexturePtr(), IntPtr.Zero);
                            break;
                        }
                    }
                    break;
                }
            }
            if (status < 0)
            {
                UnityEngine.Debug.LogError("FAR.CreateFARWindow():投屏启动失败" + status);
                FARDll.CloseDown();
            }
            else
            {
                UnityEngine.Debug.Log("FAR.CreateFARWindow():开始绘图!");
            }
        }
        ///启动投屏窗口进程
        private IEnumerator CreateFARWindow()
        {
            //为了与主渲染进程不产生冲突,等待下一帧结束
            yield return(new WaitForEndOfFrame());

            try
            {
                _hViewClient = FARDll.FindWindow(null, "ClientWinCpp");
                status       = FARDll.FAR_Status.FAR_NotInitialized;
                if (_hViewClient == IntPtr.Zero)
                {
                    string           _path     = System.IO.Path.Combine(Application.streamingAssetsPath, "ClientWin.exe");
                    ProcessStartInfo startInfo = new ProcessStartInfo();
                    startInfo.FileName           = _path;
                    FARDll.viewProcess           = new Process();
                    FARDll.viewProcess.StartInfo = startInfo;
                    FARDll.viewProcess.Start();
                    FARDll.viewProcess.WaitForInputIdle();
                    _hViewClient = FARDll.FindWindow(null, "ClientWinCpp");
                }
                if (FARDll.viewProcess != null)
                {
                    if (_hViewClient != IntPtr.Zero)
                    {
                        //全屏到非GC显示器
                        UpdateWindowPos(_hViewClient);
                        //开始绘制同屏窗口,如目标纹理指针变更可随时调用
                        switch (_curMode)
                        {
                        case ScreenManger.DualScreenMode.VR:
                            status = (FARDll.FAR_Status)FARDll.StartView(_hViewClient, renderTexture3DLeft.GetNativeTexturePtr(), renderTexture3DRight.GetNativeTexturePtr());
                            break;

                        case ScreenManger.DualScreenMode.VR_2D:
                            status = (FARDll.FAR_Status)FARDll.StartView(_hViewClient, renderTexture3DLeft.GetNativeTexturePtr(), IntPtr.Zero);
                            break;

                        case ScreenManger.DualScreenMode.AR_2D:
                            status = (FARDll.FAR_Status)FARDll.StartView(_hViewClient, renderTextureAR.GetNativeTexturePtr(), IntPtr.Zero);
                            break;

                        case ScreenManger.DualScreenMode.AR:
                            status = (FARDll.FAR_Status)FARDll.StartView(_hViewClient, renderTextureAR.GetNativeTexturePtr(), IntPtr.Zero);
                            break;

                        default:
                            FARDll.CloseDown();
                            break;
                        }
                    }
                }
                else
                {
                    status = FARDll.FAR_Status.FAR_GraphicsCardUnsupported;
                }

                if (status <= 0)
                {
                    UnityEngine.Debug.LogError("投屏启动失败" + status);
                    FARDll.CloseDown();
                }

                if (_hViewClient != IntPtr.Zero)
                {
                    if (Global.Instance.Event.CreateProjectionWindowEvent != null)
                    {
                        Global.Instance.Event.CreateProjectionWindowEvent(_hViewClient);
                    }
                }

                if (_GLIssueHandle != null)
                {
                    this.StopCoroutine(_GLIssueHandle);
                }
                _GLIssueHandle = this.StartCoroutine(CallPluginAtEndOfFrames());
            }
            catch (Exception e)
            {
                FARDll.CloseDown();
                UnityEngine.Debug.LogError("投屏启动失败" + e);
            }
        }