Add: hierarchy toggles

This commit is contained in:
AnnulusGames 2024-02-16 20:17:26 +09:00
parent e6167d419d
commit 9d87b79807
6 changed files with 54 additions and 3 deletions

View File

@ -32,7 +32,9 @@ namespace Alchemy.Editor
}
[SerializeField] HierarchyObjectMode hierarchyObjectMode = HierarchyObjectMode.RemoveInBuild;
[SerializeField] bool showHierarchyToggles;
public HierarchyObjectMode HierarchyObjectMode => hierarchyObjectMode;
public bool ShowHierarchyToggles => showHierarchyToggles;
}
}

View File

@ -57,6 +57,12 @@ namespace Alchemy.Editor
var hierarchyObjectModeField = new PropertyField(serializedObject.FindProperty("hierarchyObjectMode"));
root.Add(hierarchyObjectModeField);
var showHierarchyTogglesField = new PropertyField(serializedObject.FindProperty("showHierarchyToggles"))
{
label = "Show Toggles"
};
root.Add(showHierarchyTogglesField);
root.Bind(serializedObject);
root.TrackSerializedObjectValue(serializedObject, so =>
{

View File

@ -0,0 +1,32 @@
using UnityEditor;
using UnityEngine;
using Alchemy.Hierarchy;
namespace Alchemy.Editor
{
public sealed class HierarchyButtonDrawer : HierarchyDrawer
{
public override void OnGUI(int instanceID, Rect selectionRect)
{
var gameObject = EditorUtility.InstanceIDToObject(instanceID) as GameObject;
if (gameObject == null) return;
if (gameObject.TryGetComponent<HierarchyObject>(out _)) return;
if (AlchemySettings.GetOrCreateSettings().ShowHierarchyToggles)
{
var pos = selectionRect;
pos.x = pos.xMax - 8f;
pos.width = 16f;
var active = GUI.Toggle(pos, gameObject.activeSelf, string.Empty);
if (active != gameObject.activeSelf)
{
Undo.RecordObject(gameObject, $"{(active ? "Activate" : "Deactivate")} GameObject '{gameObject.name}'");
gameObject.SetActive(active);
EditorUtility.SetDirty(gameObject);
}
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 527cfc72d81d34166ab175d08e86e0b5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,7 +1,6 @@
using System.Linq;
using Alchemy.Editor.Internal;
using UnityEditor;
using UnityEngine;
using Alchemy.Editor.Internal;
namespace Alchemy.Editor
{

View File

@ -1,3 +1,4 @@
{
"hierarchyObjectMode": 2
"hierarchyObjectMode": 2,
"showHierarchyToggles": true
}