-
Notifications
You must be signed in to change notification settings - Fork 855
[HDRP]Improvements and fixes on Volumes Components Inspectors #3072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sebastienlagarde
merged 3 commits into
master
from
HDRP/fix/1297795-VolumeComponent-RowsSpacing
Jan 26, 2021
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
com.unity.render-pipelines.core/Tests/Editor/ReflectionUtils.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace UnityEngine.Rendering.Tests | ||
{ | ||
public static class ReflectionUtils | ||
{ | ||
/// <summary> | ||
/// Calls a private method from a class | ||
/// </summary> | ||
/// <param name="methodName">The method name</param> | ||
/// <param name="args">The arguments to pass to the method</param> | ||
public static object Invoke(this object target, string methodName, params object[] args) | ||
{ | ||
Assert.True(target != null, "The target could not be null"); | ||
Assert.IsNotEmpty(methodName, "The field to set could not be null"); | ||
|
||
var mi = target.GetType().GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance); | ||
Assert.True(mi != null, $"Could not find method `{methodName}` on object `{target}`"); | ||
return mi.Invoke(target, args); | ||
} | ||
|
||
private static FieldInfo FindField(this Type type, string fieldName) | ||
{ | ||
FieldInfo fi = null; | ||
|
||
while (type != null) | ||
{ | ||
fi = type.GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic); | ||
|
||
if (fi != null) break; | ||
|
||
type = type.BaseType; | ||
} | ||
|
||
Assert.True(fi != null, $"Could not find method `{fieldName}` on object `{type}`"); | ||
|
||
return fi; | ||
} | ||
|
||
/// <summary> | ||
/// Sets a private field from a class | ||
/// </summary> | ||
/// <param name="fieldName">The field to change</param> | ||
/// <param name="value">The new value</param> | ||
public static void SetField(this object target, string fieldName, object value) | ||
{ | ||
Assert.True(target != null, "The target could not be null"); | ||
Assert.IsNotEmpty(fieldName, "The field to set could not be null"); | ||
target.GetType().FindField(fieldName).SetValue(target, value); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the value of a private field from a class | ||
/// </summary> | ||
/// <param name="fieldName">The field to get</param> | ||
public static object GetField(this object target, string fieldName) | ||
{ | ||
Assert.True(target != null, "The target could not be null"); | ||
Assert.IsNotEmpty(fieldName, "The field to set could not be null"); | ||
return target.GetType().FindField(fieldName).GetValue(target); | ||
} | ||
|
||
/// <summary> | ||
/// Gets all the fields from a class | ||
/// </summary> | ||
public static IEnumerable<FieldInfo> GetFields(this object target) | ||
{ | ||
Assert.True(target != null, "The target could not be null"); | ||
|
||
return target.GetType() | ||
.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) | ||
.OrderBy(t => t.MetadataToken); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
com.unity.render-pipelines.core/Tests/Editor/ReflectionUtils.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not familiar with that notation. what does the ? mean after the type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is making a nullable value type (since c# 8 you can do it on reference types).
Basically it allow us to set null to the variable(default value)
I am using it here to allow me to check if it has been initialized.
For instance imagine a
bool
that is binded to UI. bool will only have true(yes) or false(no) as possibilities, but you want to make sure that the user selects if the option is wanted or not. So, you could not default tofalse
, So instead of having another bool to check if the the user has selected yes or no for this, you make abool?
now our
bool?
has three states null, true, false. This will allow us to check easily if the user has selected a value for it.So, to obtain the value of a nullable reference or value type you could do it by
.HasValue
(but it think performance wise will be the same as doing==null
), and to obtain the value stored in our case aVector2
simply use .Value.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the tip!