Ejemplo n.º 1
0
        public static TextBox CreateTextBox(Vector2Int pos, int height, int width)
        {
            GameObject gameObject = new GameObject("TextBox");

            gameObject.transform.Position = pos;

            //添加一个TextBox控件,用于寻找对应的Lable
            TextBox textBox = gameObject.AddComponent <TextBox>();

            //添加Label控件
            for (int i = height; i > 0; i--)
            {
                textBox.Labels.Add(CreateLabel(pos + new Vector2Int(1, i), "", width));
            }
            #region 创建边框
            int boxWidth = width + 2, boxHeight = height + 2;
            //添加一个方框
            GameObject boxDrawing = new GameObject("BoxDrawing");
            boxDrawing.transform.Position = pos;
            Mesh mesh = boxDrawing.AddComponent <Mesh>();

            List <Vector2Int> meshList = new List <Vector2Int>();
            //添加上下边框的Mesh
            for (int i = 0; i < boxWidth; i++)
            {
                meshList.Add(new Vector2Int(i, 0));
                meshList.Add(new Vector2Int(i, boxHeight - 1));
            }
            //添加左右边框的Mesh
            for (int i = 0; i < boxHeight; i++)
            {
                meshList.Add(new Vector2Int(0, i));
                meshList.Add(new Vector2Int(boxWidth - 1, i));
            }
            mesh.Init(meshList);

            Renderer renderer = boxDrawing.AddComponent <Renderer>();

            //添加边框的贴图
            StringBuilder sb = new StringBuilder();
            sb.Append(BoxDrawingSupply.GetFirstLine(boxWidth));
            for (int i = 0; i < boxHeight - 2; i++)
            {
                sb.Append(' ');
                sb.Append(BoxDrawingSupply.boxVertical);
                sb.Append(BoxDrawingSupply.boxVertical);
                sb.Append(' ');
            }
            sb.Append(BoxDrawingSupply.GetLastLine(boxWidth));

            renderer.Init(sb.ToString(), -1);
            #endregion
            //("wtf:" + textBox.labels[1].GetComponent<Renderer>().Pos_RenderPoint[new Vector2Int(2,0)].Depth);

            return(textBox);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 添加贴图
        /// </summary>
        private void AddTexture()
        {
            //添加边框的贴图
            StringBuilder sb = new StringBuilder();

            sb.Append(BoxDrawingSupply.GetFirstLine(Width));
            for (int i = 0; i < Height - 2; i++)
            {
                sb.Append(' ');
                sb.Append(BoxDrawingSupply.boxVertical);
                sb.Append(BoxDrawingSupply.boxVertical);
                sb.Append(' ');
            }
            sb.Append(BoxDrawingSupply.GetLastLine(Width));
            Str = sb.ToString();
        }