From 8b8ef705970cb7167db9aed99d01a1f5ba9d2108 Mon Sep 17 00:00:00 2001 From: Denys Almaral Date: Fri, 11 Aug 2023 10:27:22 -0400 Subject: [PATCH] Re-Check components when start painting --- Code/Editor/PolyPaintWindow.cs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/Code/Editor/PolyPaintWindow.cs b/Code/Editor/PolyPaintWindow.cs index 854ce80..67cf276 100644 --- a/Code/Editor/PolyPaintWindow.cs +++ b/Code/Editor/PolyPaintWindow.cs @@ -148,12 +148,16 @@ public void OnDestroy() void StartPaintMode() { - PrepareObject(); - _paintingMode = true; - _lastPixelColor = _painter.GetTextureColor(_lastUVpick); - PaintEditor.SetPixelColor(_lastPixelColor); - SceneView.lastActiveSceneView.Repaint(); - PaintEditor.PaintMode = true; + CheckComponents(_targetObject); + if (_targetTexture != null) + { + PrepareObject(); + _paintingMode = true; + _lastPixelColor = _painter.GetTextureColor(_lastUVpick); + PaintEditor.SetPixelColor(_lastPixelColor); + SceneView.lastActiveSceneView.Repaint(); + PaintEditor.PaintMode = true; + } } void StopPaintMode() @@ -203,7 +207,7 @@ void OnGUI() //Big PAINT MODE button _scrollPos = EGL.BeginScrollView(_scrollPos); - using (new EditorGUI.DisabledScope(_targetMesh == null)) + using (new EditorGUI.DisabledScope(_targetTexture == null)) { if (!_paintingMode) { @@ -1231,7 +1235,6 @@ void OnSelectionChange() if (_paintingMode) return; _targetObject = Selection.activeGameObject; - _skinned = false; if (_targetObject != null) { CheckComponents(_targetObject); @@ -1247,6 +1250,7 @@ void OnSelectionChange() private void CheckComponents(GameObject target) { + _skinned = false; var solid = target.GetComponent(); var skinned = target.GetComponent(); if (solid != null) @@ -1266,17 +1270,14 @@ private void CheckComponents(GameObject target) var r = target.GetComponent(); if (r != null) { - _targetTexture = r.sharedMaterial.mainTexture; + _targetTexture = null; + _textureData = null; + var mat = r.sharedMaterial; + if (mat != null) _targetTexture = mat.mainTexture; if (_targetTexture != null) { _textureData = ToTexture2D(_targetTexture); } - else - { - _targetTexture = null; - _textureData = null; - } - } else {