示例#1
0
文件: UIGrid_2_0.cs 项目: wjk17/WSA
        public void Input()
        {
            this.BeginOrtho(drawOrder);
            var RT       = new RectTrans(this);
            var startPos = margin + RT.centerT;

            var psy = startPos.Average(osAbs.Y(), gridCount.y, Vector2.zero);

            for (int y = 0; y < gridCount.y; y++)
            {
                var os = osAbs != Vector2.zero ? osAbs : gridOs + gridSize;
                var ps = psy[y].Average(os.x, gridCount.x, Vectors.halfRight2d);
                for (int x = 0; x < gridCount.x; x++)
                {
                    var n = new Rect(ps[x], gridSize, pivot);
                    gridUnitProp[y * gridCount.x + x].rect = n;
                }
            }
            var i = 0; bool clicked = false;

            foreach (var gup in gridUnitProp)
            {
                if (!gup.visible)
                {
                    i++; continue;
                }
                GLUI.SetFontColor(fontColor);
                GLUI.BeginOrder(0);

                if (!gup.clickable)
                {
                    DrawButton(gup, 2);
                    if (drawName)
                    {
                        gup.DrawName(nameOffset);
                    }

                    if (gup.Hover())
                    {
                        Events.Use();
                    }
                }
                else
                {
                    if (gup.Hover() && !Events.used)
                    {
                        OnOver(i);
                        if (Events.Mouse1to3)
                        {
                            DrawButton(gup, 2);
                            if (Events.MouseDown1to3 && !clicked)
                            {
                                OnClick(i);
                                clicked = true;
                            }
                        }
                        else
                        {
                            DrawButton(gup, 1);
                        }
                        Events.Use();
                    }
                    else
                    {
                        DrawButton(gup, 0);
                    }

                    if (drawName)
                    {
                        gup.DrawName(nameOffset);
                    }

                    GLUI.BeginOrder(1);

                    if (gup.texture != null)
                    {
                        gup.DrawTexture();
                    }

                    GLUI.SetLineMat();
                    GLUI.BeginOrder(0);
                }
                // 待做优化 tex和line分开两个loop
                GLUI.BeginOrder(2);
                if (drawBorder)
                {
                    gup.rect.Draw(drawBorderClr, false);
                }
                i++;
            }
        }