Skip to content

Commit 9687b67

Browse files
committed
Reorganization and added some code documentation
1 parent 16b1647 commit 9687b67

36 files changed

+627
-306
lines changed

Editor/Editors/Components/FunctionTimeline.cs

Lines changed: 13 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
using UnityEngine;
66
using UnityEngine.UIElements;
77
using UnityEditor.UIElements;
8+
using VRLabs.ModularShaderSystem.UI;
89

9-
namespace VRLabs.ModularShaderSystem
10+
namespace VRLabs.ModularShaderSystem.Debug
1011
{
12+
/// <summary>
13+
/// Modular Shader Debugger tab used to show the functions flow in the modular shader
14+
/// </summary>
1115
public class FunctionTimeline : IModularShaderDebuggerTab
1216
{
1317
public VisualElement TabContainer { get; set; }
@@ -30,8 +34,8 @@ public void UpdateTab(ModularShader shader)
3034
TabContainer.Add(new TimelineContainer(shader));
3135
}
3236
}
33-
34-
public class FunctionItem : VisualElement
37+
38+
internal class FunctionItem : VisualElement
3539
{
3640
public ShaderFunction Function { get; }
3741
public TimelineRow Row { get; set; }
@@ -65,7 +69,7 @@ public FunctionItem(TimelineRoot root, ShaderFunction function, int size, int of
6569
}
6670
}
6771

68-
public class TimelineRow : VisualElement
72+
internal class TimelineRow : VisualElement
6973
{
7074
public ShaderModule Module { get; }
7175

@@ -143,7 +147,7 @@ public void SetRowsHeight()
143147
}
144148
}
145149

146-
public class TimelineRoot : VisualElement
150+
internal class TimelineRoot : VisualElement
147151
{
148152
public List<TimelineRow> Rows { get; set; }
149153
public List<FunctionItem> Functions { get; set; }
@@ -260,7 +264,7 @@ public void ResetSelectedClass()
260264
}
261265
}
262266

263-
public class FunctionViewer : VisualElement
267+
internal class FunctionViewer : VisualElement
264268
{
265269
public ShaderFunction SelectedItem
266270
{
@@ -358,85 +362,7 @@ public FunctionViewer()
358362
}
359363
}
360364

361-
public class LabelField : VisualElement
362-
{
363-
public string Label
364-
{
365-
get => _label;
366-
set
367-
{
368-
_label = value;
369-
_labelField.text = _label;
370-
}
371-
}
372-
373-
public string Value
374-
{
375-
get => _value;
376-
set
377-
{
378-
_value = value;
379-
_valueField.text = _value;
380-
}
381-
}
382-
383-
private Label _labelField;
384-
private Label _valueField;
385-
private string _label;
386-
private string _value;
387-
388-
public LabelField(string label, string value)
389-
{
390-
_label = label;
391-
_value = value;
392-
_labelField = new Label(label);
393-
_valueField = new Label(value);
394-
395-
AddToClassList("unity-base-field");
396-
AddToClassList("unity-base-text-field");
397-
AddToClassList("unity-text-field");
398-
399-
_labelField.AddToClassList("unity-text-element");
400-
_labelField.AddToClassList("unity-label");
401-
_labelField.AddToClassList("unity-base-field__label");
402-
_labelField.AddToClassList("unity-base-text-field__label");
403-
_labelField.AddToClassList("unity-text-field__label");
404-
_labelField.AddToClassList("label-field-title");
405-
_valueField.AddToClassList("label-field-value");
406-
407-
Add(_labelField);
408-
Add(_valueField);
409-
410-
}
411-
}
412-
413-
public class VariableField : VisualElement
414-
{
415-
public Variable Variable { get; set; }
416-
417-
private string _type;
418-
419-
public VariableField(Variable variable)
420-
{
421-
Variable = variable;
422-
if(variable.Type == VariableType.Custom)
423-
_type = variable.CustomType;
424-
else
425-
_type = variable.Type.ToString();
426-
var nameField = new Label(variable.Name);
427-
var typeField = new Label(_type);
428-
429-
nameField.style.flexGrow = 1;
430-
typeField.AddToClassList("variable-type-text");
431-
Add(nameField);
432-
Add(typeField);
433-
434-
style.flexDirection = FlexDirection.Row;
435-
436-
}
437-
}
438-
439-
public class ModuleViewer : VisualElement
365+
internal class ModuleViewer : VisualElement
440366
{
441367
public ShaderModule SelectedItem
442368
{
@@ -506,7 +432,7 @@ public ModuleViewer()
506432
}
507433
}
508434

509-
public class FunctionTemplateViewer : VisualElement
435+
internal class FunctionTemplateViewer : VisualElement
510436
{
511437
public string SelectedItem
512438
{
@@ -533,7 +459,7 @@ public FunctionTemplateViewer()
533459
}
534460
}
535461

536-
public class TimelineContainer : VisualElement
462+
internal class TimelineContainer : VisualElement
537463
{
538464
private List<TimelineRoot> _roots;
539465
private PopupField<TimelineRoot> _popup;

Editor/Editors/Components/TemplateGraph.cs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using UnityEditor;
54
using UnityEditor.Experimental.GraphView;
65
using UnityEngine;
76
using UnityEngine.UIElements;
7+
using VRLabs.ModularShaderSystem.UI;
88

99

10-
namespace VRLabs.ModularShaderSystem
10+
namespace VRLabs.ModularShaderSystem.Debug
1111
{
12+
/// <summary>
13+
/// Modular Shader Debugger tab used show the current template tree of the modular shader.
14+
/// </summary>
1215
public class TemplateGraph : IModularShaderDebuggerTab
1316
{
1417
public VisualElement TabContainer { get; set; }
1518
public string TabName { get; set; }
1619

17-
public TemplateGraphView _graph;
20+
internal TemplateGraphView _graph;
1821

1922
public TemplateGraph()
2023
{
@@ -23,7 +26,6 @@ public TemplateGraph()
2326
TabContainer.StretchToParentSize();
2427
var styleSheet = Resources.Load<StyleSheet>(MSSConstants.RESOURCES_FOLDER + "/MSSUIElements/TemplateGraphStyle");
2528
TabContainer.styleSheets.Add(styleSheet);
26-
2729
}
2830

2931
public void UpdateTab(ModularShader shader)
@@ -60,7 +62,7 @@ public void UpdateTab(ModularShader shader)
6062
}
6163
}
6264

63-
public class TemplateGraphView : GraphView
65+
internal class TemplateGraphView : GraphView
6466
{
6567
public List<TemplateNode> Nodes;
6668
public List<TemplateNode> BaseNodes;
@@ -180,7 +182,7 @@ private void LinkTemplateNodes(TemplateNode left, TemplateNode right, string key
180182
}
181183
}
182184

183-
public sealed class TemplateNode : Node
185+
internal sealed class TemplateNode : Node
184186
{
185187
public TemplateAsset TemplateAsset { get; set; }
186188
public string ModuleId { get; set; }
@@ -267,18 +269,4 @@ public bool ContainsKeyword(string keyword)
267269
return TemplateAsset.Keywords.Contains(keyword);
268270
}
269271
}
270-
271-
public class TextPopup : EditorWindow
272-
{
273-
public string Text;
274-
private void CreateGUI()
275-
{
276-
var viewer = new CodeViewElement();
277-
viewer.Text = Text;
278-
viewer.StretchToParentSize();
279-
var darkThemeStyleSheet = EditorGUIUtility.Load("StyleSheets/Generated/DefaultCommonDark_inter.uss.asset") as StyleSheet;
280-
rootVisualElement.styleSheets.Add(darkThemeStyleSheet);
281-
rootVisualElement.Add(viewer);
282-
}
283-
}
284272
}

Editor/Editors/Drawers/EnablePropertyDrawer.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
using UnityEngine.UIElements;
44
using UnityEditor.UIElements;
55

6-
namespace VRLabs.ModularShaderSystem
6+
namespace VRLabs.ModularShaderSystem.UI
77
{
8+
/// <summary>
9+
/// Inspector drawer for <see cref="EnableProperty"/>.
10+
/// </summary>
811
[CustomPropertyDrawer(typeof(EnableProperty))]
912
public class EnablePropertyDrawer : PropertyDrawer
1013
{

Editor/Editors/Drawers/FunctionPropertyDrawer.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
using UnityEngine;
33
using UnityEngine.UIElements;
44

5-
namespace VRLabs.ModularShaderSystem
5+
namespace VRLabs.ModularShaderSystem.UI
66
{
7+
/// <summary>
8+
/// Inspector drawer for <see cref="ShaderFunction"/>.
9+
/// </summary>
710
[CustomPropertyDrawer(typeof(ShaderFunction))]
811
public class FunctionPropertyDrawer : PropertyDrawer
912
{

Editor/Editors/Drawers/ModuleTemplatePropertyDrawer.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
using UnityEngine.UIElements;
44
using UnityEditor.UIElements;
55

6-
namespace VRLabs.ModularShaderSystem
6+
namespace VRLabs.ModularShaderSystem.UI
77
{
8+
/// <summary>
9+
/// Inspector drawer for <see cref="ModuleTemplate"/>.
10+
/// </summary>
811
[CustomPropertyDrawer(typeof(ModuleTemplate))]
912
public class ModuleTemplatePropertyDrawer : PropertyDrawer
1013
{

Editor/Editors/Drawers/ShaderPropertyDrawer.cs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,11 @@
66
using UnityEditor.UIElements;
77
using UnityEngine.Analytics;
88

9-
namespace VRLabs.ModularShaderSystem
9+
namespace VRLabs.ModularShaderSystem.UI
1010
{
11-
public enum PropertyType
12-
{
13-
Float,
14-
Int,
15-
Range,
16-
Vector,
17-
Color,
18-
Texture2D,
19-
Texture2DArray,
20-
Cube,
21-
CubeArray,
22-
Texture3D
23-
}
24-
11+
/// <summary>
12+
/// Default values for texture properties
13+
/// </summary>
2514
public enum DefaultTextureValue
2615
{
2716
White,
@@ -30,6 +19,9 @@ public enum DefaultTextureValue
3019
Bump,
3120
}
3221

22+
/// <summary>
23+
/// Inspector drawer for <see cref="Property"/>.
24+
/// </summary>
3325
[CustomPropertyDrawer(typeof(Property))]
3426
public class ShaderPropertyDrawer : PropertyDrawer
3527
{

Editor/Editors/Drawers/VariablePropertyDrawer.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
using UnityEngine.UIElements;
44
using UnityEditor.UIElements;
55

6-
namespace VRLabs.ModularShaderSystem
6+
namespace VRLabs.ModularShaderSystem.UI
77
{
8+
/// <summary>
9+
/// Inspector drawer for <see cref="Variable"/>.
10+
/// </summary>
811
[CustomPropertyDrawer(typeof(Variable))]
912
public class VariablePropertyDrawer : PropertyDrawer
1013
{

Editor/Editors/Elements/CodeViewElement.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
using UnityEngine;
44
using UnityEngine.UIElements;
55

6-
namespace VRLabs.ModularShaderSystem
6+
namespace VRLabs.ModularShaderSystem.UI
77
{
8+
/// <summary>
9+
/// VisualElement used to show a piece of code
10+
/// </summary>
811
public class CodeViewElement : VisualElement
912
{
1013
private class LineItem : VisualElement
@@ -76,6 +79,9 @@ public string Text
7679
private ListView _listView;
7780
private int _digits;
7881

82+
/// <summary>
83+
/// Default constructor of <see cref="CodeViewElement"/>
84+
/// </summary>
7985
public CodeViewElement()
8086
{
8187
ScrollView s = new ScrollView(ScrollViewMode.Horizontal);

Editor/Editors/Elements/InspectorList.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@
44
using UnityEngine;
55
using UnityEngine.UIElements;
66

7-
namespace VRLabs.ModularShaderSystem
7+
namespace VRLabs.ModularShaderSystem.UI
88
{
9+
/// <summary>
10+
/// Interface for an inspector list used for drag reorder.
11+
/// </summary>
912
public interface IInspectorList
1013
{
1114
InspectorListItem draggedElement { get; set; }
1215
void HighlightDrops();
1316
void DeHighlightDrops();
1417
}
1518

19+
/// <summary>
20+
/// Visual element used to show a list from a Serialized property containing a list
21+
/// </summary>
1622
// Shamelessly taken from here: https://forum.unity.com/threads/custom-bindableelement.989693/
1723
public class InspectorList : BindableElement, IInspectorList
1824
{
@@ -242,8 +248,9 @@ public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext
242248

243249
}
244250

245-
246-
251+
/// <summary>
252+
/// Item for <see cref="InspectorList"/>
253+
/// </summary>
247254
public class InspectorListItem : VisualElement
248255
{
249256
public Button removeButton;

0 commit comments

Comments
 (0)