Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Commit

Permalink
Updated version to 1.1.0.
Browse files Browse the repository at this point in the history
Misc project organization.
Added SubstanceGraph extension functions to get and set graph output size.
SubstanceParameter now has a value for the value type (bool, int, Vector2) of the input parameter.
Fixed warning in SubstanceGraphExtensionsTest class.
  • Loading branch information
Synthoid committed Jul 2, 2018
1 parent 687d816 commit 39baedc
Show file tree
Hide file tree
Showing 24 changed files with 380 additions and 6 deletions.
8 changes: 8 additions & 0 deletions Assets/Plugins/Substance Extensions/Editor/Extensions.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using UnityEngine;
using UnityEditor;

namespace Substance.Editor
{
/// <summary>
/// Class containing extension methods for the <see cref="SerializedProperty"/> class.
/// </summary>
public static class SerializedPropertyExtensions
{
/// <summary>
/// Returns a sibling property to the given property.
/// </summary>
/// <param name="property">The property to get a sibling property for.</param>
/// <param name="path">The path to the target property. This is usually just the property's name.</param>
/// <param name="isRoot">If true, the target property will be navigated to starting at the given property's SerializedObject.</param>
public static SerializedProperty GetSiblingProperty(this SerializedProperty property, string path, bool isRoot = false)
{
SerializedProperty targetProperty = null;

if (!isRoot && property.propertyPath.IndexOf('.') > 0)
{
path = property.propertyPath.Substring(0, property.propertyPath.LastIndexOf('.') + 1) + path;
}

targetProperty = property.serializedObject.FindProperty(path);

return targetProperty;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ protected override string TargetField
protected override void DrawTargetField(Rect position, SerializedProperty property, SerializedProperty assetProperty)
{
SubstanceGraph graph = assetProperty.objectReferenceValue as SubstanceGraph;

SerializedProperty typeProperty = property.GetSiblingProperty("type");

int inputCount = NativeFunctions.cppGetNumInputs(graph.nativeHandle);
Globals.Input[] inputs = Globals.GetNativeInputs(graph, inputCount);
GUIContent[] labels = new GUIContent[inputCount];

for (int i = 0; i < inputCount; i++)
{
labels[i] = new GUIContent(string.Format("{0}{1} ({2})", (string.IsNullOrEmpty(inputs[i].group) ? "" : inputs[i].group + "/"), inputs[i].label, inputs[i].name));
labels[i] = new GUIContent(string.Format("{0}{1} ({2} - {3})", (string.IsNullOrEmpty(inputs[i].group) ? "" : inputs[i].group + "/"), inputs[i].label, inputs[i].name, (SubstanceInputType)inputs[i].substanceInputType), inputs[i].name);
}

int index = 0;
int index = -1;

for (int i = 0; i < inputCount; i++)
{
Expand All @@ -41,11 +42,19 @@ protected override void DrawTargetField(Rect position, SerializedProperty proper
}
}

if(index < 0 && inputCount > 0)
{
index = 0;
property.stringValue = inputs[index].name;
typeProperty.intValue = inputs[index].substanceInputType;
}

EditorGUI.BeginChangeCheck();
index = EditorGUI.Popup(position, index, labels);
if(EditorGUI.EndChangeCheck())
{
property.stringValue = inputs[index].name;
typeProperty.intValue = inputs[index].substanceInputType;
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions Assets/Plugins/Substance Extensions/Enums.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions Assets/Plugins/Substance Extensions/Enums/SubstanceInputType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Substance.Game
{
/// <summary>
/// Wrapper enum for the Global.Input.substanceInputType int value.
/// </summary>
public enum SubstanceInputType : byte
{
Float = 0,
Vector2 = 1,
Vector3 = 2,
Vector4 = 3,
Int_Or_Bool = 4,
Texture = 5,
String = 6,
Vector2Int = 8,
Vector3Int = 9,
Vector4Int = 10
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions Assets/Plugins/Substance Extensions/Enums/SubstanceOutputSize.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace Substance.Game
{
/// <summary>
/// Wrapper enum for the int values expected for setting substance output size via code.
/// Code: substanceGraph.SetInputVector2Int("$outputsize", x, y);
/// </summary>
public enum SubstanceOutputSize : byte
{
/// <summary>
/// 32 x 32
/// </summary>
_32 = 5,
/// <summary>
/// 64 x 64
/// </summary>
_64 = 6,
/// <summary>
/// 128 x 128
/// </summary>
_128 = 7,
/// <summary>
/// 256 x 256
/// </summary>
_256 = 8,
/// <summary>
/// 512 x 512
/// </summary>
_512 = 9,
/// <summary>
/// 1024 x 1024
/// </summary>
_1024 = 10,
/// <summary>
/// 2048 x 2048
/// </summary>
_2048 = 11,
/// <summary>
/// 4096 x 4096
/// </summary>
_4096 = 12
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public class SubstanceGraphExtensionsTest : MonoBehaviour
[SerializeField]
[Tooltip("Key to press to randomize the random seed value of a graph and rebuild it.")]
private KeyCode randomizeKey = KeyCode.Space;
[SerializeField]
[Tooltip("Key to press to set the output size of a graph and rebuild it.")]
private KeyCode outputSizeKey = KeyCode.O;

private void Update()
{
Expand All @@ -19,6 +22,11 @@ private void Update()
graph.RandomizeSeed();
graph.QueueForRender();
}
if(Input.GetKeyDown(outputSizeKey))
{
graph.SetOutputSize(SubstanceOutputSize._1024);
graph.QueueForRender();
}
}
}
}
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@ public class SubstanceOutputExample : MonoBehaviour
{
[SerializeField]
private SubstanceOutput output = new SubstanceOutput();
}

private void Start()
{
Debug.Log(output.outputName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2628,9 +2628,12 @@ MonoBehaviour:
luminosityParam:
graph: {fileID: 11400002, guid: 2ddac2369adc73148b56b6987705930a, type: 3}
parameter: luminosity
type: 0
hueParam:
graph: {fileID: 11400002, guid: 2ddac2369adc73148b56b6987705930a, type: 3}
parameter: hue_shift
type: 0
saturationParam:
graph: {fileID: 11400002, guid: 2ddac2369adc73148b56b6987705930a, type: 3}
parameter: saturation
type: 0
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ private void Start()
saturationSlider.onValueChanged.AddListener(OnSaturationChanged);

refreshButton.onClick.AddListener(OnRefreshClicked);

Debug.Log(string.Format("{0} - {1}\n{2} - {3}\n{4} - {5}", luminosityParam.parameter, luminosityParam.type, hueParam.parameter, hueParam.type, saturationParam.parameter, saturationParam.type));
}
}
}
Loading

0 comments on commit 39baedc

Please sign in to comment.