Skip to content

Commit a7dd44a

Browse files
superkerokeroChuanXin-Unity
authored andcommitted
A simple fix for PrefabBrush to address the 'NullReferenceException' issue in 2018.3 (Unity-Technologies#72)
* A simple fix for PrefabBrush to address the 'NullReferenceException' issue in 2018.3 * Update PrefabBrush.cs Made changes mentioned by @bgladosd and @Prog-Maker for issues in erasing and missing active tilemap.
1 parent 55b2a8e commit a7dd44a

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

Assets/Tilemap/Brushes/Prefab Brush/Scripts/Editor/PrefabBrush.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,27 @@ namespace UnityEditor
77
{
88
[CreateAssetMenu(fileName = "Prefab brush", menuName = "Brushes/Prefab brush")]
99
[CustomGridBrush(false, true, false, "Prefab Brush")]
10-
public class PrefabBrush : GridBrushBase
10+
public class PrefabBrush : GridBrush
1111
{
1212
private const float k_PerlinOffset = 100000f;
1313
public GameObject[] m_Prefabs;
1414
public float m_PerlinScale = 0.5f;
1515
public int m_Z;
16+
private GameObject prev_brushTarget;
17+
private Vector3Int prev_position;
1618

1719
public override void Paint(GridLayout grid, GameObject brushTarget, Vector3Int position)
1820
{
21+
if (position == prev_position)
22+
{
23+
return;
24+
}
25+
prev_position = position;
26+
if (brushTarget) {
27+
prev_brushTarget = brushTarget;
28+
}
29+
brushTarget = prev_brushTarget;
30+
1931
// Do not allow editing palettes
2032
if (brushTarget.layer == 31)
2133
return;
@@ -34,6 +46,11 @@ public override void Paint(GridLayout grid, GameObject brushTarget, Vector3Int p
3446

3547
public override void Erase(GridLayout grid, GameObject brushTarget, Vector3Int position)
3648
{
49+
if (brushTarget)
50+
{
51+
prev_brushTarget = brushTarget;
52+
}
53+
brushTarget = prev_brushTarget;
3754
// Do not allow editing palettes
3855
if (brushTarget.layer == 31)
3956
return;
@@ -66,7 +83,7 @@ private static float GetPerlinValue(Vector3Int position, float scale, float offs
6683
}
6784

6885
[CustomEditor(typeof(PrefabBrush))]
69-
public class PrefabBrushEditor : GridBrushEditorBase
86+
public class PrefabBrushEditor : GridBrushEditor
7087
{
7188
private PrefabBrush prefabBrush { get { return target as PrefabBrush; } }
7289

@@ -75,6 +92,7 @@ public class PrefabBrushEditor : GridBrushEditorBase
7592

7693
protected void OnEnable()
7794
{
95+
base.OnEnable();
7896
m_SerializedObject = new SerializedObject(target);
7997
m_Prefabs = m_SerializedObject.FindProperty("m_Prefabs");
8098
}

0 commit comments

Comments
 (0)