From b47d51c3ff10708ca4326d46092c0a48f95dc8eb Mon Sep 17 00:00:00 2001 From: Chatchai Saratakij Date: Thu, 30 May 2019 21:20:31 +0700 Subject: [PATCH] Add : option to set all section gameobject's tag to 'EditorOnly' (Not include these object to a build) --- Assets/Editor/HierachySection.cs | 17 +++++++++++++++-- Assets/Editor/HierachySectionSetting.asset | 1 + Assets/Editor/HierachySectionSetting.cs | 6 ++++++ Assets/Scenes/SampleScene.unity | 8 ++++---- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Assets/Editor/HierachySection.cs b/Assets/Editor/HierachySection.cs index e1702fe..9be42e9 100644 --- a/Assets/Editor/HierachySection.cs +++ b/Assets/Editor/HierachySection.cs @@ -11,6 +11,7 @@ namespace HierachySection.Editor public static class HierachySection { const char PREFIX_SYMBOL = '-'; + const string PREFIX = "---"; const string DEFAULT_LABEL = "Section"; const string DEFAULT_FULL_LABEL = "--- Section ---"; @@ -20,6 +21,7 @@ public static class HierachySection static int currentSectionIndex; static int currentPinSectionInstanceID; + static bool autoSetEditorOnlyTag = false; static bool isBeginRename = false; static bool isPinSection = false; @@ -55,6 +57,7 @@ static void SubscribeEvents() static void RefreshSectionInstanceID(Scene scene) { + LoadSettings(); sectionInstanceID.Clear(); currentSectionIndex = 0; @@ -69,16 +72,21 @@ static void RefreshSectionInstanceID(Scene scene) { if (obj.name.Contains(PREFIX)) { + if (autoSetEditorOnlyTag) + { + Undo.RecordObject(obj, "Set section tag to \"EditorOnly\""); + obj.tag = "EditorOnly"; + } + sectionInstanceID.Add(obj.GetInstanceID()); } } - - LoadSettings(); } static void LoadSettings() { var settings = HierachySectionSetting.GetOrCreateSettings(); + autoSetEditorOnlyTag = settings.AutoSetEditorOnlyTag; foregroundColor = settings.ForegroundColor; backgroundColor = settings.BackgroundColor; hilightForegroundColor = settings.HilightForegroundColor; @@ -284,6 +292,11 @@ public static void CreateSection() { GameObject obj = new GameObject(DEFAULT_FULL_LABEL); + if (autoSetEditorOnlyTag) + { + obj.tag = "EditorOnly"; + } + obj.transform.position = Vector3.zero; obj.SetActive(false); diff --git a/Assets/Editor/HierachySectionSetting.asset b/Assets/Editor/HierachySectionSetting.asset index 90d897c..219a9ff 100644 --- a/Assets/Editor/HierachySectionSetting.asset +++ b/Assets/Editor/HierachySectionSetting.asset @@ -12,6 +12,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: f10873006967c40348cc6e0e58210a2d, type: 3} m_Name: HierachySectionSetting m_EditorClassIdentifier: + autoSetEditorOnlyTag: 1 foregroundColor: {r: 1, g: 1, b: 1, a: 1} backgroundColor: {r: 0, g: 0, b: 0, a: 1} hilightForegroundColor: {r: 1, g: 1, b: 1, a: 1} diff --git a/Assets/Editor/HierachySectionSetting.cs b/Assets/Editor/HierachySectionSetting.cs index 4b723ce..12624b1 100644 --- a/Assets/Editor/HierachySectionSetting.cs +++ b/Assets/Editor/HierachySectionSetting.cs @@ -22,6 +22,9 @@ class HierachySectionSetting : ScriptableObject public static readonly Color DEFAULT_HIGHTLIGHT_BACKGROUND_COLOR = Color.yellow; + [SerializeField] + bool autoSetEditorOnlyTag; + [SerializeField] Color foregroundColor; @@ -34,6 +37,7 @@ class HierachySectionSetting : ScriptableObject [SerializeField] Color hilightBackgroundColor; + public bool AutoSetEditorOnlyTag => autoSetEditorOnlyTag; public Color ForegroundColor => foregroundColor; public Color BackgroundColor => backgroundColor; public Color HilightForegroundColor => hilightForegroundColor; @@ -61,6 +65,7 @@ internal static HierachySectionSetting CreateDefaultSettings() { var settings = ScriptableObject.CreateInstance(); + settings.autoSetEditorOnlyTag = true; settings.foregroundColor = DEFAULT_FOREGROUND_COLOR; settings.backgroundColor = DEFAULT_BACKGROUND_COLOR; settings.hilightForegroundColor = DEFAULT_HIGHTLIGHT_FOREGROUND_COLOR; @@ -100,6 +105,7 @@ public static SettingsProvider CreateMyCustomSettingsProvider() return; } + EditorGUILayout.PropertyField(settings.FindProperty("autoSetEditorOnlyTag"), new GUIContent("Auto set \" EditorOnly \" tag")); EditorGUILayout.PropertyField(settings.FindProperty("foregroundColor"), new GUIContent("Foreground")); EditorGUILayout.PropertyField(settings.FindProperty("backgroundColor"), new GUIContent("Background")); EditorGUILayout.PropertyField(settings.FindProperty("hilightForegroundColor"), new GUIContent("Hilight Foreground")); diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index e7f7412..bd3918c 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -350,7 +350,7 @@ GameObject: - component: {fileID: 606555404} m_Layer: 0 m_Name: '--- General ---' - m_TagString: Untagged + m_TagString: EditorOnly m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 @@ -506,7 +506,7 @@ GameObject: - component: {fileID: 1067747737} m_Layer: 0 m_Name: '--- Player ---' - m_TagString: Untagged + m_TagString: EditorOnly m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 @@ -739,7 +739,7 @@ GameObject: - component: {fileID: 1789440060} m_Layer: 0 m_Name: '--- UI ---' - m_TagString: Untagged + m_TagString: EditorOnly m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 @@ -769,7 +769,7 @@ GameObject: - component: {fileID: 2103336658} m_Layer: 0 m_Name: '--- Section ---' - m_TagString: Untagged + m_TagString: EditorOnly m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0