Skip to content

Commit

Permalink
fix: stop running OnValidate on immutable prefabs (#810)
Browse files Browse the repository at this point in the history
  • Loading branch information
homuler committed Dec 17, 2022
1 parent a4c7077 commit f545346
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ private void Start()
ApplyMagnitude(_magnitude); // magnitude must be set after _capScale
}

#if UNITY_EDITOR
private void OnValidate()
{
ApplyDirection(_direction);
ApplyCapScale(_capScale);
ApplyLineWidth(_lineWidth);
ApplyMagnitude(_magnitude); // magnitude must be set after _capScale
if (!UnityEditor.PrefabUtility.IsPartOfAnyPrefab(this))
{
ApplyDirection(_direction);
ApplyCapScale(_capScale);
ApplyLineWidth(_lineWidth);
ApplyMagnitude(_magnitude); // magnitude must be set after _capScale
}
}
#endif

private Transform _cone;
private Transform cone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@ private void OnDisable()
_lineRenderer.SetPositions(new Vector3[] { });
}

#if UNITY_EDITOR
private void OnValidate()
{
ApplyColor(_color);
ApplyLineWidth(_lineWidth);
if (!UnityEditor.PrefabUtility.IsPartOfAnyPrefab(this))
{
ApplyColor(_color);
ApplyLineWidth(_lineWidth);
}
}
#endif

public void SetColor(Color color)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ public sealed class ConnectionListAnnotation : ListAnnotation<ConnectionAnnotati
[SerializeField] private Color _color = Color.red;
[SerializeField, Range(0, 1)] private float _lineWidth = 1.0f;

#if UNITY_EDITOR
private void OnValidate()
{
ApplyColor(_color);
ApplyLineWidth(_lineWidth);
if (!UnityEditor.PrefabUtility.IsPartOfAnyPrefab(this))
{
ApplyColor(_color);
ApplyLineWidth(_lineWidth);
}
}
#endif

public void Fill(IList<(int, int)> connections, PointListAnnotation points)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@ public class CuboidListAnnotation : ListAnnotation<CuboidAnnotation>
[SerializeField] private float _arrowLengthScale = 1.0f;
[SerializeField, Range(0, 1)] private float _arrowWidth = 1.0f;

#if UNITY_EDITOR
private void OnValidate()
{
ApplyPointColor(_pointColor);
ApplyLineColor(_lineColor);
ApplyLineWidth(_lineWidth);
ApplyArrowCapScale(_arrowCapScale);
ApplyArrowLengthScale(_arrowLengthScale);
ApplyArrowWidth(_arrowWidth);
if (!UnityEditor.PrefabUtility.IsPartOfAnyPrefab(this))
{
ApplyPointColor(_pointColor);
ApplyLineColor(_lineColor);
ApplyLineWidth(_lineWidth);
ApplyArrowCapScale(_arrowCapScale);
ApplyArrowLengthScale(_arrowLengthScale);
ApplyArrowWidth(_arrowWidth);
}
}
#endif

public void SetPointColor(Color pointColor)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@

namespace Mediapipe.Unity
{
#pragma warning disable IDE0065
using Color = UnityEngine.Color;
#pragma warning restore IDE0065

public sealed class DetectionListAnnotation : ListAnnotation<DetectionAnnotation>
{
[SerializeField, Range(0, 1)] private float _lineWidth = 1.0f;
[SerializeField] private float _keypointRadius = 15.0f;

#if UNITY_EDITOR
private void OnValidate()
{
ApplyLineWidth(_lineWidth);
ApplyKeypointRadius(_keypointRadius);
if (!UnityEditor.PrefabUtility.IsPartOfAnyPrefab(this))
{
ApplyLineWidth(_lineWidth);
ApplyKeypointRadius(_keypointRadius);
}
}
#endif

public void SetLineWidth(float lineWidth)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ private void OnDisable()
ApplyLineWidth(0.0f);
}

#if UNITY_EDITOR
private void OnValidate()
{
ApplyColor(_color);
ApplyLineWidth(_lineWidth);
if (!UnityEditor.PrefabUtility.IsPartOfAnyPrefab(this))
{
ApplyColor(_color);
ApplyLineWidth(_lineWidth);
}
}
#endif

public void SetColor(Color color)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@ private void OnDisable()
}
}

#if UNITY_EDITOR
private void OnValidate()
{
ApplyMaskTexture(_maskTexture, _color);
ApplyThreshold(_threshold);
if (!UnityEditor.PrefabUtility.IsPartOfAnyPrefab(this))
{
ApplyMaskTexture(_maskTexture, _color);
ApplyThreshold(_threshold);
}
}
#endif

private void OnDestroy()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,22 @@ public sealed class MultiFaceLandmarkListAnnotation : ListAnnotation<FaceLandmar
[SerializeField, Range(0, 1)] private float _faceConnectionWidth = 1.0f;
[SerializeField, Range(0, 1)] private float _irisCircleWidth = 1.0f;

#if UNITY_EDITOR
private void OnValidate()
{
ApplyFaceLandmarkColor(_faceLandmarkColor);
ApplyIrisLandmarkColor(_irisLandmarkColor);
ApplyFaceLandmarkRadius(_faceLandmarkRadius);
ApplyIrisLandmarkRadius(_irisLandmarkRadius);
ApplyFaceConnectionColor(_faceConnectionColor);
ApplyIrisCircleColor(_irisCircleColor);
ApplyFaceConnectionWidth(_faceConnectionWidth);
ApplyIrisCircleWidth(_irisCircleWidth);
if (!UnityEditor.PrefabUtility.IsPartOfAnyPrefab(this))
{
ApplyFaceLandmarkColor(_faceLandmarkColor);
ApplyIrisLandmarkColor(_irisLandmarkColor);
ApplyFaceLandmarkRadius(_faceLandmarkRadius);
ApplyIrisLandmarkRadius(_irisLandmarkRadius);
ApplyFaceConnectionColor(_faceConnectionColor);
ApplyIrisCircleColor(_irisCircleColor);
ApplyFaceConnectionWidth(_faceConnectionWidth);
ApplyIrisCircleWidth(_irisCircleWidth);
}
}
#endif

public void SetFaceLandmarkRadius(float radius)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@ public sealed class MultiHandLandmarkListAnnotation : ListAnnotation<HandLandmar
[SerializeField] private Color _connectionColor = Color.white;
[SerializeField, Range(0, 1)] private float _connectionWidth = 1.0f;

#if UNITY_EDITOR
private void OnValidate()
{
ApplyLeftLandmarkColor(_leftLandmarkColor);
ApplyRightLandmarkColor(_rightLandmarkColor);
ApplyLandmarkRadius(_landmarkRadius);
ApplyConnectionColor(_connectionColor);
ApplyConnectionWidth(_connectionWidth);
if (!UnityEditor.PrefabUtility.IsPartOfAnyPrefab(this))
{
ApplyLeftLandmarkColor(_leftLandmarkColor);
ApplyRightLandmarkColor(_rightLandmarkColor);
ApplyLandmarkRadius(_landmarkRadius);
ApplyConnectionColor(_connectionColor);
ApplyConnectionWidth(_connectionWidth);
}
}
#endif

public void SetLeftLandmarkColor(Color leftLandmarkColor)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ public class PointListAnnotation : ListAnnotation<PointAnnotation>
[SerializeField] private Color _color = Color.green;
[SerializeField] private float _radius = 15.0f;

#if UNITY_EDITOR
private void OnValidate()
{
ApplyColor(_color);
ApplyRadius(_radius);
if (!UnityEditor.PrefabUtility.IsPartOfAnyPrefab(this))
{
ApplyColor(_color);
ApplyRadius(_radius);
}
}
#endif

public void SetColor(Color color)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,16 @@ private void Start()
_connectionListAnnotation.Fill(_Connections, _landmarkListAnnotation);
}

#if UNITY_EDITOR
private void OnValidate()
{
ApplyLeftLandmarkColor(_leftLandmarkColor);
ApplyRightLandmarkColor(_rightLandmarkColor);
if (!UnityEditor.PrefabUtility.IsPartOfAnyPrefab(this))
{
ApplyLeftLandmarkColor(_leftLandmarkColor);
ApplyRightLandmarkColor(_rightLandmarkColor);
}
}
#endif

public void SetLeftLandmarkColor(Color leftLandmarkColor)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@ private void OnDisable()
_lineRenderer.SetPositions(_EmptyPositions);
}

#if UNITY_EDITOR
private void OnValidate()
{
ApplyColor(_color);
ApplyLineWidth(_lineWidth);
if (!UnityEditor.PrefabUtility.IsPartOfAnyPrefab(this))
{
ApplyColor(_color);
ApplyLineWidth(_lineWidth);
}
}
#endif

public void SetColor(Color color)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ public class RectangleListAnnotation : ListAnnotation<RectangleAnnotation>
[SerializeField] private Color _color = Color.red;
[SerializeField, Range(0, 1)] private float _lineWidth = 1.0f;

#if UNITY_EDITOR
private void OnValidate()
{
ApplyColor(_color);
ApplyLineWidth(_lineWidth);
if (!UnityEditor.PrefabUtility.IsPartOfAnyPrefab(this))
{
ApplyColor(_color);
ApplyLineWidth(_lineWidth);
}
}
#endif

public void SetColor(Color color)
{
Expand Down

0 comments on commit f545346

Please sign in to comment.