// This method is called by ImmediateModeShapeDrawer - equivalent to OnPreRender of all cameras (except preview windows and probe cameras) public override void DrawShapes( Camera cam ) { // Draw.Command enqueues a set of draw commands to render in the given camera using( Draw.Command( cam ) ) { // all immediate mode drawing should happen within these using-statements Draw.ResetAllDrawStates(); // this makes sure no static draw states "leak" over to this scene Draw.Matrix = transform.localToWorldMatrix; // this makes it draw in the local space of this transform for( int i = 0; i < discCount; i++ ) { float t = i / (float)discCount; Color color = Color.HSVToRGB( t, 1, 1 ); Vector2 pos = GetDiscPosition( t ); Draw.Disc( pos, discRadius, color ); // This is the actual Shapes draw command } } }
// This function is called by ImmediateModeShapeDrawer in the appropriate OnPreRender call of each camera public override void DrawShapes(Camera cam) { // Draw.Command enqueues a set of draw commands to render in the given camera using (Draw.Command(cam)) { // all immediate mode drawing should happen within these using-statements // Set up draw state Draw.ResetAllDrawStates(); // ensure everything is set to their defaults Draw.BlendMode = ShapesBlendMode.Additive; Draw.LineThickness = lineThickness; Draw.LineGeometry = use3D ? LineGeometry.Volumetric3D : LineGeometry.Flat2D; Draw.LineThicknessSpace = ThicknessSpace.Meters; Draw.Color = lineColor; Random.InitState(seed); // initialize random state, so we get the same values every frame currentLineCount = 0; // Draw a branch at the current location. this function is recursive, so all other branches will follow BranchFrom(Draw.Matrix); } }
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 }