Skip to content

Commit

Permalink
Add : option to set all section gameobject's tag to 'EditorOnly' (Not
Browse files Browse the repository at this point in the history
include these object to a build)
  • Loading branch information
CSaratakij committed May 30, 2019
1 parent f9decea commit b47d51c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
17 changes: 15 additions & 2 deletions Assets/Editor/HierachySection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---";
Expand All @@ -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;

Expand Down Expand Up @@ -55,6 +57,7 @@ static void SubscribeEvents()

static void RefreshSectionInstanceID(Scene scene)
{
LoadSettings();
sectionInstanceID.Clear();

currentSectionIndex = 0;
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions Assets/Editor/HierachySectionSetting.asset
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
6 changes: 6 additions & 0 deletions Assets/Editor/HierachySectionSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class HierachySectionSetting : ScriptableObject
public static readonly Color DEFAULT_HIGHTLIGHT_BACKGROUND_COLOR = Color.yellow;


[SerializeField]
bool autoSetEditorOnlyTag;

[SerializeField]
Color foregroundColor;

Expand All @@ -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;
Expand Down Expand Up @@ -61,6 +65,7 @@ internal static HierachySectionSetting CreateDefaultSettings()
{
var settings = ScriptableObject.CreateInstance<HierachySectionSetting>();

settings.autoSetEditorOnlyTag = true;
settings.foregroundColor = DEFAULT_FOREGROUND_COLOR;
settings.backgroundColor = DEFAULT_BACKGROUND_COLOR;
settings.hilightForegroundColor = DEFAULT_HIGHTLIGHT_FOREGROUND_COLOR;
Expand Down Expand Up @@ -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"));
Expand Down
8 changes: 4 additions & 4 deletions Assets/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b47d51c

Please sign in to comment.