コード例 #1
0
 public static void StartGLWorld(this MonoBehaviour mono, int order = 0)
 {
     UI.owner = mono.gameObject;
     UI.ClearGL();
     UI.gl.order = order;
     GLUI.BeginOrder(0);
 }
コード例 #2
0
        void Tips()
        {
            this.StartIM();
            for (int i = 0; i < rects.Count; i++)
            {
                var rt = rects[i];
                if (rt.Contains(UI.mousePosRef))
                {
                    //show tips
                    IMUI.fontStyle.normal.textColor = tipsTxtColor;
                    var str  = tips[i];
                    var size = IMUI.CalSize(str);
                    size += fontBorder;

                    var os = offset + osFactor * size;
                    GLUI.DrawString(str, UI.mousePosRef + os, Vectors.half2d);
                    GLUI.BeginOrder(2);
                    var bg = new Rect(UI.mousePosRef + os, size, Vectors.half2d);
                    bg.Draw(tipsBgColor, true);

                    if (Events.MouseDown1to3)
                    {
                        Select(i);
                        return;
                    }
                }
            }
        }
コード例 #3
0
        void Thumbnail()
        {
            var startPos = UI.AbsRefPos(thumbnail);

            rects = new List <Rect>();
            //palette = new List<Color>();
            //tips = new List<string>();
            for (int y = 0; y < gridCount.y; y++)
            {
                for (int x = 0; x < gridCount.x; x++)
                {
                    rects.Add(new Rect(startPos + gridOsFactor * new Vector2(x, y) *
                                       (gridOs + Vector2.one * gridSize), gridSize));
                    //palette.Add(colorList[y].colors[x]);
                    //tips.Add(colorList[y].names[x]);
                }
            }
            var i = 0;

            foreach (var rt in rects)
            {
                GLUI.BeginOrder(0);
                rt.Draw(palette[i++], true);
                GLUI.BeginOrder(1);
                if (drawBorder)
                {
                    rt.Draw(drawBorderClr, false);
                }
            }
            GLUI.BeginOrder(0);
            preview.Draw(color, true);
            GLUI.BeginOrder(1);
            preview.Draw(drawPvBorderClr);
        }
コード例 #4
0
ファイル: UIMap.cs プロジェクト: wjk17/WSA
        void Input()
        {
            this.BeginOrtho();
            var vs = UITool.GetVS(rt.cornerLB, rtSize, Vector2.zero);

            GenTex2D();
            GLUI.BeginOrder(0);
            GLUI.DrawTex(tex, vs);

            // frame
            GLUI.BeginOrder(1);
            this.DrawBG(frameWidth, false);
            vs = UITool.GetVS(rt.center, Vector2.one * texPlayerSize, Vectors.half2d);
            GLUI.DrawTex(texPlayer, vs);

            if (Events.MouseDown0)
            {
                prevMousePos = UI.mousePosRef;
                prevViewOs   = viewMapOs;
            }
            else if (Events.Mouse0)
            {
                var os = (UI.mousePosRef - prevMousePos).RoundToInt();
                os        = (os * Vector2.one / viewScale).RoundToInt();
                viewMapOs = prevViewOs - os;
            }
        }
コード例 #5
0
        private void Draw()
        {
            this.StartGLWorld();
            GLUI.DrawGrid(gridSize, gridUnitSize, colorGrid);

            var half = gridSize * 0.5f;

            GLUI.BeginOrder(1);
            GLUI.DrawLineDirect(-half.X(), half.X(), colorAxisX);
            GLUI.DrawLineDirect(-half.Z(), half.Z(), colorAxisZ);

            GLUI.BeginOrder(2);
            var selAxisSize = gridSize * 10f;
            var pos         = transform.position;

            if (drawAxis == 0)
            {
                GLUI.DrawLineDirect(pos - selAxisSize.X(), pos + selAxisSize.X(), colorAxisXSel);
            }
            else if (drawAxis == 1)
            {
                GLUI.DrawLineDirect(pos - selAxisSize.Y(), pos + selAxisSize.Y(), colorAxisYSel);
            }
            else if (drawAxis == 2)
            {
                GLUI.DrawLineDirect(pos - selAxisSize.Z(), pos + selAxisSize.Z(), colorAxisZSel);
            }

            if (dragging && drawAxisProj)
            {
                DrawLineScreen(screenThisPos, screenThisPos + screenAxis.normalized * drawAxisLength, Color.white);
                DrawLineScreen(screenThisPos, mousePosProj, Color.red);
                DrawLineScreen(screenThisPos, UnityEngine.Input.mousePosition, Color.black);
            }
        }
コード例 #6
0
 public static void BeginOrtho(this MonoBehaviour mono, int glOrder = 0)
 {
     UI.owner = mono.gameObject;
     UI.ClearCmd();
     if (glOrder != 0)
     {
         UI.gl.order = glOrder;
     }
     GLUI._insertOrder = 0;
     GLUI.BeginOrder(0);
     GLUI.LoadOrtho();
 }
コード例 #7
0
 public static void BeginOrtho(this object obj, int glOrder = 0)
 {
     UI.owner = obj;
     UI.ClearCmd();
     if (glOrder != 0)
     {
         UI.gl.order = glOrder;
     }
     GLUI._insertOrder = 0;
     GLUI.BeginOrder(0);
     GLUI.LoadOrtho();
 }
コード例 #8
0
ファイル: UIGrid.cs プロジェクト: wjk17/WSA
        public void Input()
        {
            ic.order = drawOrder;
            this.BeginOrtho();
            var startPos = this.AbsRefPos();

            rects = new List <Rect>();
            for (int y = 0; y < gridCount.y; y++)
            {
                for (int x = 0; x < gridCount.x; x++)
                {
                    rects.Add(new Rect(startPos + gridOsFactor * new Vector2(x, y) *
                                       (gridOs + gridSize), gridSize, pivot));
                }
            }
            var i = 0; bool clicked = false;

            foreach (var rt in rects)
            {
                if (visible.NotEmpty() && !visible[i])
                {
                    i++; continue;
                }
                GLUI.fontColor = fontColor;
                GLUI.BeginOrder(0);

                if (!clickable[i])
                {
                    DrawButton(rt, 2);
                }
                else
                {
                    if (rt.Contains(UI.mousePosRef) && clickable[i])
                    {
                        OnOver(i);
                        if (Events.Mouse1to3)
                        {
                            DrawButton(rt, 2);
                            if (Events.MouseDown1to3 && !clicked)
                            {
                                OnClick(i);
                                clicked = true;
                            }
                        }
                        else
                        {
                            DrawButton(rt, 1);
                            if (drawTips)
                            {
                                // tips
                                var str  = names[i];
                                var size = IMUI.CalSize(str);
                                size += fontBorder;

                                var os = offset + osFactor * size;
                                GLUI.DrawString(str, UI.mousePosRef + os, Vectors.half2d);
                                GLUI.BeginOrder(3);
                                var bg = new Rect(UI.mousePosRef + os, size, Vectors.half2d);
                                bg.Draw(Color.white, true);
                            }
                        }
                    }
                    else
                    {
                        DrawButton(rt, 0);
                    }
                    if (drawName)
                    {
                        GLUI.DrawString(names[i], (rt.pos + nameOffset), Vectors.half2d);
                    }
                    GLUI.BeginOrder(1);
                    if (textures.NotEmpty() && textures[i] != null)
                    {
                        GLUI.DrawTex(textures[i], rt.ToPointsCWLT(-1));
                    }

                    GLUI.SetLineMat();
                    GLUI.BeginOrder(0);
                }
                // 待做优化 tex和line分开两个loop
                GLUI.BeginOrder(2);
                if (drawBorder)
                {
                    rt.Draw(drawBorderClr, false);
                }
                i++;
            }
        }
コード例 #9
0
        private void Update()
        {
            this.BeginOrtho();

            Curve2.colorCtrlLines = clrCtrlLinesUnSel;
            Curve2.colorBorder    = clrBorder;

            var offset = m_Ref_Curve.ScaleV2(-drawAreaOffset);

            drawAreaStart = offset.RoundToInt();
            drawAreaEnd   = drawAreaStart + drawAreaSize_I;
            // TODO GridLine 对应 Offset调整
            // TODO Offset 绘制Curve

            var lineSpaceFst = (drawAreaSize * gridFactor).RoundToInt();

            lineSpaceFst = Vector2Int.Max(Vector2Int.one * 2, lineSpaceFst);
            var lineSpaceSnd = (lineSpaceFst * Vectors.half2d).RoundToInt();

            // grids
            var a = drawAreaStart;
            var b = new Vector2(drawAreaEnd.x, drawAreaStart.y);

            for (int i = drawAreaStart.y; i <= drawAreaEnd.y; b.y = a.y = i += 1)
            {
                if (i % lineSpaceSnd.y == 0)
                {
                    DrawLine(a, b, (i % lineSpaceFst.y == 0) ? clrGridLinesFst : clrGridLinesSnd, m_Curve_Ref);
                }
            }
            a = drawAreaStart;
            b = new Vector2(drawAreaStart.x, drawAreaEnd.y);
            for (int i = drawAreaStart.x; i <= drawAreaEnd.x; b.x = a.x = i += 1)
            {
                if (i % lineSpaceSnd.x == 0)
                {
                    DrawLine(a, b, (i % lineSpaceFst.x == 0) ? clrGridLinesFst : clrGridLinesSnd, m_Curve_Ref);
                }
            }
            // Timeline 当前帧
            GLUI.BeginOrder(5);
            b.x = a.x = UITimeLine.I.frameIdx;
            DrawLine(a, b, UITimeLine.I.clrTimeLine, m_Curve_Ref);

            // Axis 坐标轴
            GLUI.BeginOrder(2);
            b.x = a.x = 0;
            a.y = drawAreaStart.y;
            b.y = drawAreaEnd.y;
            DrawLine(a, b, UITimeLine.I.clrAxis, m_Curve_Ref);

            b.y = a.y = 0;
            a.x = drawAreaStart.x;
            b.x = drawAreaEnd.x;
            DrawLine(a, b, UITimeLine.I.clrAxis, m_Curve_Ref);

            if (curveObj == null)
            {
                return;
            }
            var cc = 0;

            // Curve
            foreach (var curve in curveObj.curves)
            {
                if (drawSelOnly)
                {
                    Curve2.colorTrack = clrTracks[(int)_curveSelType];
                }
                else
                {
                    Curve2.colorTrack = clrTracks[cc++];
                }
                if (drawSelOnly && curve != curveSel)
                {
                    continue;
                }
                if (curve == null || curve.Count == 0)
                {
                    continue;
                }
                if (mirror) // 使用默认方法画出曲线线段
                {
                    curveMirror.drawAreaSize   = drawAreaSize;
                    curveMirror.drawAreaOffset = offset;
                    curveMirror.Draw(m_Curve_Ref, showTangentsUnSel);
                }
                else
                {
                    curve.drawAreaSize   = drawAreaSize;
                    curve.drawAreaOffset = offset;
                    curve.Draw(m_Curve_Ref, showTangentsUnSel);
                }

                // 尾线
                GLUI.BeginOrder(3);
                var l = curve.Last().frameKey;
                var e = new Vector2(drawAreaSize.x, l.y);
                DrawLine(l, e, Curve2.colorTrack, m_Curve_Ref);
            }
            GLUI.BeginOrder(4);
            Key2 k = keySel;

            if (drawSel && k != null)
            {
                var i = (subIdxs != null && id < subIdxs.Count) ? subIdxs[id] : -1;


                if (k.inMode == KeyMode.Bezier)
                {
                    DrawLine(k.frameKey, k.inKey, i == 0 || i == 1 ? clrSubSel : clrCtrlLinesSel, m_Curve_Ref);
                    //DrawTangent(k.inTangent, Curve2.colorTangents, matrixViewToRect);
                }
                if (k.outMode == KeyMode.Bezier && !(mirror && k.time == 0.5f))
                {
                    DrawLine(k.frameKey, k.outKey, i == 0 || i == 2 ? clrSubSel : clrCtrlLinesSel, m_Curve_Ref);
                    //DrawTangent(k.outTangent, Curve2.colorTangents, matrixViewToRect);
                }

                DrawRect(k.frameKey, Vector2.one * sizeDrawVector,
                         Curve2.colorVectors, m_Curve_Ref, i == 0 ? clrSubSel : clrVectorSel, true);
                if (k.inMode == KeyMode.Bezier)
                {
                    DrawRhombus(k.inKey, Vector2.one * sizeDrawTangent,
                                Curve2.colorTangents, m_Curve_Ref, i == 0 || i == 1 ? clrSubSel : clrCtrlLinesSel, true);
                }
                if (k.outMode == KeyMode.Bezier && !(mirror && k.time == 0.5f))
                {
                    DrawRhombus(k.outKey, Vector2.one * sizeDrawTangent,
                                Curve2.colorTangents, m_Curve_Ref, i == 0 || i == 2 ? clrSubSel : clrCtrlLinesSel, true);
                }
            }
        }
コード例 #10
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++;
            }
        }
コード例 #11
0
        private void Update()
        {
            this.BeginOrtho();
            this.Draw(Color.grey);
            var pos = UI.AbsRefPos(rtArea) - rtArea.rect.size * 0.5f;
            var scl = rtAreaSize / SizeInt;

            var os           = Matrix4x4.Translate(START);
            var m_CurveToRef = Matrix4x4.TRS(pos, Quaternion.identity, scl) * os;
            var m_RulerToRef = Matrix4x4.TRS(UI.AbsRefPos(ruler) - rulerSize.X() * 0.5f
                                             , Quaternion.identity, rtSize / SizeInt) * os;

            var a = Vector2.zero;
            var b = Vector2.up * SIZE.y;
            var f = 1f / SIZE.x;

            xSpaceTextInRuler = Mathf.RoundToInt(SIZE.x * gridFactorText);
            var fitted = (xSpaceTextInRuler / 5) * 5;

            if (Mathf.Abs(xSpaceTextInRuler - fitted) > maxError)
            {
                fitted = (xSpaceTextInRuler / 2) * 2;
            }

            xSpaceTextInRuler = Mathf.Max(2, fitted);


            xSpaceLineInRuler = Mathf.RoundToInt(SIZE.x * gridFactorLine);
            fitted            = (xSpaceLineInRuler / 5) * 5;
            if (Mathf.Abs(xSpaceLineInRuler - fitted) > maxError)
            {
                fitted = (xSpaceLineInRuler / 2) * 2;
            }

            xSpaceLineInRuler = Mathf.Max(2, xSpaceLineInRuler);

            // grid
            for (int i = Mathf.RoundToInt(-START.x); i < -START.x + SIZE.x; i++)
            {
                if ((i % xSpaceLineInRuler) == 0)
                {
                    a.x = b.x = i; // 曲线空间坐标
                    DrawLine(a, b, I.clrGrid, m_CurveToRef);
                }
                if ((i % xSpaceTextInRuler) == 0)
                {
                    a.x = i + f * 0.5f;
                    Vector2 c = m_RulerToRef.MultiplyPoint(a);
                    c = rulerPos + c.ToLT();
                    GLUI.DrawString(i.ToString(), c, Vectors.half2d);// 画字 帧号标签
                }
            }
            // timeline
            GLUI.BeginOrder(5);
            b.x = a.x = frameIdx;
            DrawLine(a, b, I.clrTimeLine, m_CurveToRef, width);
            // axis
            GLUI.BeginOrder(2);
            b.x = a.x = 0;
            DrawLine(a, b, I.clrAxis, m_CurveToRef, width);
        }