Improved work in prefab view

pull/87/head
Mane Function 2019-05-13 17:35:42 +03:00
parent 7c89572540
commit f59a4a8560
3 changed files with 59 additions and 11 deletions

View File

@ -1,4 +1,3 @@
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
@ -34,7 +33,7 @@ namespace Coffee.UIExtensions.Editors
if (0 < fixTargets.Count) if (0 < fixTargets.Count)
{ {
GUILayout.BeginHorizontal (); GUILayout.BeginHorizontal ();
EditorGUILayout.HelpBox ("There are child Graphicss that does not have a SoftMaskable component.\nAdd SoftMaskable component to them.", MessageType.Warning); EditorGUILayout.HelpBox ("There are child Graphics that does not have a SoftMaskable component.\nAdd SoftMaskable component to them.", MessageType.Warning);
GUILayout.BeginVertical (); GUILayout.BeginVertical ();
if (GUILayout.Button ("Fix")) if (GUILayout.Button ("Fix"))
{ {
@ -42,6 +41,8 @@ namespace Coffee.UIExtensions.Editors
{ {
p.gameObject.AddComponent<SoftMaskable> (); p.gameObject.AddComponent<SoftMaskable> ();
} }
Utils.MarkPrefabDirty ();
} }
if (GUILayout.Button ("Ping")) if (GUILayout.Button ("Ping"))
{ {
@ -60,8 +61,8 @@ namespace Coffee.UIExtensions.Editors
if (s_Preview) if (s_Preview)
{ {
var tex = current.softMaskBuffer; var tex = current.softMaskBuffer;
var wtdth = tex.width * 64 / tex.height; var width = tex.width * 64 / tex.height;
EditorGUI.DrawPreviewTexture (GUILayoutUtility.GetRect (wtdth, 64), tex, null, ScaleMode.ScaleToFit); EditorGUI.DrawPreviewTexture (GUILayoutUtility.GetRect (width, 64), tex, null, ScaleMode.ScaleToFit);
Repaint (); Repaint ();
} }
GUILayout.FlexibleSpace (); GUILayout.FlexibleSpace ();

View File

@ -1,4 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using UnityEditor; using UnityEditor;
@ -71,7 +71,7 @@ namespace Coffee.UIExtensions.Editors
List<MaterialEditor> _materialEditors = new List<MaterialEditor> (); List<MaterialEditor> _materialEditors = new List<MaterialEditor> ();
SerializedProperty _spMaskInteraction; SerializedProperty _spMaskInteraction;
private void OnEnable () void OnEnable ()
{ {
_spMaskInteraction = serializedObject.FindProperty("m_MaskInteraction"); _spMaskInteraction = serializedObject.FindProperty("m_MaskInteraction");
_custom = (maskInteraction == MaskInteraction.Custom); _custom = (maskInteraction == MaskInteraction.Custom);
@ -98,8 +98,8 @@ namespace Coffee.UIExtensions.Editors
s_MaskWarning = new GUIContent(EditorGUIUtility.FindTexture("console.warnicon.sml"), "This component is not SoftMask. Use SoftMask instead of Mask."); s_MaskWarning = new GUIContent(EditorGUIUtility.FindTexture("console.warnicon.sml"), "This component is not SoftMask. Use SoftMask instead of Mask.");
} }
private void OnDisable () void OnDisable ()
{ {
ClearMaterialEditors (); ClearMaterialEditors ();
} }
@ -201,15 +201,14 @@ namespace Coffee.UIExtensions.Editors
// var current = target as SoftMaskable;
var current = target as SoftMaskable; var current = target as SoftMaskable;
current.GetComponentsInChildren<Graphic> (true, s_Graphics); current.GetComponentsInChildren<Graphic> (true, s_Graphics);
var fixTargets = s_Graphics.Where (x => x.gameObject != current.gameObject && !x.GetComponent<SoftMaskable> () && (!x.GetComponent<Mask> () || x.GetComponent<Mask> ().showMaskGraphic)).ToList (); var fixTargets = s_Graphics.Where (x => x.gameObject != current.gameObject && !x.GetComponent<SoftMaskable> () && (!x.GetComponent<Mask> () || x.GetComponent<Mask> ().showMaskGraphic)).ToList ();
if (0 < fixTargets.Count) if (0 < fixTargets.Count)
{ {
GUILayout.BeginHorizontal (); GUILayout.BeginHorizontal ();
EditorGUILayout.HelpBox ("There are child Graphicss that does not have a SoftMaskable component.\nAdd SoftMaskable component to them.", MessageType.Warning); EditorGUILayout.HelpBox ("There are child Graphics that does not have a SoftMaskable component.\nAdd SoftMaskable component to them.", MessageType.Warning);
GUILayout.BeginVertical (); GUILayout.BeginVertical ();
if (GUILayout.Button ("Fix")) if (GUILayout.Button ("Fix"))
{ {
@ -236,6 +235,34 @@ namespace Coffee.UIExtensions.Editors
ShowMaterialEditors (fontSharedMaterials, 1, fontSharedMaterials.Length - 1); ShowMaterialEditors (fontSharedMaterials, 1, fontSharedMaterials.Length - 1);
} }
} }
if (!DetectMask (current.transform.parent))
{
GUILayout.BeginHorizontal ();
EditorGUILayout.HelpBox ("This is unnecessary SoftMaskable.\nCan't find any SoftMask components above.", MessageType.Warning);
if (GUILayout.Button ("Remove", GUILayout.Height (40)))
{
DestroyImmediate (current);
Utils.MarkPrefabDirty ();
}
GUILayout.EndHorizontal ();
}
}
static bool DetectMask (Transform transform)
{
if (transform == null)
{
return false;
}
if (transform.GetComponent<SoftMask> () != null)
{
return true;
}
return DetectMask (transform.parent);
} }
void ClearMaterialEditors () void ClearMaterialEditors ()

20
Scripts/Editor/Utils.cs Normal file
View File

@ -0,0 +1,20 @@
using UnityEditor.Experimental.SceneManagement;
using UnityEditor.SceneManagement;
namespace Coffee.UIExtensions.Editors
{
public static class Utils
{
public static void MarkPrefabDirty ()
{
#if UNITY_2018_3_OR_NEWER
var prefabStage = PrefabStageUtility.GetCurrentPrefabStage ();
if (prefabStage != null)
{
EditorSceneManager.MarkSceneDirty (prefabStage.scene);
}
#endif
}
}
}