예제 #1
0
 static void Pie_Internal([OvldDefault(nameof(Radius))] float radius,
                          [OvldDefault(nameof(Color))] DiscColors colors,
                          float angleRadStart,
                          float angleRadEnd)
 {
     DiscCore(false, true, radius, 0f, colors, angleRadStart, angleRadEnd);
 }
예제 #2
0
 static void Arc_Internal([OvldDefault(nameof(Radius))] float radius,
                          [OvldDefault(nameof(Thickness))] float thickness,
                          [OvldDefault(nameof(Color))] DiscColors colors,
                          float angleRadStart,
                          float angleRadEnd,
                          [OvldDefault(nameof(ArcEndCap) + "." + nameof(ArcEndCap.None))] ArcEndCap endCaps)
 {
     DiscCore(true, true, radius, thickness, colors, angleRadStart, angleRadEnd, endCaps);
 }
예제 #3
0
        void DrawShapes()
        {
            Vector2 center    = position.size / 2;
            float   fitRadius = Mathf.Min(position.width, position.height) / 2 - 8;

            // set doot positions
            float t = (float)EditorApplication.timeSinceStartup / 2;

            foreach (Doot doot in doots)
            {
                float   ang = doot.angSpeed * t * ShapesMath.TAU + doot.angOffset;
                Vector2 dir = ShapesMath.AngToDir(ang);
                doot.pos = dir * (fitRadius * doot.radialOffset);
            }

            // mouse doot~
            Vector2 mouseRawPos    = Event.current.mousePosition - center;
            float   maxRadius      = fitRadius * DOOT_MAX_RADIUS;
            Vector2 mouseTargetPos = Vector2.ClampMagnitude(mouseRawPos, maxRadius);

            doots[0].pos = Vector2.Lerp(doots[0].pos, mouseTargetPos, mouseDootT);
            bool mouseOver = mouseOverWindow == this;

            mouseDootT = Mathf.Lerp(mouseDootT, mouseOver ? 1f : 0f, 0.05f);


            Draw.Push();             // save state
            Draw.ResetAllDrawStates();

            // draw setup
            Draw.Matrix         = Matrix4x4.TRS(new Vector3(center.x, center.y, 1f), Quaternion.identity, Vector3.one);
            Draw.BlendMode      = ShapesBlendMode.Transparent;
            Draw.RadiusSpace    = ThicknessSpace.Meters;
            Draw.ThicknessSpace = ThicknessSpace.Meters;
            Draw.LineGeometry   = LineGeometry.Flat2D;
            Draw.LineEndCaps    = LineEndCap.Round;

            // Drawing
            Draw.Ring(Vector3.zero, fitRadius, fitRadius * 0.1f, DiscColors.Radial(Color.black, new Color(0, 0, 0, 0)));
            Draw.Disc(Vector3.zero, fitRadius, Color.black);

            // edge noodles
            const int noodCount = 64;

            for (int i = 0; i < noodCount; i++)
            {
                float   tDir = i / ((float)noodCount);
                float   tAng = ShapesMath.TAU * tDir;
                Vector2 dir  = ShapesMath.AngToDir(tAng);
                if (Mathf.Abs(dir.y) > 0.75f)
                {
                    continue;
                }
                Vector2 root          = dir * fitRadius;
                float   distToNearest = float.MaxValue;
                for (int j = 0; j < doots.Length; j++)
                {
                    distToNearest = Mathf.Min(distToNearest, Vector2.Distance(doots[j].pos, root));
                }
                float distMod       = Mathf.InverseLerp(fitRadius * 0.5f, fitRadius * 0.1f, distToNearest);
                float noodMaxOffset = fitRadius * (1 + 0.1f * distMod);
                Draw.Line(root, dir * noodMaxOffset, fitRadius * Mathf.Lerp(0.07f, 0.04f, distMod));
            }

            // ring
            Draw.Ring(Vector3.zero, fitRadius, fitRadius * 0.0125f, colMain);

            // connecting lines
            for (int i = 0; i < doots.Length; i++)
            {
                Vector2 a = doots[i].pos;
                for (int j = i; j < doots.Length; j++)
                {
                    Vector2 b          = doots[j].pos;
                    float   dist       = Vector2.Distance(a, b);
                    float   rangeValue = Mathf.InverseLerp(fitRadius * 1f, fitRadius * 0.02f, dist);
                    if (rangeValue > 0)
                    {
                        Color col = Color.Lerp(colFade, colMain, rangeValue);
                        Draw.Line(a, b, fitRadius * 0.015f * rangeValue, LineEndCap.Round, col);
                    }
                }
            }

            // doots~
            foreach (Doot doot in doots)
            {
                Draw.BlendMode = ShapesBlendMode.Transparent;
                Draw.Disc(doot.pos, fitRadius * 0.025f, Color.black);
                Draw.Disc(doot.pos, fitRadius * 0.015f, colMain);
                Draw.BlendMode = ShapesBlendMode.Additive;
                Color innerColor = colMain;
                innerColor.a = 0.25f;
                Color outerColor = Color.clear;
                Draw.Disc(doot.pos, fitRadius * 0.18f, DiscColors.Radial(innerColor, outerColor));
            }

            Draw.BlendMode = ShapesBlendMode.Multiplicative;
            Draw.Disc(Vector3.zero, fitRadius * 0.5f, DiscColors.Radial(Color.black, Color.clear));

            Draw.Pop();             // restore state
        }
예제 #4
0
        static void DiscCore(bool hollow, bool sector, float radius, float thickness, DiscColors colors, float angleRadStart = 0f, float angleRadEnd = 0f, ArcEndCap arcEndCaps = ArcEndCap.None)
        {
            if (sector && Mathf.Abs(angleRadEnd - angleRadStart) < 0.0001f)
            {
                return;
            }

            using (new IMDrawer(mpbDisc, ShapesMaterialUtils.GetDiscMaterial(hollow, sector)[Draw.BlendMode], ShapesMeshUtils.QuadMesh[0])) {
                MetaMpb.ApplyDashSettings(mpbDisc, thickness);
                mpbDisc.radius.Add(radius);
                mpbDisc.radiusSpace.Add((int)Draw.RadiusSpace);
                mpbDisc.alignment.Add((int)Draw.DiscGeometry);
                mpbDisc.thicknessSpace.Add((int)Draw.ThicknessSpace);
                mpbDisc.thickness.Add(thickness);
                mpbDisc.scaleMode.Add((int)ScaleMode);
                mpbDisc.angleStart.Add(angleRadStart);
                mpbDisc.angleEnd.Add(angleRadEnd);
                mpbDisc.roundCaps.Add((int)arcEndCaps);
                mpbDisc.color.Add(colors.innerStart.ColorSpaceAdjusted());
                mpbDisc.colorOuterStart.Add(colors.outerStart.ColorSpaceAdjusted());
                mpbDisc.colorInnerEnd.Add(colors.innerEnd.ColorSpaceAdjusted());
                mpbDisc.colorOuterEnd.Add(colors.outerEnd.ColorSpaceAdjusted());
            }
        }
예제 #5
0
 static void Ring_Internal([OvldDefault(nameof(Radius))] float radius,
                           [OvldDefault(nameof(Thickness))] float thickness,
                           [OvldDefault(nameof(Color))] DiscColors colors)
 {
     DiscCore(true, false, radius, thickness, colors);
 }
예제 #6
0
 static void Disc_Internal([OvldDefault(nameof(Radius))] float radius,
                           [OvldDefault(nameof(Color))] DiscColors colors)
 {
     DiscCore(false, false, radius, 0f, colors);
 }
예제 #7
0
        public void DrawBar(FpsController fpsController, float barRadius)
        {
            // get some data
            float barThickness            = fpsController.ammoBarThickness;
            float ammoBarOutlineThickness = fpsController.ammoBarOutlineThickness;
            float angRadMin     = -fpsController.ammoBarAngularSpanRad / 2;
            float angRadMax     = fpsController.ammoBarAngularSpanRad / 2;
            float angRadMinLeft = angRadMin + ShapesMath.TAU / 2;
            float angRadMaxLeft = angRadMax + ShapesMath.TAU / 2;
            float outerRadius   = barRadius + barThickness / 2;

            float chargeAnim = chargeFillCurve.Evaluate(charge);

            // charge bar shake:
            float   chargeMag    = animChargeShakeMagnitude.Evaluate(chargeAnim) * chargeShakeMagnitude;
            Vector2 origin       = fpsController.GetShake(chargeShakeSpeed, chargeMag);         // do shake here
            float   chargeAngRad = Mathf.Lerp(angRadMaxLeft, angRadMinLeft, chargeAnim);
            Color   chargeColor  = chargeFillGradient.Evaluate(chargeAnim);

            Draw.Arc(origin, fpsController.ammoBarRadius, barThickness, angRadMaxLeft, chargeAngRad, chargeColor);

            Vector2 movingLeftPos = origin + ShapesMath.AngToDir(chargeAngRad) * barRadius;
            Vector2 bottomLeftPos = origin + ShapesMath.AngToDir(angRadMaxLeft) * barRadius;

            // bottom fill
            Draw.Disc(bottomLeftPos, barThickness / 2f, chargeColor);

            // ticks
            const int tickCount = 7;

            Draw.LineEndCaps = LineEndCap.None;
            for (int i = 0; i < tickCount; i++)
            {
                float   t      = i / (tickCount - 1f);
                float   angRad = Mathf.Lerp(angRadMaxLeft, angRadMinLeft, t);
                Vector2 dir    = ShapesMath.AngToDir(angRad);
                Vector2 a      = origin + dir * outerRadius;
                bool    lorge  = i % 3 == 0;
                Vector2 b      = a + dir * (lorge ? tickSizeLorge : tickSizeSmol);
                Draw.Line(a, b, tickTickness, tickColor);

                // scale based on distance to real value
                float chargeDelta = t - chargeAnim;
                float growRange   = chargeDelta < 0 ? fontGrowRangePrev : fontGrowRangeNext;
                float tFontScale  = 1f - ShapesMath.SmoothCos01(Mathf.Clamp01(Mathf.Abs(chargeDelta) / growRange));
                float fontScale   = ShapesMath.Eerp(fontSize, fontSizeLorge, tFontScale);
                Draw.FontSize = fontScale;
                Vector2 labelPos = a + dir * percentLabelOffset;
                string  pct      = Mathf.RoundToInt(t * 100) + "%";
                Draw.Text(labelPos, angRad + ShapesMath.TAU / 2, pct, TextAlign.Right);
            }

            // moving dot
            Draw.Disc(movingLeftPos, barThickness / 2f + ammoBarOutlineThickness / 2f);
            Draw.Disc(movingLeftPos, barThickness / 2f - ammoBarOutlineThickness / 2f, chargeColor);

            FpsController.DrawRoundedArcOutline(origin, barRadius, barThickness, ammoBarOutlineThickness, angRadMinLeft, angRadMaxLeft);

            Draw.LineEndCaps = LineEndCap.Round;

            // glow
            Draw.BlendMode = ShapesBlendMode.Additive;
            Draw.Disc(movingLeftPos, barThickness * 2, DiscColors.Radial(chargeColor, Color.clear));
            Draw.BlendMode = ShapesBlendMode.Transparent;
        }