public void EM_Update(UpdateContext context) { DisplayOptions.SetEditModeHideFlags(); DisplayOptions.defaultRoot = this.transform; container.Update(context); DisplayOptions.defaultRoot = null; if (setNativeChildrenOrder) { CacheNativeChildrenRenderers(); int cnt = _renders.Count; int sv = context.renderingOrder++; for (int i = 0; i < cnt; i++) { Renderer r = _renders[i]; if (r != null) { r.sortingOrder = sv; } } } }
void CreateUI_EditMode() { if (!EMRenderSupport.packageListReady || UIPackage.GetByName(packageName) == null) { return; } #if (UNITY_5 || UNITY_5_3_OR_NEWER) DisplayOptions.SetEditModeHideFlags(); GObject obj = UIPackage.CreateObject(packageName, componentName); if (obj != null && !(obj is GComponent)) { obj.Dispose(); Debug.LogWarning("Not a GComponnet: " + packageName + "/" + componentName); return; } _ui = (GComponent)obj; if (_ui != null) { _ui.displayObject.gameObject.hideFlags |= HideFlags.HideInHierarchy; _ui.gameObjectName = "UI(AutoGenerated)"; _ui.position = position; if (scale.x != 0 && scale.y != 0) { _ui.scale = scale; } _ui.rotationX = rotation.x; _ui.rotationY = rotation.y; _ui.rotation = rotation.z; this.container.AddChildAt(_ui.displayObject, 0); cachedUISize = _ui.size; uiBounds.size = cachedUISize; HandleScreenSizeChanged(); } #else PackageItem pi = UIPackage.GetByName(packageName).GetItemByName(componentName); if (pi != null) { cachedUISize = new Vector2(pi.width, pi.height); uiBounds.size = cachedUISize; HandleScreenSizeChanged(); } #endif }
void CreateUI_EditMode() { if (!EMRenderSupport.packageListReady || UIPackage.GetByName(packageName) == null) { return; } #if UNITY_5 UIObjectFactory.packageItemExtensions.Clear(); UIObjectFactory.loaderConstructor = null; DisplayOptions.SetEditModeHideFlags(); _ui = (GComponent)UIPackage.CreateObject(packageName, componentName); if (_ui != null) { _ui.displayObject.gameObject.hideFlags |= HideFlags.HideInHierarchy; _ui.gameObjectName = "UI(AutoGenerated)"; _ui.position = position; if (scale.x != 0 && scale.y != 0) { _ui.scale = scale; } _ui.rotationX = rotation.x; _ui.rotationY = rotation.y; _ui.rotation = rotation.z; this.container.AddChildAt(_ui.displayObject, 0); cachedUISize = _ui.size; uiBounds.size = cachedUISize; HandleScreenSizeChanged(); } #else PackageItem pi = UIPackage.GetByName(packageName).GetItemByName(componentName); if (pi != null) { cachedUISize = new Vector2(pi.width, pi.height); uiBounds.size = cachedUISize; HandleScreenSizeChanged(); } #endif }
void CreateUI_EditMode() { if (!packageListReady || UIPackage.GetByName(packageName) == null) { return; } #if UNITY_5 UIObjectFactory.packageItemExtensions.Clear(); UIObjectFactory.loaderConstructor = null; DisplayOptions.SetEditModeHideFlags(); DisplayOptions.defaultRoot = new Transform[] { this.transform }; _ui = (GComponent)UIPackage.CreateObject(packageName, componentName); DisplayOptions.defaultRoot = null; if (_ui != null) { _ui.position = position; if (scale.x != 0 && scale.y != 0) { _ui.scale = scale; } _ui.rotationX = rotation.x; _ui.rotationY = rotation.y; _ui.rotation = rotation.z; this.container.AddChild(_ui.displayObject); cachedUISize = _ui.size; uiBounds.size = cachedUISize; HandleScreenSizeChanged(); } #else PackageItem pi = UIPackage.GetByName(packageName).GetItemByName(componentName); if (pi != null) { cachedUISize = new Vector2(pi.width, pi.height); uiBounds.size = cachedUISize; HandleScreenSizeChanged(); } #endif }
void HandleScreenSizeChanged() { if (!Application.isPlaying) { DisplayOptions.SetEditModeHideFlags(); } screenSizeVer = StageCamera.screenSizeVer; if (this.container != null) { if (this.container.renderMode != RenderMode.WorldSpace) { this.container.scale = new Vector2(StageCamera.UnitsPerPixel * UIContentScaler.scaleFactor, StageCamera.UnitsPerPixel * UIContentScaler.scaleFactor); } } int width = Mathf.CeilToInt(Screen.width / UIContentScaler.scaleFactor); int height = Mathf.CeilToInt(Screen.height / UIContentScaler.scaleFactor); if (this._ui != null) { switch (fitScreen) { case FitScreen.FitSize: this._ui.SetXY(0, 0); this._ui.SetSize(width, height); break; case FitScreen.FitWidthAndSetMiddle: this._ui.SetXY(0, (int)((height - this._ui.sourceHeight) / 2)); this._ui.SetSize(width, this._ui.sourceHeight); break; case FitScreen.FitHeightAndSetCenter: this._ui.SetXY((int)((width - this._ui.sourceWidth) / 2), 0); this._ui.SetSize(this._ui.sourceWidth, height); break; } } else { switch (fitScreen) { case FitScreen.FitSize: uiBounds.position = new Vector2(0, 0); uiBounds.size = new Vector2(width, height); break; case FitScreen.FitWidthAndSetMiddle: uiBounds.position = new Vector2(0, (int)((height - cachedUISize.y) / 2)); uiBounds.size = new Vector2(width, cachedUISize.y); break; case FitScreen.FitHeightAndSetCenter: uiBounds.position = new Vector2((int)((width - cachedUISize.x) / 2), 0); uiBounds.size = new Vector2(cachedUISize.x, height); break; } } }
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; } } }
void CaptureInEditMode() { if (!packageListReady || UIPackage.GetByName(packageName) == null) { return; } _captured = true; GameObject tempGo = new GameObject("Temp Object"); tempGo.layer = CaptureCamera.layer; UIObjectFactory.packageItemExtensions.Clear(); UIObjectFactory.loaderConstructor = null; DisplayOptions.SetEditModeHideFlags(); DisplayOptions.defaultRoot = new Transform[] { tempGo.transform }; GComponent view = (GComponent)UIPackage.CreateObject(packageName, componentName); DisplayOptions.defaultRoot = null; if (view != null) { if (texture != null) { DestroyTexture(); } CreateTexture(Mathf.CeilToInt(view.width), Mathf.CeilToInt(view.height)); 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.orthographicSize = view.height / 2; camera.nearClipPlane = -30; camera.farClipPlane = 30; camera.enabled = false; camera.targetTexture = texture; Vector3 pos = root.cachedTransform.position; pos.x += camera.orthographicSize * camera.aspect; pos.y -= camera.orthographicSize; pos.z = 0; cameraObject.transform.localPosition = pos; 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); GameObject.DestroyImmediate(tempGo); this.GetComponent <Renderer>().sharedMaterial.mainTexture = texture; } }