@@ -37,163 +37,164 @@ public class LineRendererBase : MonoBehaviour
3737
3838 #region Events
3939
40- // Internally invoked by `LineRendererCamera.OnPostRender` (if any).
41- public virtual void OnLineRendererCameraPostRender ( )
42- {
43- // Subclass template.
44- }
40+ // Internally invoked by `LineRendererCamera.OnPostRender` (if any).
41+ public virtual void OnLineRendererCameraPostRender ( )
42+ {
43+ // Subclass template.
44+ }
4545
4646 #endregion
4747
4848
4949 #region Batch lines
5050
51- protected virtual void DrawLine ( Vector3 from , Vector3 to , Color color , float width = 1f )
52- {
53- // Subclass template.
54- }
51+ protected virtual void DrawLine ( Vector3 from , Vector3 to , Color color )
52+ {
53+ // Subclass template.
54+ }
55+
5556 #endregion
5657
5758
5859 #region Drawing methods
5960
60- protected void DrawPoints ( Vector2 [ ] points , Color color , bool closed = true )
61- { DrawPointsWithTransform ( points , color , null , closed ) ; }
61+ protected void DrawPoints ( Vector2 [ ] points , Color color , bool closed = true )
62+ { DrawPointsWithTransform ( points , color , null , closed ) ; }
6263
63- protected void DrawPointsWithTransform ( Vector2 [ ] points , Color color , Transform transform_ , bool closed = true )
64- {
65- int lastIndex = ( closed ) ? points . Length : points . Length - 1 ;
66- for ( int index = 0 ; index < lastIndex ; index ++ )
64+ protected void DrawPointsWithTransform ( Vector2 [ ] points , Color color , Transform transform_ , bool closed = true )
6765 {
68- Vector2 eachPoint = points [ index ] ;
69- Vector2 eachNextPoint = ( index < points . Length - 1 ) ? points [ index + 1 ] : points [ 0 ] ;
66+ int lastIndex = ( closed ) ? points . Length : points . Length - 1 ;
67+ for ( int index = 0 ; index < lastIndex ; index ++ )
68+ {
69+ Vector2 eachPoint = points [ index ] ;
70+ Vector2 eachNextPoint = ( index < points . Length - 1 ) ? points [ index + 1 ] : points [ 0 ] ;
71+
72+ // Apply shape transform (if any).
73+ if ( transform_ != null )
74+ {
75+ eachPoint = transform_ . TransformPoint ( eachPoint ) ;
76+ eachNextPoint = transform_ . TransformPoint ( eachNextPoint ) ;
77+ }
78+
79+ // Draw.
80+ DrawLine ( eachPoint , eachNextPoint , color ) ;
81+ }
82+ }
83+
84+ protected void DrawRect ( Rect rect , Color color )
85+ { DrawRectWithTransform ( rect , color , null ) ; }
86+
87+ protected void DrawRectWithTransform ( Rect rect , Color color , Transform transform_ )
88+ {
89+ Vector2 leftTop = new Vector2 ( rect . xMin , rect . yMin ) ;
90+ Vector2 rightTop = new Vector2 ( rect . xMax , rect . yMin ) ;
91+ Vector2 rightBottom = new Vector2 ( rect . xMax , rect . yMax ) ;
92+ Vector2 leftBottom = new Vector2 ( rect . xMin , rect . yMax ) ;
7093
71- // Apply shape transform (if any).
7294 if ( transform_ != null )
7395 {
74- eachPoint = transform_ . TransformPoint ( eachPoint ) ;
75- eachNextPoint = transform_ . TransformPoint ( eachNextPoint ) ;
96+ leftTop = transform_ . TransformPoint ( leftTop ) ;
97+ rightTop = transform_ . TransformPoint ( rightTop ) ;
98+ rightBottom = transform_ . TransformPoint ( rightBottom ) ;
99+ leftBottom = transform_ . TransformPoint ( leftBottom ) ;
76100 }
77101
78- // Draw.
79- DrawLine ( eachPoint , eachNextPoint , color ) ;
80- }
81- }
102+ DrawLine (
103+ leftTop ,
104+ rightTop ,
105+ color ) ;
82106
83- protected void DrawRect ( Rect rect , Color color )
84- { DrawRectWithTransform ( rect , color , null ) ; }
107+ DrawLine (
108+ rightTop ,
109+ rightBottom ,
110+ color ) ;
85111
86- protected void DrawRectWithTransform ( Rect rect , Color color , Transform transform_ )
87- {
88- Vector2 leftTop = new Vector2 ( rect . xMin , rect . yMin ) ;
89- Vector2 rightTop = new Vector2 ( rect . xMax , rect . yMin ) ;
90- Vector2 rightBottom = new Vector2 ( rect . xMax , rect . yMax ) ;
91- Vector2 leftBottom = new Vector2 ( rect . xMin , rect . yMax ) ;
112+ DrawLine (
113+ rightBottom ,
114+ leftBottom ,
115+ color ) ;
92116
93- if ( transform_ != null )
94- {
95- leftTop = transform_ . TransformPoint ( leftTop ) ;
96- rightTop = transform_ . TransformPoint ( rightTop ) ;
97- rightBottom = transform_ . TransformPoint ( rightBottom ) ;
98- leftBottom = transform_ . TransformPoint ( leftBottom ) ;
117+ DrawLine (
118+ leftTop ,
119+ leftBottom ,
120+ color ) ;
99121 }
100122
101- DrawLine (
102- leftTop ,
103- rightTop ,
104- color ) ;
105-
106- DrawLine (
107- rightTop ,
108- rightBottom ,
109- color ) ;
110-
111- DrawLine (
112- rightBottom ,
113- leftBottom ,
114- color ) ;
115-
116- DrawLine (
117- leftTop ,
118- leftBottom ,
119- color ) ;
120- }
121-
122- protected void DrawCircle ( Vector2 center , float radius , int segments , Color color )
123- { DrawCircleWithTransform ( center , radius , segments , color , null ) ; }
124-
125- protected void DrawCircleWithTransform ( Vector2 center , float radius , int segments , Color color , Transform transform_ )
126- {
127- Vector2 [ ] vertices = new Vector2 [ segments ] ;
128-
129- // Compose a half circle (and mirrored) in normalized space (at 0,0).
130- float angularStep = Mathf . PI * 2.0f / ( float ) segments ;
131- for ( int index = 0 ; index < 1 + segments / 2 ; index ++ )
123+ protected void DrawCircle ( Vector2 center , float radius , int segments , Color color )
124+ { DrawCircleWithTransform ( center , radius , segments , color , null ) ; }
125+
126+ protected void DrawCircleWithTransform ( Vector2 center , float radius , int segments , Color color , Transform transform_ )
132127 {
133- // Trigonometry.
134- float angle = ( float ) index * angularStep ;
135- float x = Mathf . Sin ( angle ) ;
136- float y = Mathf . Cos ( angle ) ;
128+ Vector2 [ ] vertices = new Vector2 [ segments ] ;
137129
138- Vector2 vertex = new Vector2 ( x * radius , y * radius ) ;
139- Vector2 mirrored = new Vector2 ( - x * radius , y * radius ) ;
130+ // Compose a half circle (and mirrored) in normalized space (at 0,0).
131+ float angularStep = Mathf . PI * 2.0f / ( float ) segments ;
132+ for ( int index = 0 ; index < 1 + segments / 2 ; index ++ )
133+ {
134+ // Trigonometry.
135+ float angle = ( float ) index * angularStep ;
136+ float x = Mathf . Sin ( angle ) ;
137+ float y = Mathf . Cos ( angle ) ;
140138
141- // Save right, then left.
142- vertices [ index ] = vertex ;
143- if ( index > 0 ) vertices [ segments - index ] = mirrored ;
144- }
139+ Vector2 vertex = new Vector2 ( x * radius , y * radius ) ;
140+ Vector2 mirrored = new Vector2 ( - x * radius , y * radius ) ;
145141
146- // Draw around center.
147- for ( int index = 0 ; index < segments - 1 ; index ++ )
148- {
142+ // Save right, then left.
143+ vertices [ index ] = vertex ;
144+ if ( index > 0 ) vertices [ segments - index ] = mirrored ;
145+ }
146+
147+ // Draw around center.
148+ for ( int index = 0 ; index < segments - 1 ; index ++ )
149+ {
150+ if ( transform_ != null )
151+ {
152+ DrawLineWithTransform (
153+ center + vertices [ index ] ,
154+ center + vertices [ index + 1 ] ,
155+ color ,
156+ transform
157+ ) ;
158+ }
159+ else
160+ {
161+ DrawLine (
162+ center + vertices [ index ] ,
163+ center + vertices [ index + 1 ] ,
164+ color
165+ ) ;
166+ }
167+ }
168+
169+ // Last segment.
149170 if ( transform_ != null )
150171 {
151172 DrawLineWithTransform (
152- center + vertices [ index ] ,
153- center + vertices [ index + 1 ] ,
173+ center + vertices [ segments - 1 ] ,
174+ center + vertices [ 0 ] ,
154175 color ,
155176 transform
156177 ) ;
157178 }
158179 else
159180 {
160181 DrawLine (
161- center + vertices [ index ] ,
162- center + vertices [ index + 1 ] ,
182+ center + vertices [ segments - 1 ] ,
183+ center + vertices [ 0 ] ,
163184 color
164185 ) ;
165186 }
166187 }
167188
168- // Last segment.
169- if ( transform_ != null )
189+ protected void DrawLineWithTransform ( Vector2 from , Vector2 to , Color color , Transform transform_ )
170190 {
171- DrawLineWithTransform (
172- center + vertices [ segments - 1 ] ,
173- center + vertices [ 0 ] ,
174- color ,
175- transform
176- ) ;
191+ Vector2 from_ = transform_ . TransformPoint ( from ) ;
192+ Vector2 to_ = transform_ . TransformPoint ( to ) ;
193+ DrawLine ( from_ , to_ , color ) ;
177194 }
178- else
179- {
180- DrawLine (
181- center + vertices [ segments - 1 ] ,
182- center + vertices [ 0 ] ,
183- color
184- ) ;
185- }
186- }
187-
188- protected void DrawLineWithTransform ( Vector2 from , Vector2 to , Color color , Transform transform_ )
189- {
190- Vector2 from_ = transform_ . TransformPoint ( from ) ;
191- Vector2 to_ = transform_ . TransformPoint ( to ) ;
192- DrawLine ( from_ , to_ , color ) ;
193- }
194195
195196 #endregion
196197
197198
198199 }
199- }
200+ }
0 commit comments