예제 #1
0
 public GoWrapper(GameObject go)
 {
     _owner = go;
     this._skipInFairyBatching = true;
     CreateGameObject("GoWrapper");
     ToolSet.SetParent(_owner.transform, this.cachedTransform);
     CacheRenderers();
 }
예제 #2
0
        /// <summary>
        /// 进入绘画模式,整个对象将画到一张RenderTexture上,然后这种贴图将代替原有的显示内容。
        /// 可以在onPaint回调里对这张纹理进行进一步操作,实现特殊效果。
        /// 可能有多个地方要求进入绘画模式,这里用requestorId加以区别,取值是1、2、4、8、16以此类推。1024内内部保留。用户自定义的id从1024开始。
        /// </summary>
        /// <param name="requestId">请求者id</param>
        /// <param name="margin">纹理四周的留空。如果特殊处理后的内容大于原内容,那么这里的设置可以使纹理扩大。</param>
        public void EnterPaintingMode(int requestorId, Margin?margin)
        {
            bool first = _paintingMode == 0;

            _paintingMode |= requestorId;
            if (first)
            {
                if (paintingGraphics == null)
                {
                    if (graphics == null)
                    {
                        paintingGraphics = new NGraphics(this.gameObject);
                    }
                    else
                    {
                        GameObject go = new GameObject(this.gameObject.name + " (Painter)");
                        go.layer = this.gameObject.layer;
                        ToolSet.SetParent(go.transform, cachedTransform);
                        go.hideFlags     = DisplayOptions.hideFlags;
                        paintingGraphics = new NGraphics(go);
                    }
                }
                else
                {
                    paintingGraphics.enabled = true;
                }
                paintingGraphics.vertexMatrix = null;

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

                if (this is Container)
                {
                    ((Container)this).SetChildrenLayer(CaptureCamera.hiddenLayer);
                    ((Container)this).UpdateBatchingFlags();
                }
                else
                {
                    this.InvalidateBatchingState();
                }

                if (graphics != null)
                {
                    this.gameObject.layer = CaptureCamera.hiddenLayer;
                }

                _paintingMargin = new Margin();
            }
            if (margin != null)
            {
                _paintingMargin = (Margin)margin;
            }
            _paintingFlag = 1;
        }
예제 #3
0
 public GoWrapper(GameObject go)
     : base(null)
 {
     this._go = go;
     this.SetGoLayer(LayerMask.NameToLayer(Stage.LAYER_NAME));
     this.name = "GoWrapper";
     ToolSet.SetParent(this._go.transform, this.rectTransform);
     this.CacheRenderers();
 }
예제 #4
0
        void UpdateHierarchy()
        {
            if (!_ownsGameObject)
            {
                if (gameObject != null)
                {
                    //we dont change transform parent of this object
                    if (parent != null && visible)
                    {
                        gameObject.SetActive(true);
                    }
                    else
                    {
                        gameObject.SetActive(false);
                    }
                }
            }
            else if (parent != null)
            {
                ToolSet.SetParent(cachedTransform, parent.cachedTransform);

                if (_visible)
                {
                    gameObject.SetActive(true);
                }

                int layerValue = parent.gameObject.layer;
                if (parent._paintingMode != 0)
                {
                    layerValue = CaptureCamera.hiddenLayer;
                }

                if ((this is Container) && this.gameObject.layer != layerValue && this._paintingMode == 0)
                {
                    ((Container)this).SetChildrenLayer(layerValue);
                }

                this.layer = layerValue;
            }
            else if (!_disposed && this.gameObject != null && !StageEngine.beingQuit)
            {
                if (Application.isPlaying)
                {
                    if (gOwner == null || gOwner.parent == null)                    //如果gOwner还有parent的话,说明只是暂时的隐藏
                    {
                        ToolSet.SetParent(cachedTransform, _home);
                        if (_home == null)
                        {
                            Object.DontDestroyOnLoad(this.gameObject);
                        }
                    }
                }

                gameObject.SetActive(false);
            }
        }
예제 #5
0
파일: Stage.cs 프로젝트: blueberryWT/CatLib
        internal Transform CreatePoolManager(string name)
        {
            GameObject go = new GameObject("[" + name + "]");

            go.SetActive(false);

            Transform t = go.transform;

            ToolSet.SetParent(t, cachedTransform);

            return(t);
        }
예제 #6
0
        /// <summary>
        ///  设置包装对象。注意如果原来有包装对象,设置新的包装对象后,原来的包装对象只会被删除引用,但不会被销毁。
        /// </summary>
        /// <param name="target"></param>
        /// <param name="cloneMaterial">如果true,则复制材质,否则直接使用sharedMaterial。</param>
        public void setWrapTarget(GameObject target, bool cloneMaterial)
        {
            RecoverMaterials();

            // FairyGUI修改:清除裁剪
            ClearStencil();

            _cloneMaterial = cloneMaterial;
            if (_wrapTarget != null)
            {
                ToolSet.SetParent(_wrapTarget.transform, null);
            }

#if (UNITY_5 || UNITY_5_3_OR_NEWER)
            _canvas = null;
#endif
            _wrapTarget = target;
            _renderers.Clear();
            _sortingOrders.Clear();
            _materials.Clear();

            if (_wrapTarget != null)
            {
                ToolSet.SetParent(_wrapTarget.transform, this.cachedTransform);
#if (UNITY_5 || UNITY_5_3_OR_NEWER)
                _canvas = _wrapTarget.GetComponent <Canvas>();
                if (_canvas != null)
                {
                    _canvas.renderMode      = RenderMode.WorldSpace;
                    _canvas.worldCamera     = StageCamera.main;
                    _canvas.overrideSorting = true;

                    RectTransform rt = _canvas.GetComponent <RectTransform>();
                    rt.pivot    = new Vector2(0, 1);
                    rt.position = new Vector3(0, 0, 0);
                    this.SetSize(rt.rect.width, rt.rect.height);
                }
                else
#endif
                {
                    CacheRenderers();
                    this.SetSize(0, 0);
                }

                Transform[] transforms = _wrapTarget.GetComponentsInChildren <Transform>(true);
                int         lv         = this.layer;
                foreach (Transform t in transforms)
                {
                    t.gameObject.layer = lv;
                }
            }
        }
예제 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        public void ReturnObject(GObject obj)
        {
            string          url = obj.resourceURL;
            Queue <GObject> arr;

            if (!_pool.TryGetValue(url, out arr))
            {
                arr = new Queue <GObject>();
                _pool.Add(url, arr);
            }

            ToolSet.SetParent(obj.displayObject.cachedTransform, _manager);
            arr.Enqueue(obj);
        }
예제 #8
0
        public StencilEraser(Transform parent)
        {
            gameObject = new GameObject("Eraser");
            ToolSet.SetParent(gameObject.transform, parent);
            meshFilter   = gameObject.AddComponent <MeshFilter>();
            meshRenderer = gameObject.AddComponent <MeshRenderer>();
#if (UNITY_5 || UNITY_5_3_OR_NEWER)
            meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
#else
            meshRenderer.castShadows = false;
#endif
            meshRenderer.receiveShadows = false;

            gameObject.layer       = parent.gameObject.layer;
            gameObject.hideFlags   = parent.gameObject.hideFlags;
            meshFilter.hideFlags   = parent.gameObject.hideFlags;
            meshRenderer.hideFlags = parent.gameObject.hideFlags;
        }
        internal void ConstructFromResource(List <GObject> objectPool, int poolIndex)
        {
            this.gameObjectName = packageItem.name;

            XML xml = packageItem.componentData;

            string str;

            string[] arr;

            underConstruct = true;

            arr          = xml.GetAttributeArray("size");
            sourceWidth  = int.Parse(arr[0]);
            sourceHeight = int.Parse(arr[1]);
            initWidth    = sourceWidth;
            initHeight   = sourceHeight;

            SetSize(sourceWidth, sourceHeight);

            arr = xml.GetAttributeArray("pivot");
            if (arr != null)
            {
                float f1 = float.Parse(arr[0]);
                float f2 = float.Parse(arr[1]);
                this.SetPivot(f1, f2, xml.GetAttributeBool("anchor"));
            }

            this.opaque = xml.GetAttributeBool("opaque", true);
            arr         = xml.GetAttributeArray("hitTest");
            if (arr != null)
            {
                PixelHitTestData hitTestData = packageItem.owner.GetPixelHitTestData(arr[0]);
                if (hitTestData != null)
                {
                    this.rootContainer.hitArea = new PixelHitTest(hitTestData, int.Parse(arr[1]), int.Parse(arr[2]));
                }
            }

            OverflowType overflow;

            str = xml.GetAttribute("overflow");
            if (str != null)
            {
                overflow = FieldTypes.ParseOverflowType(str);
            }
            else
            {
                overflow = OverflowType.Visible;
            }

            str = xml.GetAttribute("margin");
            if (str != null)
            {
                _margin.Parse(str);
            }

            if (overflow == OverflowType.Scroll)
            {
                ScrollType scroll;
                str = xml.GetAttribute("scroll");
                if (str != null)
                {
                    scroll = FieldTypes.ParseScrollType(str);
                }
                else
                {
                    scroll = ScrollType.Vertical;
                }

                ScrollBarDisplayType scrollBarDisplay;
                str = xml.GetAttribute("scrollBar");
                if (str != null)
                {
                    scrollBarDisplay = FieldTypes.ParseScrollBarDisplayType(str);
                }
                else
                {
                    scrollBarDisplay = ScrollBarDisplayType.Default;
                }

                int scrollBarFlags = xml.GetAttributeInt("scrollBarFlags");

                Margin scrollBarMargin = new Margin();
                str = xml.GetAttribute("scrollBarMargin");
                if (str != null)
                {
                    scrollBarMargin.Parse(str);
                }

                string vtScrollBarRes = null;
                string hzScrollBarRes = null;
                arr = xml.GetAttributeArray("scrollBarRes");
                if (arr != null)
                {
                    vtScrollBarRes = arr[0];
                    hzScrollBarRes = arr[1];
                }

                SetupScroll(scrollBarMargin, scroll, scrollBarDisplay, scrollBarFlags, vtScrollBarRes, hzScrollBarRes);
            }
            else
            {
                SetupOverflow(overflow);
            }

            arr = xml.GetAttributeArray("clipSoftness");
            if (arr != null)
            {
                this.clipSoftness = new Vector2(int.Parse(arr[0]), int.Parse(arr[1]));
            }

            _buildingDisplayList = true;

            XMLList.Enumerator et = xml.GetEnumerator("controller");
            Controller         controller;

            while (et.MoveNext())
            {
                controller = new Controller();
                _controllers.Add(controller);
                controller.parent = this;
                controller.Setup(et.Current);
            }

            GObject child;

            DisplayListItem[] displayList = packageItem.displayList;
            int childCount = displayList.Length;

            for (int i = 0; i < childCount; i++)
            {
                DisplayListItem di = displayList[i];
                if (objectPool != null)
                {
                    child = objectPool[poolIndex + i];
                }
                else if (di.packageItem != null)
                {
                    di.packageItem.Load();
                    child             = UIObjectFactory.NewObject(di.packageItem);
                    child.packageItem = di.packageItem;
                    child.ConstructFromResource();
                }
                else
                {
                    child = UIObjectFactory.NewObject(di.type);
                }

                child.underConstruct = true;
                child.Setup_BeforeAdd(di.desc);
                child.InternalSetParent(this);
                _children.Add(child);
            }

            this.relations.Setup(xml);

            for (int i = 0; i < childCount; i++)
            {
                _children[i].relations.Setup(displayList[i].desc);
            }

            for (int i = 0; i < childCount; i++)
            {
                child = _children[i];
                child.Setup_AfterAdd(displayList[i].desc);
                child.underConstruct = false;
                if (child.displayObject != null)
                {
                    ToolSet.SetParent(child.displayObject.cachedTransform, this.displayObject.cachedTransform);
                }
            }

            str = xml.GetAttribute("mask");
            if (str != null)
            {
                this.mask = GetChildById(str).displayObject;
            }

            et = xml.GetEnumerator("transition");
            while (et.MoveNext())
            {
                Transition trans = new Transition(this);
                trans.Setup(et.Current);
                _transitions.Add(trans);
            }

            if (_transitions.Count > 0)
            {
                this.onAddedToStage.Add(__addedToStage);
                this.onRemovedFromStage.Add(__removedFromStage);
            }

            ApplyAllControllers();

            _buildingDisplayList = false;
            underConstruct       = false;

            BuildNativeDisplayList();
            SetBoundsChangedFlag();

            ConstructFromXML(xml);
        }
예제 #10
0
파일: GoWrapper.cs 프로젝트: zscboy/bobo
        /// <summary>
        ///  设置包装对象。注意如果原来有包装对象,设置新的包装对象后,原来的包装对象只会被删除引用,但不会被销毁。
        /// </summary>
        /// <param name="target"></param>
        /// <param name="cloneMaterial">如果true,则复制材质,否则直接使用sharedMaterial。</param>
        public void SetWrapTarget(GameObject target, bool cloneMaterial)
        {
            RecoverMaterials();

            _cloneMaterial = cloneMaterial;
            if (_wrapTarget != null)
            {
                ToolSet.SetParent(_wrapTarget.transform, null);
            }

#if (UNITY_5 || UNITY_5_3_OR_NEWER)
            _canvas = null;
#endif
            _wrapTarget = target;
            _renderers.Clear();
            _sortingOrders.Clear();
            _materials.Clear();

            if (_wrapTarget != null)
            {
                ToolSet.SetParent(_wrapTarget.transform, this.cachedTransform);
#if (UNITY_5 || UNITY_5_3_OR_NEWER)
                _canvas = _wrapTarget.GetComponent <Canvas>();
                if (_canvas != null)
                {
                    _canvas.renderMode      = RenderMode.WorldSpace;
                    _canvas.worldCamera     = StageCamera.main;
                    _canvas.overrideSorting = true;

                    RectTransform rt = _canvas.GetComponent <RectTransform>();
                    // LLWANT modify from '(0.0f, 1.0f)' to '(0.5f, 0.5f)'
                    rt.pivot    = new Vector2(0.5f, 0.5f);
                    rt.position = new Vector3(0, 0, 0);
                    this.SetSize(rt.rect.width, rt.rect.height);

                    // LLWANT ADD, cached renderers of canvas children
                    _renderers.Clear();
                    _sortingOrders.Clear();
                    _wrapTarget.GetComponentsInChildren <Renderer>(true, _renderers);
                    _sortingOrders.Capacity = _renderers.Count;
                    for (int i = 0; i < _renderers.Count; i++)
                    {
                        _sortingOrders.Add(_renderers[i].sortingOrder);
                    }
                    // LLWANT ADD END
                }
                else
#endif
                {
                    CacheRenderers();
                    this.SetSize(0, 0);
                }

                Transform[] transforms = _wrapTarget.GetComponentsInChildren <Transform>(true);
                int         lv         = this.layer;
                foreach (Transform t in transforms)
                {
                    t.gameObject.layer = lv;
                }
            }
        }