// 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); } }
// called by the ImmediateModeShapeDrawer base type public override void DrawShapes(Camera cam) { if (cam != this.cam) // only draw in the player camera { return; } using (Draw.Command(cam)) { Draw.ZTest = CompareFunction.Always; // to make sure it draws on top of everything like a HUD Draw.Matrix = crosshairTransform.localToWorldMatrix; // draw it in the space of crosshairTransform Draw.BlendMode = ShapesBlendMode.Transparent; Draw.LineGeometry = LineGeometry.Flat2D; crosshair.DrawCrosshair(); float radiusPunched = ammoBarRadius + fireSidebarRadiusPunchAmount * crosshair.fireDecayer.value; ammoBar.DrawBar(this, radiusPunched); chargeBar.DrawBar(this, radiusPunched); compass.DrawCompass(head.transform.forward); } }