コード例 #1
0
ファイル: UIStencilMaterials.cs プロジェクト: Matodor/mUI
 static UIStencilMaterials()
 {
     if (_instance == null)
     {
         _instance = new UIStencilMaterials();
     }
 }
コード例 #2
0
        internal virtual void SetupView(UIViewProps props, IView parent, object[] @params)
        {
            if (props == null)
            {
                throw new Exception("UIView: UIViewProps can not be null");
            }

            SetupParent((UIObject)parent);
            ApplyProps(props, parent);
            InitCompleted(true);

            if (_stencilId.HasValue && _stencilId.Value != 0)
            {
                // TODO при изменении padding изменение canvas
                var meshRenderer = GameObject.AddComponent <MeshRenderer>();
                meshRenderer.sharedMaterial = UIStencilMaterials.GetOrCreate(_stencilId.Value).CanvasMaterial;
                meshRenderer.sharedMaterial.SetTexture("_MainTex", Texture2D.blackTexture);
                meshRenderer.sortingOrder = SortingOrder;

                SortingOrderChanged += sender =>
                {
                    meshRenderer.sortingOrder = SortingOrder;
                };

                UIStencilMaterials.CreateMesh(this);
            }

            mUI.ObjectCreated(this);
            CreateInterface(@params);
        }
コード例 #3
0
ファイル: UISpriteRenderer.cs プロジェクト: Matodor/mUI
        public UISpriteRenderer(UIObject obj, UISpriteSettings settings)
        {
            Renderer                = obj.GameObject.AddComponent <SpriteRenderer>();
            Renderer.sprite         = settings.Sprite;
            Renderer.sharedMaterial = UIStencilMaterials.GetOrCreate(obj.ParentView.StencilId ?? 0).SpritesMaterial;

            if (settings.Color.HasValue)
            {
                SetColor(settings.Color.Value);
            }

            _object = obj;

            obj.SortingOrderChanged += sender =>
            {
                Renderer.sortingOrder = sender.SortingOrder();
            };
        }
コード例 #4
0
ファイル: UISpriteRenderer.cs プロジェクト: Matodor/mUI
        public UISprite SetMask(Sprite mask, bool useAlphaClip = true, bool insideMask = true)
        {
            if (SpriteMask == null)
            {
                SpriteMask = _object.Sprite(new UISpriteSettings
                {
                    Sprite = mask,
                });

                var layer = UIStencilMaterials.Create(1,
                                                      insideMask ? CompareFunction.Equal : CompareFunction.NotEqual, StencilOp.Replace, 1, 1);

                SpriteMask.Renderer.material = layer.CanvasMaterial;
                SpriteMask.Renderer.material.SetFloat("_UseUIAlphaClip", useAlphaClip ? 1f : 0f);
                SpriteMask.Renderer.material.SetFloat("_UseUIAlphaClip", useAlphaClip ? 1f : 0f);
                SpriteMask.Renderer.color = new Color32(255, 255, 255, 0);
                Renderer.material         = layer.SpritesMaterial;
            }

            return(SpriteMask);
        }