com.soosvet_games.common_tools 1.1.8 → 1.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,111 @@
1
+ #if UNITY_6000_6_OR_NEWER
2
+ using Unity.Hierarchy;
3
+ using Unity.Hierarchy.Editor;
4
+ using UnityEditor;
5
+ using UnityEngine;
6
+ using UnityEngine.UIElements;
7
+
8
+ namespace SoosvetGames.CommonTools.Extensions.Editor
9
+ {
10
+ internal static class HierarchyActivationToolUnity6_6
11
+ {
12
+ [ InitializeOnLoadMethod ]
13
+ private static void Install()
14
+ {
15
+ HierarchyWindow.BindViewItem += BindItem;
16
+ HierarchyWindow.UnbindViewItem += UnbindItem;
17
+ AssemblyReloadEvents.beforeAssemblyReload += Uninstall;
18
+ }
19
+
20
+ private static void Uninstall()
21
+ {
22
+ HierarchyWindow.BindViewItem -= BindItem;
23
+ HierarchyWindow.UnbindViewItem -= UnbindItem;
24
+ }
25
+
26
+ private static void BindItem( HierarchyWindow window, HierarchyView view, HierarchyViewItem item )
27
+ {
28
+ GameObject gameObject = item.Handler switch
29
+ {
30
+ HierarchyGameObjectHandler handler => handler.GetGameObject( item.Node ),
31
+ HierarchySubSceneAuthoringHandler handler => handler.GetGameObject( item.Node ),
32
+ _ => null
33
+ };
34
+ if ( gameObject == null )
35
+ return;
36
+
37
+ VisualElement container = item.RightCustomContainer;
38
+ ActivationToggle toggle = container.Q<ActivationToggle>();
39
+ if ( toggle == null )
40
+ {
41
+ toggle = new ActivationToggle();
42
+ container.Add( toggle );
43
+ }
44
+
45
+ toggle.BindGameObject( gameObject );
46
+ }
47
+
48
+ private static void UnbindItem( HierarchyWindow window, HierarchyView view, HierarchyViewItem item )
49
+ {
50
+ item.RightCustomContainer.Q<ActivationToggle>()?.UnbindGameObject();
51
+ }
52
+
53
+ private sealed class ActivationToggle : Toggle
54
+ {
55
+ private readonly IVisualElementScheduledItem _refresh;
56
+ private GameObject _gameObject;
57
+
58
+ public ActivationToggle()
59
+ {
60
+ name = "soosvet-hierarchy-activation-toggle";
61
+ tooltip = "Set GameObject Active";
62
+ focusable = false;
63
+ style.marginTop = 0;
64
+ style.marginBottom = 0;
65
+
66
+ this.RegisterValueChangedCallback( SetActive );
67
+ // Inspector edits, Undo and scripts can change activeSelf while this row stays bound.
68
+ _refresh = schedule.Execute( RefreshValue ).Every( 100 );
69
+ }
70
+
71
+ public void BindGameObject( GameObject gameObject )
72
+ {
73
+ _gameObject = gameObject;
74
+ RefreshValue();
75
+ style.display = DisplayStyle.Flex;
76
+ _refresh.Resume();
77
+ }
78
+
79
+ public void UnbindGameObject()
80
+ {
81
+ _gameObject = null;
82
+ _refresh.Pause();
83
+ style.display = DisplayStyle.None;
84
+ }
85
+
86
+ private void RefreshValue()
87
+ {
88
+ if ( _gameObject == null )
89
+ return;
90
+
91
+ bool isActive = _gameObject.activeSelf;
92
+ if ( value != isActive )
93
+ SetValueWithoutNotify( isActive );
94
+ }
95
+
96
+ private void SetActive( ChangeEvent<bool> change )
97
+ {
98
+ GameObject gameObject = _gameObject;
99
+ if ( gameObject == null || gameObject.activeSelf == change.newValue )
100
+ return;
101
+
102
+ Undo.RecordObject( gameObject, $"Set Active {gameObject.name}" );
103
+ gameObject.SetActive( change.newValue );
104
+
105
+ if ( gameObject != null && PrefabUtility.IsPartOfPrefabInstance( gameObject ) )
106
+ PrefabUtility.RecordPrefabInstancePropertyModifications( gameObject );
107
+ }
108
+ }
109
+ }
110
+ }
111
+ #endif
@@ -0,0 +1,2 @@
1
+ fileFormatVersion: 2
2
+ guid: 0fdf21d5333749feaed6dd05890c0d00
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name" : "com.soosvet_games.common_tools",
3
3
  "displayName" : "Soosvet Games Common Tools",
4
- "version" : "1.1.8",
4
+ "version" : "1.1.9",
5
5
  "author" : "Soosvet Games",
6
6
  "description" : "Common tools for Unity.",
7
7
  "repository": {