Ejemplo n.º 1
0
        ///启动投屏窗口进程
        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():开始绘图!");
            }
        }
Ejemplo n.º 2
0
        ///启动投屏窗口进程
        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);
            }
        }