Esempio n. 1
0
        protected override void Rebuild()
        {
            _needRebuild = false;

            if (frameCount == 0)
            {
                quadBatch.enabled = false;
                return;
            }

            quadBatch.enabled = true;
            Vector3[] verts     = new Vector3[frameCount * 4];
            Vector2[] uv        = new Vector2[frameCount * 4];
            Rect      EmptyRect = new Rect(0, 0, 0, 0);

            for (int i = 0; i < frameCount; i++)
            {
                Frame frame = frames[i];
                if (frame.texture != null)
                {
                    QuadBatch.FillVertsOfQuad(verts, i * 4, frame.rect, this.scaleX, this.scaleY);
                    QuadBatch.FillUVOfQuad(uv, i * 4, frame.texture.uvRect);
                }
                else
                {
                    QuadBatch.FillVertsOfQuad(verts, i * 4, EmptyRect);
                    QuadBatch.FillUVOfQuad(uv, i * 4, EmptyRect);
                }
            }
            quadBatch.Fill(verts, uv, _color);
            quadBatch.SetQuadAlpha(_currentFrame, 1, 1f, 0f);
        }
Esempio n. 2
0
        private void Rebuild()
        {
            _needRebuild = false;
            float rectWidth  = contentRect.width * this.scaleX;
            float rectHeight = contentRect.height * this.scaleY;

            if (_lineSize == 0)
            {
                quadBatch.Fill(new Rect(0, 0, rectWidth, rectHeight), 1, 1, new Rect(0, 0, 1, 1), _fillColor);
            }
            else
            {
                Vector3[] verts = new Vector3[20];
                Vector2[] uv    = new Vector2[20];
                Color32[] cols  = new Color32[20];

                int lineSize = Mathf.CeilToInt(Mathf.Min(_lineSize * this.scaleX, _lineSize * this.scaleY));

                Rect rect;
                //left,right
                rect = Rect.MinMaxRect(0, 0, lineSize, rectHeight);
                QuadBatch.FillVertsOfQuad(verts, 0, rect);
                rect = Rect.MinMaxRect(rectWidth - lineSize, 0, rectWidth, rectHeight);
                QuadBatch.FillVertsOfQuad(verts, 4, rect);

                //top, bottom
                rect = Rect.MinMaxRect(lineSize, 0, rectWidth - lineSize, lineSize);
                QuadBatch.FillVertsOfQuad(verts, 8, rect);
                rect = Rect.MinMaxRect(lineSize, rectHeight - lineSize, rectWidth - lineSize, rectHeight);
                QuadBatch.FillVertsOfQuad(verts, 12, rect);

                //middle
                rect = Rect.MinMaxRect(lineSize, lineSize, rectWidth - lineSize, rectHeight - lineSize);
                QuadBatch.FillVertsOfQuad(verts, 16, rect);

                rect = new Rect(0, 0, 1, 1);
                int i;
                for (i = 0; i < 5; i++)
                {
                    QuadBatch.FillUVOfQuad(uv, i * 4, rect);
                }

                Color32 col32 = _lineColor;
                for (i = 0; i < 16; i++)
                {
                    cols[i] = col32;
                }

                col32 = _fillColor;
                for (i = 16; i < 20; i++)
                {
                    cols[i] = col32;
                }

                quadBatch.Fill(verts, uv, cols);
            }
        }
Esempio n. 3
0
        public InputCaret()
        {
            gameObject = new GameObject("InputCaret");
            gameObject.hideFlags = HideFlags.HideInHierarchy;
            gameObject.layer = Stage.defaultLayer;
            Object.DontDestroyOnLoad(gameObject);

            quadBatch = new QuadBatch(gameObject);
            quadBatch.texture = NTexture.Empty;
            quadBatch.enabled = false;

            cachedTransform = gameObject.transform;
        }
Esempio n. 4
0
        public InputCaret()
        {
            gameObject           = new GameObject("InputCaret");
            gameObject.hideFlags = HideFlags.HideInHierarchy;
            gameObject.layer     = Stage.defaultLayer;
            Object.DontDestroyOnLoad(gameObject);

            quadBatch         = new QuadBatch(gameObject);
            quadBatch.texture = NTexture.Empty;
            quadBatch.enabled = false;

            cachedTransform = gameObject.transform;
        }
        public Highlighter()
        {
            gameObject           = new GameObject("Highlighter");
            gameObject.hideFlags = HideFlags.HideInHierarchy;
            gameObject.layer     = Stage.defaultLayer;
            Object.DontDestroyOnLoad(gameObject);
            cachedTransform = gameObject.transform;

            quadBatch         = new QuadBatch(gameObject);
            quadBatch.texture = NTexture.Empty;
            quadBatch.enabled = false;

            _color = new Color(1f, 223f / 255f, 141f / 255f, 0.5f);
            _rects = new List <Rect>();
        }
Esempio n. 6
0
        public Highlighter()
        {
            gameObject = new GameObject("Highlighter");
            gameObject.hideFlags = HideFlags.HideInHierarchy;
            gameObject.layer = Stage.defaultLayer;
            Object.DontDestroyOnLoad(gameObject);
            cachedTransform = gameObject.transform;

            quadBatch = new QuadBatch(gameObject);
            quadBatch.texture = NTexture.Empty;
            quadBatch.enabled = false;

            _color = new Color(1f, 223f / 255f, 141f / 255f, 0.5f);
            _rects = new List<Rect>();
        }
Esempio n. 7
0
 public void DrawRect(float aWidth, float aHeight, int lineSize, Color lineColor, Color fillColor)
 {
     if (quadBatch == null)
     {
         quadBatch = new QuadBatch(gameObject);
         quadBatch.texture = NTexture.Empty;
         InvalidateBatchingState();
     }
     _empty = false;
     optimizeNotTouchable = false;
     contentRect = new Rect(0, 0, aWidth, aHeight);
     _needRebuild = true;
     _lineSize = lineSize;
     _lineColor = lineColor;
     _fillColor = fillColor;
 }
Esempio n. 8
0
        public void Create(NTexture texture)
        {
            quadBatch        = new QuadBatch(gameObject);
            quadBatch.shader = ShaderConfig.imageShader;

            _texture = texture;
            _color   = Color.white;
            if (_texture != null)
            {
                contentRect.width  = _texture.width;
                contentRect.height = _texture.height;
                UpdateTexture();
            }
            optimizeNotTouchable = true;
            scaleOverrided       = true;
        }
Esempio n. 9
0
 public void DrawRect(float aWidth, float aHeight, int lineSize, Color lineColor, Color fillColor)
 {
     if (quadBatch == null)
     {
         quadBatch         = new QuadBatch(gameObject);
         quadBatch.texture = NTexture.Empty;
         InvalidateBatchingState();
     }
     _empty = false;
     optimizeNotTouchable = false;
     contentRect          = new Rect(0, 0, aWidth, aHeight);
     _needRebuild         = true;
     _lineSize            = lineSize;
     _lineColor           = lineColor;
     _fillColor           = fillColor;
 }
Esempio n. 10
0
        public TextField()
        {
            _textFormat = new TextFormat();
            _textFormat.size = 12;
            _textFormat.lineSpacing = 3;
            _fontScale = 1;
            _strokeColor = new Color(0, 0, 0, 1);

            _wordWrap = true;
            _displayAsPassword = false;
            optimizeNotTouchable = true;
            _maxLength = int.MaxValue;
            _text = string.Empty;

            _elements = new List<HtmlElement>();
            _lines = new List<LineInfo>();

            quadBatch = new QuadBatch(gameObject);

            onFocusIn = new EventListener(this, "onFocusIn");
            onFocusOut = new EventListener(this, "onFocusOut");
            onChanged = new EventListener(this, "onChanged");
        }
Esempio n. 11
0
        public void EndUpdate()
        {
            if (_rects.Count == 0)
            {
                quadBatch.enabled = false;
                return;
            }
            quadBatch.enabled = true;

            Vector3[] verts;
            Vector2[] uv;
            int       count = _rects.Count * 4;

            verts = new Vector3[count];
            uv    = new Vector2[count];
            Rect uvRect = new Rect(0, 0, 1, 1);

            for (int i = 0; i < count; i += 4)
            {
                QuadBatch.FillVertsOfQuad(verts, i, _rects[i / 4]);
                QuadBatch.FillUVOfQuad(uv, i, uvRect);
            }
            quadBatch.Fill(verts, uv, _color);
        }
Esempio n. 12
0
        public void PrintTo(Mesh mesh, Rect localRect)
        {
            if (_needRebuild)
            {
                Rebuild();
            }

            Rect uvRect = _texture.uvRect;

            if (_flip != FlipType.None)
            {
                ToolSet.flipRect(ref uvRect, _flip);
            }

            Vector3[] verts;
            Vector2[] uv;
            Color32[] colors;
            int[]     triangles;
            int       vertCount = 0;

            if (_scaleByTile)
            {
                verts = new Vector3[quadBatch.vertices.Length];
                uv    = new Vector2[quadBatch.uv.Length];

                float rx = this.scaleX / GRoot.contentScaleFactor;
                float ry = this.scaleY / GRoot.contentScaleFactor;

                int   hc         = Mathf.CeilToInt(rx);
                int   vc         = Mathf.CeilToInt(ry);
                float partWidth  = contentRect.width * (rx - (hc - 1));
                float partHeight = contentRect.height * (ry - (vc - 1));
                localRect.xMin *= rx;
                localRect.xMax *= rx;
                localRect.yMin *= ry;
                localRect.yMax *= ry;

                Vector2 offset = new Vector2(0, 0);
                for (int i = 0; i < hc; i++)
                {
                    for (int j = 0; j < vc; j++)
                    {
                        Rect rect = new Rect(i * contentRect.width, j * contentRect.height,
                                             i == (hc - 1) ? partWidth : contentRect.width, j == (vc - 1) ? partHeight : contentRect.height);
                        Rect uvTmp = uvRect;
                        if (i == hc - 1)
                        {
                            uvTmp.xMax = Mathf.Lerp(uvRect.xMin, uvRect.xMax, partWidth / contentRect.width);
                        }
                        if (j == vc - 1)
                        {
                            uvTmp.yMin = Mathf.Lerp(uvRect.yMin, uvRect.yMax, 1 - partHeight / contentRect.height);
                        }

                        Rect bound = ToolSet.Intersection(ref rect, ref localRect);
                        if (bound.xMax - bound.xMin >= 0 && bound.yMax - bound.yMin > 0)
                        {
                            float u0 = (bound.xMin - rect.x) / rect.width;
                            float u1 = (bound.xMax - rect.x) / rect.width;
                            float v0 = (rect.y + rect.height - bound.yMax) / rect.height;
                            float v1 = (rect.y + rect.height - bound.yMin) / rect.height;
                            u0 = Mathf.Lerp(uvTmp.xMin, uvTmp.xMax, u0);
                            u1 = Mathf.Lerp(uvTmp.xMin, uvTmp.xMax, u1);
                            v0 = Mathf.Lerp(uvTmp.yMin, uvTmp.yMax, v0);
                            v1 = Mathf.Lerp(uvTmp.yMin, uvTmp.yMax, v1);
                            QuadBatch.FillUVOfQuad(uv, vertCount, Rect.MinMaxRect(u0, v0, u1, v1));

                            if (i == 0 && j == 0)
                            {
                                offset = new Vector2(bound.x, bound.y);
                            }
                            bound.x -= offset.x;
                            bound.y -= offset.y;

                            QuadBatch.FillVertsOfQuad(verts, vertCount, bound, GRoot.contentScaleFactor, GRoot.contentScaleFactor);

                            vertCount += 4;
                        }
                    }
                }
            }
            else if (_scale9Grid == null || (this.scaleX == 1 && this.scaleY == 1))
            {
                verts = new Vector3[quadBatch.vertices.Length];
                uv    = new Vector2[quadBatch.uv.Length];

                Rect bound = ToolSet.Intersection(ref contentRect, ref localRect);

                float u0 = bound.xMin / contentRect.width;
                float u1 = bound.xMax / contentRect.width;
                float v0 = (contentRect.height - bound.yMax) / contentRect.height;
                float v1 = (contentRect.height - bound.yMin) / contentRect.height;
                u0 = Mathf.Lerp(uvRect.xMin, uvRect.xMax, u0);
                u1 = Mathf.Lerp(uvRect.xMin, uvRect.xMax, u1);
                v0 = Mathf.Lerp(uvRect.yMin, uvRect.yMax, v0);
                v1 = Mathf.Lerp(uvRect.yMin, uvRect.yMax, v1);
                QuadBatch.FillUVOfQuad(uv, 0, Rect.MinMaxRect(u0, v0, u1, v1));

                bound.x = 0;
                bound.y = 0;
                QuadBatch.FillVertsOfQuad(verts, 0, bound, scaleX, scaleY);
                vertCount += 4;
            }
            else
            {
                verts = new Vector3[36];
                uv    = new Vector2[36];

                localRect.xMin *= this.scaleX;
                localRect.xMax *= this.scaleX;
                localRect.yMin *= this.scaleY;
                localRect.yMax *= this.scaleY;

                float scale9Width  = contentRect.width * this.scaleX / GRoot.contentScaleFactor;
                float scale9Height = contentRect.height * this.scaleY / GRoot.contentScaleFactor;

                float[] rows;
                float[] cols;
                float[] dRows;
                float[] dCols;
                Rect    gridRect = (Rect)_scale9Grid;

                rows = new float[] { 0, gridRect.yMin, gridRect.yMax, contentRect.height };
                cols = new float[] { 0, gridRect.xMin, gridRect.xMax, contentRect.width };

                if (scale9Height >= (contentRect.height - gridRect.height))
                {
                    dRows = new float[] { 0, gridRect.yMin, scale9Height - (contentRect.height - gridRect.yMax), scale9Height }
                }
                ;
                else
                {
                    float tmp = gridRect.yMin / (contentRect.height - gridRect.yMax);
                    tmp   = scale9Height * tmp / (1 + tmp);
                    dRows = new float[] { 0, tmp, tmp, scale9Height };
                }

                if (scale9Width >= (contentRect.width - gridRect.width))
                {
                    dCols = new float[] { 0, gridRect.xMin, scale9Width - (contentRect.width - gridRect.xMax), scale9Width }
                }
                ;
                else
                {
                    float tmp = gridRect.xMin / (contentRect.width - gridRect.xMax);
                    tmp   = scale9Width * tmp / (1 + tmp);
                    dCols = new float[] { 0, tmp, tmp, scale9Width };
                }

                float scaleXLeft = contentRect.width * this.scaleX / scale9Width;
                float scaleYLeft = contentRect.height * this.scaleY / scale9Height;

                Vector2 offset = new Vector2();
                for (int cy = 0; cy < 3; cy++)
                {
                    for (int cx = 0; cx < 3; cx++)
                    {
                        Rect rect = Rect.MinMaxRect(dCols[cx] * scaleXLeft, dRows[cy] * scaleYLeft,
                                                    dCols[cx + 1] * scaleXLeft, dRows[cy + 1] * scaleYLeft);
                        Rect bound = ToolSet.Intersection(ref rect, ref localRect);
                        if (bound.xMax - bound.xMin >= 0 && bound.yMax - bound.yMin > 0)
                        {
                            Rect texBound = Rect.MinMaxRect(uvRect.x + cols[cx] / contentRect.width * uvRect.width,
                                                            uvRect.y + (1 - rows[cy + 1] / contentRect.height) * uvRect.height,
                                                            uvRect.x + cols[cx + 1] / contentRect.width * uvRect.width,
                                                            uvRect.y + (1 - rows[cy] / contentRect.height) * uvRect.height);

                            float u0 = (bound.xMin - rect.x) / rect.width;
                            float u1 = (bound.xMax - rect.x) / rect.width;
                            float v0 = (rect.y + rect.height - bound.yMax) / rect.height;
                            float v1 = (rect.y + rect.height - bound.yMin) / rect.height;
                            u0 = Mathf.Lerp(texBound.xMin, texBound.xMax, u0);
                            u1 = Mathf.Lerp(texBound.xMin, texBound.xMax, u1);
                            v0 = Mathf.Lerp(texBound.yMin, texBound.yMax, v0);
                            v1 = Mathf.Lerp(texBound.yMin, texBound.yMax, v1);
                            QuadBatch.FillUVOfQuad(uv, vertCount, Rect.MinMaxRect(u0, v0, u1, v1));

                            if (vertCount == 0)
                            {
                                offset = new Vector2(bound.x, bound.y);
                            }
                            bound.x -= offset.x;
                            bound.y -= offset.y;
                            QuadBatch.FillVertsOfQuad(verts, vertCount, bound);

                            vertCount += 4;
                        }
                    }
                }
            }

            if (vertCount != verts.Length)
            {
                Array.Resize(ref verts, vertCount);
                Array.Resize(ref uv, vertCount);
            }
            int triangleCount = (vertCount >> 1) * 3;

            triangles = new int[triangleCount];
            int k = 0;

            for (int i = 0; i < vertCount; i += 4)
            {
                triangles[k++] = i;
                triangles[k++] = i + 1;
                triangles[k++] = i + 2;

                triangles[k++] = i + 2;
                triangles[k++] = i + 3;
                triangles[k++] = i;
            }

            colors = new Color32[vertCount];
            for (int i = 0; i < vertCount; i++)
            {
                Color col = _color;
                col.a     = this.alpha;
                colors[i] = col;
            }

            mesh.Clear();
            mesh.vertices  = verts;
            mesh.uv        = uv;
            mesh.triangles = triangles;
            mesh.colors32  = colors;
        }
Esempio n. 13
0
        virtual protected void Rebuild()
        {
            _needRebuild = false;
            if (_texture == null || scaleX == 0 || scaleY == 0)
            {
                quadBatch.enabled = false;
                return;
            }

            quadBatch.enabled = true;

            Rect uvRect = _texture.uvRect;

            if (_flip != FlipType.None)
            {
                ToolSet.flipRect(ref uvRect, _flip);
            }

            if (_scaleByTile)
            {
                float rx = this.scaleX / GRoot.contentScaleFactor;
                float ry = this.scaleY / GRoot.contentScaleFactor;

                int       hc         = Mathf.CeilToInt(rx);
                int       vc         = Mathf.CeilToInt(ry);
                float     partWidth  = contentRect.width * (rx - (hc - 1));
                float     partHeight = contentRect.height * (ry - (vc - 1));
                Vector3[] verts      = new Vector3[hc * vc * 4];
                Vector2[] uv         = new Vector2[verts.Length];

                int k = 0;
                for (int i = 0; i < hc; i++)
                {
                    for (int j = 0; j < vc; j++)
                    {
                        QuadBatch.FillVertsOfQuad(verts, k,
                                                  new Rect(i * contentRect.width, j * contentRect.height,
                                                           i == (hc - 1) ? partWidth : contentRect.width, j == (vc - 1) ? partHeight : contentRect.height),
                                                  GRoot.contentScaleFactor, GRoot.contentScaleFactor);
                        Rect uvTmp = uvRect;
                        if (i == hc - 1)
                        {
                            uvTmp.xMax = Mathf.Lerp(uvRect.xMin, uvRect.xMax, partWidth / contentRect.width);
                        }
                        if (j == vc - 1)
                        {
                            uvTmp.yMin = Mathf.Lerp(uvRect.yMin, uvRect.yMax, 1 - partHeight / contentRect.height);
                        }
                        QuadBatch.FillUVOfQuad(uv, k, uvTmp);
                        k += 4;
                    }
                }

                quadBatch.Fill(verts, uv, _color);
            }
            else if (_scale9Grid == null || (this.scaleX == 1 && this.scaleY == 1))
            {
                quadBatch.Fill(contentRect, this.scaleX, this.scaleY, uvRect, _color);
            }
            else
            {
                float scale9Width  = contentRect.width * this.scaleX / GRoot.contentScaleFactor;
                float scale9Height = contentRect.height * this.scaleY / GRoot.contentScaleFactor;

                float[] rows;
                float[] cols;
                float[] dRows;
                float[] dCols;
                Rect    gridRect = (Rect)_scale9Grid;

                rows = new float[] { 0, gridRect.yMin, gridRect.yMax, contentRect.height };
                cols = new float[] { 0, gridRect.xMin, gridRect.xMax, contentRect.width };

                if (scale9Height >= (contentRect.height - gridRect.height))
                {
                    dRows = new float[] { 0, gridRect.yMin, scale9Height - (contentRect.height - gridRect.yMax), scale9Height }
                }
                ;
                else
                {
                    float tmp = gridRect.yMin / (contentRect.height - gridRect.yMax);
                    tmp   = scale9Height * tmp / (1 + tmp);
                    dRows = new float[] { 0, tmp, tmp, scale9Height };
                }

                if (scale9Width >= (contentRect.width - gridRect.width))
                {
                    dCols = new float[] { 0, gridRect.xMin, scale9Width - (contentRect.width - gridRect.xMax), scale9Width }
                }
                ;
                else
                {
                    float tmp = gridRect.xMin / (contentRect.width - gridRect.xMax);
                    tmp   = scale9Width * tmp / (1 + tmp);
                    dCols = new float[] { 0, tmp, tmp, scale9Width };
                }

                Vector3[] verts = new Vector3[16];
                Vector2[] uv    = new Vector2[16];

                int k = 0;
                for (int cy = 0; cy < 4; cy++)
                {
                    for (int cx = 0; cx < 4; cx++)
                    {
                        Vector2 subTextCoords;
                        subTextCoords.x = uvRect.x + cols[cx] / contentRect.width * uvRect.width;
                        subTextCoords.y = uvRect.y + (1 - rows[cy] / contentRect.height) * uvRect.height;
                        uv[k]           = subTextCoords;

                        Vector3 drawCoords;
                        drawCoords.x = dCols[cx] * GRoot.contentScaleFactor;
                        drawCoords.y = -dRows[cy] * GRoot.contentScaleFactor;
                        drawCoords.z = 0;
                        verts[k]     = drawCoords;

                        k++;
                    }
                }

                quadBatch.Fill(verts, uv, _color, QuickIndices.Grid9);
            }
        }
Esempio n. 14
0
        public void Create(NTexture texture)
        {
            quadBatch = new QuadBatch(gameObject);
            quadBatch.shader = ShaderConfig.imageShader;

            _texture = texture;
            _color = Color.white;
            if (_texture != null)
            {
                contentRect.width = _texture.width;
                contentRect.height = _texture.height;
                UpdateTexture();
            }
            optimizeNotTouchable = true;
            scaleOverrided = true;
        }