Skip to content

Commit 21ef415

Browse files
committed
Changed the timing for regenerating instances.
- Changed to ensure that instances are not regenerated even when component values are changed at runtime. - Changed to regenerate the instance when position or rotation changes.
1 parent 9eaed3b commit 21ef415

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

InstantiateComponents/Assets/InstantiateComponents/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
### Modified
55
- Modified the name of the parent object of the instance.
66
- Modified the inspector display.
7+
### Changed
8+
- Changed to ensure that instances are not regenerated even when component values are changed at runtime.
9+
- Changed to regenerate the instance when position or rotation changes.
710

811
## [1.0.0] - 2024-12-26
912
### Added

InstantiateComponents/Assets/InstantiateComponents/Scripts/Runtime/ShapeInstantiate.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ public class Vector3Range
5454
public int RandomSeed = 0;
5555

5656
public int CountLimit { get; set; } = 10000;
57+
58+
private Vector3 _lastPosition;
59+
private Quaternion _lastRotation;
60+
5761
private bool _isDirty;
5862

5963
private struct Location
@@ -69,6 +73,8 @@ private void OnEnable()
6973
{
7074
RandomSeed = GetInstanceID();
7175
}
76+
_lastPosition = transform.position;
77+
_lastRotation = transform.rotation;
7278
SetDirty();
7379
}
7480

@@ -79,7 +85,10 @@ private void OnDisable()
7985

8086
private void OnValidate()
8187
{
82-
SetDirty();
88+
if (!Application.isPlaying)
89+
{
90+
SetDirty();
91+
}
8392
}
8493

8594
public void SetDirty()
@@ -89,6 +98,13 @@ public void SetDirty()
8998

9099
private void Update()
91100
{
101+
if (!Application.isPlaying && (_lastPosition != transform.position || _lastRotation != transform.rotation))
102+
{
103+
_lastPosition = transform.position;
104+
_lastRotation = transform.rotation;
105+
SetDirty();
106+
}
107+
92108
if (_isDirty && isActiveAndEnabled)
93109
{
94110
_isDirty = false;

0 commit comments

Comments
 (0)