summaryrefslogtreecommitdiff
path: root/GameCode/SizeRectangleToMeshBounds.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2023-11-02 11:51:31 +0800
committerchai <215380520@qq.com>2023-11-02 11:51:31 +0800
commit7f493f682503f5186308de7b8f74b5b49233cfe4 (patch)
tree8a91e2056bc79788ee4735dce88b8d516ba12beb /GameCode/SizeRectangleToMeshBounds.cs
+init
Diffstat (limited to 'GameCode/SizeRectangleToMeshBounds.cs')
-rw-r--r--GameCode/SizeRectangleToMeshBounds.cs20
1 files changed, 20 insertions, 0 deletions
diff --git a/GameCode/SizeRectangleToMeshBounds.cs b/GameCode/SizeRectangleToMeshBounds.cs
new file mode 100644
index 0000000..8962f24
--- /dev/null
+++ b/GameCode/SizeRectangleToMeshBounds.cs
@@ -0,0 +1,20 @@
+using Shapes;
+using UnityEngine;
+
+[RequireComponent(typeof(Rectangle))]
+public class SizeRectangleToMeshBounds : MonoBehaviour
+{
+ public float xMargin = 1f;
+
+ public float yMargin = 1f;
+
+ public MeshFilter meshFilter;
+
+ [ContextMenu("RESIZE")]
+ private void OnEnable()
+ {
+ Rectangle component = GetComponent<Rectangle>();
+ component.Height = meshFilter.sharedMesh.bounds.size.y + 2f * yMargin;
+ component.Width = meshFilter.sharedMesh.bounds.size.x + 2f * xMargin;
+ }
+}