Skip to content

Commit

Permalink
✨ feat(static-profile): Layer override
Browse files Browse the repository at this point in the history
  • Loading branch information
esnya committed Jun 9, 2022
1 parent 6e59d4b commit 071baaf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
19 changes: 17 additions & 2 deletions Assets/EsnyaUnityTools/Scripts/StaticProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using UnityEditor.SceneManagement;
#endif


namespace EsnyaFactory
{
public class StaticProfile : MonoBehaviour
Expand All @@ -28,6 +27,11 @@ public enum ColliderModification
[Multiline] public string includePattern = ".*";
[Multiline] public string excludePattern = @"Text \(TMP\)";

[Header("Layer")]
public bool overrideLayer;
public int layer;


[Header("Static Flags")]
public bool overrideStaticFlags = false;
#if UNITY_EDITOR
Expand Down Expand Up @@ -80,6 +84,7 @@ public void Apply()
var origin = transform.parent;
foreach (var o in origin.GetComponentsInChildren<Transform>(true).Select(t => t.gameObject).Where(o => includeRegex.IsMatch(o.name) && !excludeRegex.IsMatch(o.name)))
{
if (overrideLayer) o.layer = layer;
if (overrideStaticFlags) GameObjectUtility.SetStaticEditorFlags(o, o == gameObject ? 0 : staticFlags);

if (overrideLightmapSettings)
Expand Down Expand Up @@ -161,7 +166,7 @@ public void Apply()
}

var terrains = transform.parent.GetComponentsInChildren<Terrain>(true).ToArray();
if (overrideLightmapSettings)
if (terrains.Length > 0 && overrideLightmapSettings)
{
var serializedObject = new SerializedObject(terrains);
serializedObject.FindProperty("m_ScaleInLightmap").floatValue = lightmapScaleOffset;
Expand Down Expand Up @@ -251,6 +256,12 @@ private static int EnumMaskToggleButtons<E>(int value) where E : System.Enum
return value;
}

private static void LayerPopup(SerializedProperty property)
{
var layerNames = Enumerable.Range(0, 32).Select(LayerMask.LayerToName).ToArray();
property.intValue = EditorGUILayout.Popup(property.displayName, property.intValue, layerNames);
}

private static bool IsHeader(SerializedProperty property)
{
var type = property.serializedObject.targetObject.GetType();
Expand Down Expand Up @@ -281,6 +292,10 @@ public override void OnInspectorGUI()
{
property.intValue = EnumMaskToggleButtons<StaticEditorFlags>(property.displayName, property.intValue);
}
else if (property.name == nameof(StaticProfile.layer))
{
LayerPopup(property);
}
else
{
EditorGUILayout.PropertyField(property, true);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.nekometer.esnya-unity-tools",
"version": "3.12.0-beta.2",
"version": "3.12.0-beta.4",
"displayName": "EsnyaUnityTools",
"unity": "2019.4",
"description": "",
Expand Down

0 comments on commit 071baaf

Please sign in to comment.