void CaptureInEditMode()
{
if (!EMRenderSupport.packageListReady || UIPackage.GetByName(packageName) == null)
return;
_captured = true;
UIObjectFactory.packageItemExtensions.Clear();
UIObjectFactory.loaderConstructor = null;
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;
}
}