A game about forced loneliness, made by TACStudios
1using System;
2using UnityEditor.IMGUI.Controls;
3using UnityEngine;
4using UnityEngine.UIElements;
5
6namespace UnityEditor.U2D.Animation
7{
8 internal interface IVisibilityTool
9 {
10 VisualElement view { get; }
11 string name { get; }
12 void Activate();
13 void Deactivate();
14 bool isAvailable { get; }
15 void SetAvailabilityChangeCallback(Action callback);
16 void Setup();
17 void Dispose();
18 }
19
20 internal class VisibilityToolViewBase : VisualElement
21 {
22 IMGUIContainer m_Container;
23 SearchField m_SearchField;
24 protected IMGUI.Controls.TreeView m_TreeView;
25 protected TreeViewState m_TreeViewState = new TreeViewState();
26
27 public Action<float> SetOpacityValue = null;
28 public Func<float> GetOpacityValue = null;
29
30 protected static class Styles
31 {
32 public static readonly GUIStyle preLabel = "preLabel";
33 public static readonly GUIStyle preSlider = "preSlider";
34 public static readonly GUIStyle preSliderThumb = "preSliderThumb";
35 }
36
37 public VisibilityToolViewBase()
38 {
39 m_Container = new IMGUIContainer(OnGUI);
40 this.Add(m_Container);
41 m_TreeViewState.searchString = "";
42 }
43
44 protected void SetupSearchField()
45 {
46 m_SearchField = new SearchField();
47 m_SearchField.downOrUpArrowKeyPressed += m_TreeView.SetFocusAndEnsureSelectedItem;
48 }
49
50 void DoSearchField()
51 {
52 m_SearchField.downOrUpArrowKeyPressed += m_TreeView.SetFocusAndEnsureSelectedItem;
53 GUILayout.BeginHorizontal(EditorStyles.toolbar);
54 m_TreeView.searchString = m_SearchField.OnToolbarGUI(m_TreeView.searchString);
55 GUILayout.EndHorizontal();
56 }
57
58 void DoOpacitySlider()
59 {
60 if (GetOpacityValue != null && SetOpacityValue != null)
61 {
62 GUILayout.BeginHorizontal(EditorStyles.toolbar);
63 EditorGUI.BeginChangeCheck();
64 var opacity = GUILayout.HorizontalSlider(GetOpacityValue(), 0, 1, Styles.preSlider, Styles.preSliderThumb);
65 if (EditorGUI.EndChangeCheck())
66 SetOpacityValue(opacity);
67 GUILayout.EndHorizontal();
68 }
69 }
70
71 void OnGUI()
72 {
73 GUILayout.BeginVertical();
74 DoSearchField();
75 GUILayout.EndVertical();
76 Rect rect = GUILayoutUtility.GetRect(0, 100000, 0, 100000);
77 m_TreeView.OnGUI(rect);
78 DoOpacitySlider();
79 }
80 }
81
82 internal class TreeViewItemBase<T> : TreeViewItem
83 {
84 public T customData;
85
86 public TreeViewItemBase(int id, int depth, string name, T data) : base(id, depth, name)
87 {
88 customData = data;
89 }
90 }
91
92 internal class VisibilityTreeViewBase : IMGUI.Controls.TreeView
93 {
94 static internal class VisibilityIconStyle
95 {
96 public static readonly GUIContent visibilityOnIcon = new GUIContent(EditorIconUtility.LoadIconResource("Visibility_Tool", EditorIconUtility.LightIconPath, EditorIconUtility.DarkIconPath), L10n.Tr("On"));
97 public static readonly GUIContent visibilityOffIcon = new GUIContent(EditorIconUtility.LoadIconResource("Visibility_Hidded", EditorIconUtility.LightIconPath, EditorIconUtility.DarkIconPath), L10n.Tr("Off"));
98 }
99
100
101 public VisibilityTreeViewBase(TreeViewState treeViewState, MultiColumnHeader multiColumn)
102 : base(treeViewState, multiColumn)
103 {
104 Init();
105 }
106
107 public VisibilityTreeViewBase(TreeViewState treeViewState)
108 : base(treeViewState)
109 {
110 Init();
111 }
112
113 void Init()
114 {
115 this.showAlternatingRowBackgrounds = true;
116 this.useScrollView = true;
117 }
118
119 protected override TreeViewItem BuildRoot()
120 {
121 return new TreeViewItem { id = 0, depth = -1 };
122 }
123 }
124}