Inheritance: UnityEngine.MonoBehaviour
示例#1
0
        public static void CheckMain()
        {
            if (_main != null && _main.cachedCamera != null)
            {
                return;
            }

            GameObject go = GameObject.Find(Name);

            if (go != null)
            {
                _main = go.GetComponent <CaptureCamera>();
                return;
            }

            GameObject cameraObject = new GameObject(Name);
            Camera     camera       = cameraObject.AddComponent <Camera>();

            camera.depth            = 0;
            camera.cullingMask      = 1 << layer;
            camera.clearFlags       = CameraClearFlags.Depth;
            camera.orthographic     = true;
            camera.orthographicSize = 5;
            camera.nearClipPlane    = -30;
            camera.farClipPlane     = 30;
            camera.enabled          = false;
            cameraObject.AddComponent <CaptureCamera>();
        }
示例#2
0
 void Capture()
 {
     if (this._ui != null)
     {
         CaptureCamera.Capture(this.container, this.texture);
     }
 }
 void Capture()
 {
     CaptureCamera.Capture(this.container, _texture, Vector2.zero);
     if (_renderer != null)
     {
         _renderer.sortingOrder = container.renderingOrder;
     }
 }
示例#4
0
        void OnEnable()
        {
            cachedCamera    = this.GetComponent <Camera>();
            cachedTransform = this.gameObject.transform;

            if (this.gameObject.name == Name)
            {
                _main = this;
            }
        }
示例#5
0
        void Capture()
        {
            Vector2 offset = new Vector2(_paintingMargin.left, _paintingMargin.top);

            CaptureCamera.Capture(this, (RenderTexture)paintingGraphics.texture.nativeTexture, offset);

            _paintingFlag = 2;             //2表示已完成一次Capture
            if (onPaint != null)
            {
                onPaint();
            }
        }
 static public int get_cachedTransform(IntPtr l)
 {
     try {
         FairyGUI.CaptureCamera self = (FairyGUI.CaptureCamera)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.cachedTransform);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int set_cachedCamera(IntPtr l)
 {
     try {
         FairyGUI.CaptureCamera self = (FairyGUI.CaptureCamera)checkSelf(l);
         UnityEngine.Camera     v;
         checkType(l, 2, out v);
         self.cachedCamera = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
示例#8
0
        /// <summary>
        ///
        /// </summary>
        public void CreateUI()
        {
            if (_ui != null)
            {
                _ui.Dispose();
                _ui = null;
                DestroyTexture();
            }

            _created = true;

            if (string.IsNullOrEmpty(packageName) || string.IsNullOrEmpty(componentName))
            {
                return;
            }

            _ui = (GComponent)UIPackage.CreateObject(packageName, componentName);
            if (_ui != null)
            {
                this.container.AddChild(_ui.displayObject);
                ((MeshColliderHitTest)this.container.hitArea).SetArea(0, 0, _ui.width, _ui.height);
                this.container.size = _ui.size;
                _texture            = CaptureCamera.CreateRenderTexture(Mathf.RoundToInt(_ui.width), Mathf.RoundToInt(_ui.height), UIConfig.depthSupportForPaintingMode);
                _renderer           = this.GetComponent <Renderer>();
                if (_renderer != null)
                {
                    _renderer.sharedMaterial.mainTexture = _texture;
                    _captureDelegate = Capture;
                    if (_renderer.sharedMaterial.renderQueue == 3000)                     //Set in transpare queue only
                    {
                        this.container.onUpdate = () =>
                        {
                            UpdateContext.OnEnd += _captureDelegate;
                        };
                    }
                }
            }
            else
            {
                Debug.LogError("Create " + componentName + "@" + packageName + " failed!");
            }
        }
示例#9
0
        /// <summary>
        ///
        /// </summary>
        public static void CheckMain()
        {
            if (_main != null && _main.cachedCamera != null)
            {
                return;
            }

            GameObject go = GameObject.Find(Name);

            if (go != null)
            {
                _main = go.GetComponent <CaptureCamera>();
                return;
            }

            GameObject cameraObject = new GameObject(Name);
            Camera     camera       = cameraObject.AddComponent <Camera>();

            camera.depth            = 0;
            camera.cullingMask      = 1 << layer;
            camera.clearFlags       = CameraClearFlags.SolidColor;
            camera.backgroundColor  = Color.clear;
            camera.orthographic     = true;
            camera.orthographicSize = 5;
            camera.nearClipPlane    = -30;
            camera.farClipPlane     = 30;
            camera.enabled          = false;
#if UNITY_5_4_OR_NEWER
            camera.stereoTargetEye = StereoTargetEyeMask.None;
#endif

#if UNITY_5_6_OR_NEWER
            camera.allowHDR  = false;
            camera.allowMSAA = false;
#endif
            cameraObject.AddComponent <CaptureCamera>();
        }
示例#10
0
        virtual public void Update(UpdateContext context)
        {
            if (graphics != null)
            {
                graphics.alpha  = context.alpha * _alpha;
                graphics.grayed = context.grayed | _grayed;
                graphics.UpdateMaterial(context);
            }

            if (_paintingMode != 0)
            {
                NTexture paintingTexture = paintingGraphics.texture;
                if (paintingTexture != null && paintingTexture.disposed)                 //Texture可能已被Stage.MonitorTexture销毁
                {
                    paintingTexture = null;
                    _paintingFlag   = 1;
                }
                if (_paintingFlag == 1)
                {
                    _paintingFlag = 0;

                    //从优化考虑,决定使用绘画模式的容器都需要明确指定大小,而不是自动计算包围。这在UI使用上并没有问题,因为组件总是有固定大小的
                    int textureWidth  = Mathf.RoundToInt(_contentRect.width + _paintingMargin.left + _paintingMargin.right);
                    int textureHeight = Mathf.RoundToInt(_contentRect.height + _paintingMargin.top + _paintingMargin.bottom);
                    if (paintingTexture == null || paintingTexture.width != textureWidth || paintingTexture.height != textureHeight)
                    {
                        if (paintingTexture != null)
                        {
                            paintingTexture.Dispose(true);
                        }
                        if (textureWidth > 0 && textureHeight > 0)
                        {
                            paintingTexture = new NTexture(CaptureCamera.CreateRenderTexture(textureWidth, textureHeight, UIConfig.depthSupportForPaintingMode));
                            Stage.inst.MonitorTexture(paintingTexture);
                        }
                        else
                        {
                            paintingTexture = null;
                        }
                        paintingGraphics.texture = paintingTexture;
                    }

                    if (paintingTexture != null)
                    {
                        paintingGraphics.DrawRect(
                            new Rect(-_paintingMargin.left, -_paintingMargin.top, paintingTexture.width, paintingTexture.height),
                            new Rect(0, 0, 1, 1), Color.white);
                        paintingGraphics.UpdateMesh();
                    }
                    else
                    {
                        paintingGraphics.ClearMesh();
                    }
                }

                if (paintingTexture != null)
                {
                    paintingTexture.lastActive = Time.time;

                    if (!(this is Container) &&                  //如果是容器,这句移到Container.Update的最后执行,因为容器中可能也有需要Capture的内容,要等他们完成后再进行容器的Capture。
                        (_paintingFlag != 2 || !_cacheAsBitmap))
                    {
                        UpdateContext.OnEnd += _captureDelegate;
                    }
                }

                paintingGraphics.UpdateMaterial(context);
            }

            if (_filter != null)
            {
                _filter.Update();
            }

            Stats.ObjectCount++;
        }
示例#11
0
        virtual public void Update(UpdateContext context)
        {
            if (graphics != null)
            {
                graphics.alpha  = context.alpha * _alpha;
                graphics.grayed = context.grayed | _grayed;
                graphics.UpdateMaterial(context);
            }

            if (_paintingMode != 0)
            {
                NTexture paintingTexture = paintingGraphics.texture;
                if (paintingTexture != null && paintingTexture.disposed)                 //Texture可能已被Stage.MonitorTexture销毁
                {
                    paintingTexture = null;
                    _paintingFlag   = 1;
                }
                if (_paintingFlag == 1)
                {
                    _paintingFlag = 0;

                    //从优化考虑,决定使用绘画模式的容器都需要明确指定大小,而不是自动计算包围。这在UI使用上并没有问题,因为组件总是有固定大小的
                    int textureWidth  = Mathf.RoundToInt(_contentRect.width + _paintingMargin.left + _paintingMargin.right);
                    int textureHeight = Mathf.RoundToInt(_contentRect.height + _paintingMargin.top + _paintingMargin.bottom);
                    if (paintingTexture == null || paintingTexture.width != textureWidth || paintingTexture.height != textureHeight)
                    {
                        if (paintingTexture != null)
                        {
                            paintingTexture.Dispose();
                        }
                        if (textureWidth > 0 && textureHeight > 0)
                        {
                            paintingTexture = new NTexture(CaptureCamera.CreateRenderTexture(textureWidth, textureHeight, false));
                            Stage.inst.MonitorTexture(paintingTexture);
                        }
                        else
                        {
                            paintingTexture = null;
                        }
                        paintingGraphics.texture = paintingTexture;
                    }

                    if (paintingGraphics.material == null)
                    {
                        paintingGraphics.material           = new Material(ShaderConfig.GetShader(ShaderConfig.imageShader));
                        paintingGraphics.material.hideFlags = DisplayOptions.hideFlags;
                    }

                    if (paintingTexture != null)
                    {
                        paintingGraphics.SetOneQuadMesh(
                            new Rect(-_paintingMargin.left, -_paintingMargin.top, paintingTexture.width, paintingTexture.height),
                            new Rect(0, 0, 1, 1), Color.white);
                    }
                    else
                    {
                        paintingGraphics.ClearMesh();
                    }
                }

                if (paintingTexture != null)
                {
                    paintingTexture.lastActive = Time.time;

                    if (!(this is Container))                     //如果是容器,这句移到Container.Update的最后执行,因为容器中可能也有需要Capture的内容,要等他们完成后再进行容器的Capture。
                    {
                        UpdateContext.OnEnd += _captureDelegate;
                    }
                }

                paintingGraphics.UpdateMaterial(context);
            }

            if (_filter != null)
            {
                _filter.Update();
            }

            context.counter++;
        }
        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;
                }
            }
        }
示例#13
0
        void OnEnable()
        {
            cachedCamera = this.GetComponent<Camera>();
            cachedTransform = this.gameObject.transform;

            if (this.gameObject.name == Name)
                _main = this;
        }
示例#14
0
        /// <summary>
        /// 
        /// </summary>
        public static void CheckMain()
        {
            if (_main != null && _main.cachedCamera != null)
                return;

            GameObject go = GameObject.Find(Name);
            if (go != null)
            {
                _main = go.GetComponent<CaptureCamera>();
                return;
            }

            GameObject cameraObject = new GameObject(Name);
            Camera camera = cameraObject.AddComponent<Camera>();
            camera.depth = 0;
            camera.cullingMask = 1 << layer;
            camera.clearFlags = CameraClearFlags.Depth;
            camera.orthographic = true;
            camera.orthographicSize = 5;
            camera.nearClipPlane = -30;
            camera.farClipPlane = 30;
            camera.enabled = false;
            #if UNITY_5_4_OR_NEWER
            camera.stereoTargetEye = StereoTargetEyeMask.None;
            #endif
            cameraObject.AddComponent<CaptureCamera>();
        }
示例#15
0
 public static void ClearStatic()
 {
     _main        = null;
     _layer       = -1;
     _hiddenLayer = -1;
 }