Skip to content

Commit 0d79d1e

Browse files
Merge pull request #8 from RobProductions/working-branch
Fix Booleans and Add Vector Prefixes
2 parents b09d6d0 + 1cd73b9 commit 0d79d1e

File tree

5 files changed

+149
-26
lines changed

5 files changed

+149
-26
lines changed

CHANGELOG.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
## [Unreleased]
6+
7+
## [1.3.0] - 2023-12-14
8+
9+
### Added
10+
11+
- Added Vector prefix feature
12+
13+
### Fixed
14+
15+
- Fixed Boolean property rendering
16+
17+
## [1.2.1] - 2022-11-20
18+
19+
### Fixed
20+
21+
- Fixed build issues
22+
23+
## [1.2.0] - 2022-11-10
24+
25+
### Added
26+
27+
- Added foldout group feature
28+
29+
## [1.1.0] - 2022-11-06
30+
31+
### Added
32+
33+
- Added field expansion prefixes
34+

CHANGELOG.md.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/ShaderGraphEditor/OpenGraphGUIEditor.cs

Lines changed: 81 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using UnityEngine;
44
using UnityEditor;
5+
using UnityEngine.UIElements;
56

67
/// <summary>
78
/// This is a globally accessible "wrapper" class that helps
@@ -32,6 +33,10 @@ public class OpenGraphGUIEditor : ShaderGUI
3233
/// </summary>
3334
const float texFieldBoxSize = 65f;
3435
/// <summary>
36+
/// Width of vector field on Vec2 and Vec3 property renders.
37+
/// </summary>
38+
const float vecFieldBoxSize = 220f;
39+
/// <summary>
3540
/// Heuristic for when extra field shrinking kicks in on small inspectors.
3641
/// </summary>
3742
const float minLabelWidthAdjustField = 320f;
@@ -70,6 +75,9 @@ public class OpenGraphGUIEditor : ShaderGUI
7075
const string singleLineTexPrefix = "%";
7176
const string dependentVisibleTextPrefix = "^";
7277
const string linkedPropertyPrefix = "&";
78+
const string vec2Prefix = "2~";
79+
const string vec3Prefix = "3~";
80+
const string vec4Prefix = "4~";
7381

7482
/// <summary>
7583
/// Representation of a property with the linkedPropertyPrefix.
@@ -175,7 +183,6 @@ void RenderPropertiesList(MaterialProperty[] properties)
175183
else if (thisProp.displayName.StartsWith(foldoutPrefix))
176184
{
177185
//This is a foldout property
178-
179186
foldoutCount++;
180187
}
181188
}
@@ -194,7 +201,7 @@ void RenderPropertiesList(MaterialProperty[] properties)
194201
continue;
195202
}
196203

197-
//First check if this property has a custom extension
204+
//Check if this property has a custom extension
198205
if(renderExtensions != null && renderExtensions.ContainsKey(thisProp.displayName))
199206
{
200207
//Invoke the custom render function passed into the dictionary
@@ -226,7 +233,7 @@ void RenderPropertiesList(MaterialProperty[] properties)
226233
//Use min field width and don't render this property
227234
SetFieldExpandedMode(false);
228235
}
229-
else if(currentLinkedProperties.ContainsKey(propName) && DoRenderProp())
236+
else if(currentLinkedProperties.ContainsKey(propName) && DoRenderFoldoutProp())
230237
{
231238
//This is a linked property, so check if it was rendered already
232239
var thisLinkedProp = currentLinkedProperties[propName];
@@ -288,7 +295,7 @@ void RenderPropertiesList(MaterialProperty[] properties)
288295
}
289296

290297
}
291-
else if(propName.StartsWith(labelPrefix) && DoRenderProp())
298+
else if(propName.StartsWith(labelPrefix) && DoRenderFoldoutProp())
292299
{
293300
//This is a label type, so show a bold header instead of the property
294301

@@ -297,7 +304,7 @@ void RenderPropertiesList(MaterialProperty[] properties)
297304

298305
RenderLabelProperty(propName);
299306
}
300-
else if (propName.StartsWith(dependentVisibleTextPrefix) && DoRenderProp())
307+
else if (propName.StartsWith(dependentVisibleTextPrefix) && DoRenderFoldoutProp())
301308
{
302309
//It is dependent, so we will conditionally render it
303310

@@ -313,7 +320,7 @@ void RenderPropertiesList(MaterialProperty[] properties)
313320
//Don't render this property
314321
}
315322
}
316-
else if (DoRenderProp())
323+
else if (DoRenderFoldoutProp())
317324
{
318325
//It's not dependent, so update populated state based on this
319326
if (thisProp.type == MaterialProperty.PropType.Texture)
@@ -403,6 +410,8 @@ void RenderDependentVisibleProperty(MaterialProperty v, string labelName, int in
403410
/// <param name="index"></param>
404411
void RenderVisibleProperty(MaterialProperty v, string labelName, int index)
405412
{
413+
bool lastMixedValue = EditorGUI.showMixedValue;
414+
EditorGUI.showMixedValue = v.hasMixedValue;
406415

407416
if (labelName.StartsWith(singleLineTexPrefix))
408417
{
@@ -439,14 +448,76 @@ void RenderVisibleProperty(MaterialProperty v, string labelName, int index)
439448
{
440449
//Labeled as a single line tex type, but not a texture
441450
GraphLog("Property was labeled as a single line texture (" + singleLineTexPrefix
442-
+ "), but not a texture type - " + labelName);
451+
+ "), but not a Texture type - " + labelName);
452+
RenderDefaultPropertyView(v, labelName);
453+
}
454+
}
455+
else if(labelName.StartsWith(vec2Prefix) || labelName.StartsWith(vec3Prefix) || labelName.StartsWith(vec4Prefix))
456+
{
457+
if(v.type == MaterialProperty.PropType.Vector)
458+
{
459+
//This is a vector type
460+
461+
int vecCount = 2;
462+
string thisPrefix = vec2Prefix;
463+
if(labelName.StartsWith(vec3Prefix))
464+
{
465+
vecCount = 3;
466+
thisPrefix = vec3Prefix;
467+
}
468+
else if (labelName.StartsWith(vec4Prefix))
469+
{
470+
vecCount = 4;
471+
thisPrefix = vec4Prefix;
472+
}
473+
474+
//Trim the vector prefix
475+
labelName = labelName.Substring(thisPrefix.Length);
476+
477+
if(vecCount == 4)
478+
{
479+
RenderDefaultPropertyView(v, labelName);
480+
}
481+
else
482+
{
483+
//Render custom vector fields
484+
485+
//Set the label width for vectors
486+
var lastLabelWidth = EditorGUIUtility.labelWidth;
487+
EditorGUIUtility.labelWidth = 0f;
488+
489+
EditorGUI.BeginChangeCheck();
490+
Vector4 vec;
491+
if(vecCount == 3)
492+
{
493+
vec = EditorGUILayout.Vector3Field(labelName, v.vectorValue, GUILayout.ExpandWidth(true));
494+
}
495+
else
496+
{
497+
vec = EditorGUILayout.Vector2Field(labelName, v.vectorValue, GUILayout.ExpandWidth(true));
498+
}
499+
if (EditorGUI.EndChangeCheck())
500+
{
501+
v.vectorValue = vec;
502+
}
503+
504+
EditorGUIUtility.labelWidth = lastLabelWidth;
505+
}
506+
}
507+
else
508+
{
509+
//Labeled as a vector but not one
510+
GraphLog("Property was labeled as a Vector (" + vec2Prefix + " or " + vec3Prefix + " or " + vec4Prefix
511+
+ "), but was not a Vector type - " + labelName);
443512
RenderDefaultPropertyView(v, labelName);
444513
}
445514
}
446515
else
447516
{
448517
RenderDefaultPropertyView(v, labelName);
449518
}
519+
520+
EditorGUI.showMixedValue = lastMixedValue;
450521
}
451522

452523
/// <summary>
@@ -458,6 +529,7 @@ void RenderDefaultPropertyView(MaterialProperty v, string customName = "")
458529

459530
string finalName = (customName == "") ? v.displayName : customName;
460531

532+
//Note: May want to check ShaderUtil.GetPropertyType for more complex fields
461533
switch(v.type)
462534
{
463535
case MaterialProperty.PropType.Texture:
@@ -477,7 +549,7 @@ void RenderDefaultPropertyView(MaterialProperty v, string customName = "")
477549
EditorGUIUtility.labelWidth = lastLabel;
478550
break;
479551
default:
480-
matEditor.DefaultShaderProperty(v, finalName);
552+
matEditor.ShaderProperty(v, finalName);
481553
break;
482554
}
483555

@@ -501,7 +573,7 @@ void RenderLabelProperty(string propName)
501573
/// based on foldout status.
502574
/// </summary>
503575
/// <returns></returns>
504-
bool DoRenderProp()
576+
bool DoRenderFoldoutProp()
505577
{
506578
return (!currentlyInFoldout || foldoutArray[currentFoldoutIndex]);
507579
}

README.md

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ The default Inspector view for ShaderGraph-based materials can be somewhat bland
1717

1818
If you're looking for a more comprehensive and feature-complete Shader GUI package, I highly recommend [Shader Graph Markdown](https://assetstore.unity.com/packages/tools/gui/shader-graph-markdown-194781) which this project is inspired from. They will be able to provide much more support and QOL features for developers needing extensive custom GUIs. The intent of OpenGraphGUI is to provide a simple open source alternative that the community is free to edit and improve as needed.
1919

20-
### Match the look of URP Lit Materials
20+
### Match the look of built-in URP Materials
2121

22-
**OpenGraphGUI** was built to be a replacement for the default ShaderGraph GUI provided by Unity. The feature set allows you to add in features such as the "Single Line Texture" that you'd find in default URP materials. It also provides labels and other "clean up" enhancements to give you more control over the look of your GUI.
22+
**OpenGraphGUI** was built to be a replacement for the default ShaderGraph GUI provided by Unity. The feature set allows you to add cleaner layouts for your material properties such as the "Single Line Texture" that you'd find in default URP materials. It also provides labels and other organizational enhancements to give you more control over the look of your GUI.
2323

2424
## Usage
2525

@@ -29,30 +29,36 @@ In ShaderGraph, simply change your *"Custom Editor GUI"* setting to the named cl
2929

3030
### Labels & Alignment
3131

32-
Prefix one of your properties with the **star symbol (\*)** and that field will become a bold label.
32+
> Use these naming rules to adjust the spacing of your Material's inspector and organize fields. Note that these properties are only meant to send information to OpenGraphGUI and will not be rendered, so you can use any type you prefer. For consistency, choosing a Boolean for these properties is simplest.
3333
34-
Use a property called **\[Centered\]** to adjust the spacing of the Inspector fields to match the look of non-ShaderGraph default materials. Use a property called **\[RightBound\]** to return the field spacing to the default ShaderGraph look.
34+
Prefix one of your property names with the **star symbol (\*)** and that field will become a bold label. For example, if you want a bold label with the text **"Lighting"**, use the name `*Lighting` for that property in ShaderGraph.
35+
36+
Create a property with the name **\[Centered\]** to adjust the spacing of the Inspector fields to match the look of non-ShaderGraph default materials. Use a property called **\[RightBound\]** to return the field spacing to the default ShaderGraph look.
3537

3638
<img width = "800" src="Documentation~/DocAssets/AlignmentTags.gif">
3739

38-
**New!** When in the **\[Centered\]** mode, use a property called **\[MaxField\]** to let the field take up more width in the inspector. This look is meant to match the "expanded" feel of color tints for single-line textures and improve the accessibility of fields by making them easier to edit. Use a property called **\[MinField\]** to return to the small field style.
40+
When in the **\[Centered\]** mode, use a property called **\[MaxField\]** to let the value field take up more width in the inspector. This look is meant to match the "expanded" feel of color tints for single-line textures and improve the accessibility of fields by making them easier to edit. Use a property called **\[MinField\]** to return to the default spacing style.
3941

4042
<img width = "500" src="Documentation~/DocAssets/FieldWidthScreenshot.jpg">
4143

42-
**New!** Use the **hashtag symbol (#)** as a prefix for one of your properties and you will create a Foldout Group with your property name as the title. Create up to 128 unique foldout groups by creating new foldout properties in sequence without having to tag the end of each group. If you do wish to close the previous Foldout Group, simply create a property that consists of only a **hashtag symbol (#)** without any name. The following properties will exist outside of the last group.
44+
Use the **hashtag symbol (#)** as a prefix for one of your properties and you will create a Foldout Group with your property name as the title. Each subsequent property will become a part of the group. You can create up to 128 unique foldout groups by labeling new foldout properties in sequence without having to tag the end of each group. If you do wish to close the previous Foldout Group, simply create a property that consists of only a **hashtag symbol (#)** without any name. The following properties will exist outside of the last group.
4345

4446
<img width = "550" src="Documentation~/DocAssets/FoldoutGroupsScreenshot.jpg">
4547

4648
### Property Rendering Features
4749

48-
Prefix a texture property with the **percent symbol (%)** and it will show as a single line texture property instead of the big thumbnail version. Single line textures are commonly used in the built-in materials and offer a cleaner look that takes up less space in your Inspector.
50+
> Use these naming rules to adjust how each field is rendered in the inspector.
51+
52+
Prefix a texture property with the **percent symbol (%)** and it will show as a single line texture property instead of the big thumbnail version. Single line textures are commonly used in the built-in materials and offer a cleaner look that takes up less space in your Inspector. Example name: `%MySingleLineTexture`
4953

50-
Follow up a single-line texture property with an **ampersand prefix (&)** and the resulting property will be drawn on the same line as the texture. OpenGraphGUI calls this a "linked property", and you'll commonly find these used as "tint colors" in the default materials.
54+
Follow up a single-line texture property with a property that uses the **ampersand prefix (&)** and the resulting property will be shown on the same line as the texture. OpenGraphGUI calls this a "linked property", and you'll commonly find these used as "tint colors" in the default materials. Example name: `&MyLinkedProperty`
5155

52-
Follow up any texture property with an **arrow prefix (^)** and that property will only become visible when the texture above it has been filled out by the user (not null). This is called a "dependent visible" property. You'll find this on many custom shaders that utilize a strength value, appearing only when the asociated texture is present.
56+
Follow up any texture property with a property that uses the **arrow prefix (^)** and that property will only become visible when the texture above it has been populated by the user (not null). This is called a "dependent visible" property. You'll find this on many custom shaders that utilize a strength value, appearing only when the asociated texture is present. Example name: `^MyDependentProperty`
5357

5458
<img width = "800" src="Documentation~/DocAssets/DependentTags.gif">
5559

60+
**NEW!** Prefix any vector property with **2~**, **3~**, or **4~** to show it as a Vector2, Vector3, or Vector4 field respectively. By default, ShaderGraph material inspectors render all vectors as Vector4, so this extra information is necessary to tell OpenGraphGUI which type you want to use. Example name: `2~MyVector2` or `3~MyVector3`
61+
5662
### Extensions
5763

5864
**OpenGraphGUI** also supports custom property extensions if you'd like to keep the ease of use of prefixing without re-writing the whole package.
@@ -72,18 +78,22 @@ public MyOpenGraphGUIExtension()
7278

7379
Finally, set the *Custom Editor GUI* of your ShaderGraph to your custom class. That's it! Now you've got a custom function to render the property of your choice which is used in place of the drawing code that OpenGraphGUI would've used once it finds that property.
7480

75-
## Installation
81+
## Recommended Installation
7682

7783
1. Open the [Package Manager](https://docs.unity3d.com/2020.3/Documentation/Manual/upm-ui.html) in Unity
7884
2. Click the '+' icon and hit *"Add package from git URL"*
7985
3. Add the GitHub "HTTPS Clone" URL for OpenGraphGUI: [https://github.com/RobProductions/OpenGraphGUI.git](https://github.com/RobProductions/OpenGraphGUI.git)
8086
4. Wait for download to complete
8187
5. Add the custom GUI class *RPOpenGraphGUI* to the *Custom Editor GUI* field in your ShaderGraph of choice
8288

83-
If installation fails due to version requirements, you may be able force OpenGraphGUI to work by downloading the project as .zip and editing the "package.json" file to lower the Unity requirement. Deleting the .meta files may also be necessary and shouldn't break anything... I think. Then use the *"Add package from disk"* option to add your custom version instead.
84-
8589
If you're looking to add a specific release of OpenGraphGUI, you can specify a release tag with the hashtag like so: "https://github.com/RobProductions/OpenGraphGUI.git#ReleaseNumber"
8690

91+
## Manual Installation
92+
93+
You can also manually install OpenGraphGUI by downloading the project as .zip and placing the contents into your *Assets* folder or into the *Packages* folder to create an embedded package. I don't recommend going this route unless you have specific reason to keep a static local copy.
94+
95+
If the Package Manager installation fails due to version requirements, you may be able force OpenGraphGUI to work by downloading the project as .zip and editing the "package.json" file to lower the Unity requirement. Deleting the .meta files may also be necessary and shouldn't break anything... I think. Then use the *"Add package from disk"* option to add your custom version instead.
96+
8797
## How to Contribute
8898

8999
This open source project is free for all to suggest improvements, and I'm hoping that more contributors could help clean up the code and add further features as suggested by the community. These are the recommended steps to add your contribution:
@@ -108,7 +118,7 @@ In theory **OpenGraphGUI** should work with regular Shaders and even HDRP Shader
108118
### Limitations
109119

110120
- Though there shouldn't be any performance concerns with the prefixing approach (Unity should automatically cull out properties internally that are not used), it does bloat up the ShaderGraph quite a bit. Since this is meant to be a simple enhancement, I didn't take the route of editing the ShaderGraph GUI itself, so prefixed properties won't look any different from non-prefixed ones.
111-
- There are certain rules you must follow for your properties to show up as expected. All linked properties must follow a single line texture property. Dependent visible properties must follow another dependent visible or texture property or linked property (since it will be bundled with the texture). If those rules are violated, OpenGraphGUI will throw a warning to the console.
121+
- There are certain rules you must follow for your properties to show up as expected. All linked properties must follow a single line texture property. Dependent visible properties must follow another dependent visible property, a texture property, or a linked property (since it will be bundled with the texture). If those rules are violated, OpenGraphGUI will throw a warning to the console with some specifics about what went wrong.
112122

113123
### License
114124

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.robproductions.opengraphgui",
3-
"version": "1.2.1",
3+
"version": "1.3.0",
44
"displayName": "Open Graph GUI",
55
"description": "An open-source generic Shader GUI for use with URP ShaderGraphs. This package aims to help developers clean up the look of their Material properties while maintaining the built-in style.",
66
"unity": "2020.3",
@@ -9,9 +9,9 @@
99
"license": "MIT License",
1010
"keywords": [
1111
"shader",
12-
"graph",
13-
"editor",
14-
"gui"
12+
"graph",
13+
"editor",
14+
"gui"
1515
],
1616
"author": {
1717
"name": "RobProductions",

0 commit comments

Comments
 (0)