From 071baaf9d1a1ff3d9f8d47a2dd251236d2bf3d44 Mon Sep 17 00:00:00 2001 From: esnya Date: Sat, 9 Apr 2022 16:55:19 +0900 Subject: [PATCH] :sparkles: feat(static-profile): Layer override --- .../EsnyaUnityTools/Scripts/StaticProfile.cs | 19 +++++++++++++++++-- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Assets/EsnyaUnityTools/Scripts/StaticProfile.cs b/Assets/EsnyaUnityTools/Scripts/StaticProfile.cs index b026ae5..53dc72c 100644 --- a/Assets/EsnyaUnityTools/Scripts/StaticProfile.cs +++ b/Assets/EsnyaUnityTools/Scripts/StaticProfile.cs @@ -9,7 +9,6 @@ using UnityEditor.SceneManagement; #endif - namespace EsnyaFactory { public class StaticProfile : MonoBehaviour @@ -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 @@ -80,6 +84,7 @@ public void Apply() var origin = transform.parent; foreach (var o in origin.GetComponentsInChildren(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) @@ -161,7 +166,7 @@ public void Apply() } var terrains = transform.parent.GetComponentsInChildren(true).ToArray(); - if (overrideLightmapSettings) + if (terrains.Length > 0 && overrideLightmapSettings) { var serializedObject = new SerializedObject(terrains); serializedObject.FindProperty("m_ScaleInLightmap").floatValue = lightmapScaleOffset; @@ -251,6 +256,12 @@ private static int EnumMaskToggleButtons(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(); @@ -281,6 +292,10 @@ public override void OnInspectorGUI() { property.intValue = EnumMaskToggleButtons(property.displayName, property.intValue); } + else if (property.name == nameof(StaticProfile.layer)) + { + LayerPopup(property); + } else { EditorGUILayout.PropertyField(property, true); diff --git a/package-lock.json b/package-lock.json index 41c52e5..37b2cc8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "com.nekometer.esnya-unity-tools", - "version": "3.12.0-beta.2", + "version": "3.12.0-beta.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "com.nekometer.esnya-unity-tools", - "version": "3.12.0-beta.2", + "version": "3.12.0-beta.4", "license": "MIT", "dependencies": { "@semantic-release/exec": "^6.0.3", diff --git a/package.json b/package.json index cc7d80f..9ea7cee 100644 --- a/package.json +++ b/package.json @@ -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": "",