Skip to content

Commit 7890f63

Browse files
committed
0.8.2
1 parent a490b26 commit 7890f63

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# eppz! `Geometry`
22

3+
* 0.8.2
4+
5+
+ `PolygonSource`
6+
+ Offset now can be manipulated at runtime
7+
+ Maintain the original polygon, so offset polygon can be recalculated any time
8+
39
* 0.8.0
410

511
+ Test scenes

Components/PolygonSource.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,21 @@ public class PolygonSource : MonoBehaviour
2020

2121

2222
public Transform[] pointTransforms;
23-
[Range (-2,2)] public float offset = 0.0f;
23+
public float offset = 0.0f;
2424

2525
public enum UpdateMode { Awake, Update, LateUpdate };
2626
public UpdateMode update = UpdateMode.Awake;
2727

28-
public Polygon polygon;
28+
Polygon _polygon;
29+
Polygon _offsetPolygon;
30+
public Polygon polygon { get { return (offset != 0.0f) ? _offsetPolygon : _polygon; } }
2931

3032

3133
void Awake()
3234
{
3335
// Construct a polygon model from transforms (if not created by a root polygon already).
34-
if (polygon == null) polygon = Polygon.PolygonWithSource(this);
35-
if (offset != 0.0f) polygon = polygon.OffsetPolygon(offset);
36+
if (_polygon == null) _polygon = Polygon.PolygonWithSource(this);
37+
if (offset != 0.0f) _offsetPolygon = _polygon.OffsetPolygon(offset);
3638
}
3739

3840
void Update()
@@ -50,8 +52,8 @@ void LateUpdate()
5052
void UpdateModel()
5153
{
5254
// Update polygon model with transforms, also update calculations.
53-
polygon.UpdatePointPositionsWithSource(this);
54-
if (offset != 0.0f) polygon = polygon.OffsetPolygon(offset);
55+
_polygon.UpdatePointPositionsWithSource(this);
56+
if (offset != 0.0f) _offsetPolygon = _polygon.OffsetPolygon(offset);
5557
}
5658
}
5759
}

Lines/PolygonLineRenderer.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,23 @@ public class PolygonLineRenderer : GeometryLineRenderer
2727
public bool normals = false;
2828

2929
public Polygon polygon;
30+
PolygonSource polygonSource;
3031

3132

3233
void Start()
3334
{
3435
// Model reference.
35-
PolygonSource polygonSource = GetComponent<PolygonSource>();
36+
polygonSource = GetComponent<PolygonSource>();
37+
3638
if (polygonSource != null)
3739
{ polygon = polygonSource.polygon; }
3840
}
3941

4042
protected override void OnDraw()
4143
{
44+
if (polygonSource != null)
45+
{ polygon = polygonSource.polygon; }
46+
4247
if (polygon == null) return; // Only having polygon
4348

4449
DrawRect(polygon.bounds, boundsColor);

Model/Polygon.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ public static Polygon PolygonWithSource(PolygonSource polygonSource)
8080
if (eachChildPolygonSource != null)
8181
{
8282
Polygon eachSubPolygon = Polygon.PolygonWithSource(eachChildPolygonSource);
83-
eachChildPolygonSource.polygon = eachSubPolygon; // Inject into source
8483
rootPolygon.AddPolygon(eachSubPolygon);
8584
}
8685
}

0 commit comments

Comments
 (0)