FairyGUI.CaptureCamera.CreateRenderTexture C# (CSharp) Method

CreateRenderTexture() public static method

public static CreateRenderTexture ( int width, int height, bool stencilSupport ) : RenderTexture
width int
height int
stencilSupport bool
return UnityEngine.RenderTexture
        public static RenderTexture CreateRenderTexture(int width, int height, bool stencilSupport)
        {
            RenderTexture texture = new RenderTexture(width, height, stencilSupport ? 24 : 0, RenderTextureFormat.ARGB32);
            texture.antiAliasing = 1;
            texture.filterMode = FilterMode.Bilinear;
            texture.anisoLevel = 0;
            texture.useMipMap = false;
            texture.wrapMode = TextureWrapMode.Clamp;
            texture.hideFlags = DisplayOptions.hideFlags;
            return texture;
        }

Usage Example

示例#1
0
        void CaptureInEditMode()
        {
            if (!EMRenderSupport.packageListReady || UIPackage.GetByName(packageName) == null)
            {
                return;
            }

            _captured = true;

            DisplayOptions.SetEditModeHideFlags();
            GComponent view = (GComponent)UIPackage.CreateObject(packageName, componentName);

            if (view != null)
            {
                DestroyTexture();

                _texture = CaptureCamera.CreateRenderTexture(Mathf.RoundToInt(view.width), Mathf.RoundToInt(view.height), false);

                Container root = (Container)view.displayObject;
                root.layer = CaptureCamera.layer;
                root.SetChildrenLayer(CaptureCamera.layer);
                root.gameObject.hideFlags = HideFlags.None;
                root.gameObject.SetActive(true);

                GameObject cameraObject = new GameObject("Temp Capture Camera");
                Camera     camera       = cameraObject.AddComponent <Camera>();
                camera.depth         = 0;
                camera.cullingMask   = 1 << CaptureCamera.layer;
                camera.clearFlags    = CameraClearFlags.Depth;
                camera.orthographic  = true;
                camera.nearClipPlane = -30;
                camera.farClipPlane  = 30;
                camera.enabled       = false;
                camera.targetTexture = _texture;

                float halfHeight = (float)_texture.height / 2;
                camera.orthographicSize = halfHeight;
                cameraObject.transform.localPosition = root.cachedTransform.TransformPoint(halfHeight * camera.aspect, -halfHeight, 0);

                UpdateContext context = new UpdateContext();
                //run two times
                context.Begin();
                view.displayObject.Update(context);
                context.End();

                context.Begin();
                view.displayObject.Update(context);
                context.End();

                RenderTexture old = RenderTexture.active;
                RenderTexture.active = _texture;
                GL.Clear(true, true, Color.clear);
                camera.Render();
                RenderTexture.active = old;

                camera.targetTexture = null;
                view.Dispose();
                GameObject.DestroyImmediate(cameraObject);

                if (_renderer != null)
                {
                    _renderer.sharedMaterial.mainTexture = _texture;
                }
            }
        }
All Usage Examples Of FairyGUI.CaptureCamera::CreateRenderTexture