Skip to content

Commit

Permalink
com.unity.render-pipelines.core@4.2.0-preview
Browse files Browse the repository at this point in the history
## [4.2.0-preview] - 2018-11-16

### Added
- Added a define for determining if any instancing path is taken.
  • Loading branch information
Unity Technologies committed Nov 15, 2018
1 parent 4f9f203 commit a8b88ee
Show file tree
Hide file tree
Showing 24 changed files with 1,221 additions and 74 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this package will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [4.2.0-preview] - 2018-11-16

### Added
- Added a define for determining if any instancing path is taken.

## [4.1.0-preview] - 2018-10-18

### Changed
Expand Down
491 changes: 482 additions & 9 deletions Editor/CoreEditorDrawers.cs

Large diffs are not rendered by default.

167 changes: 160 additions & 7 deletions Editor/CoreEditorUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class CoreEditorUtils
{
// GUIContent cache utilities
static Dictionary<string, GUIContent> s_GUIContentCache = new Dictionary<string, GUIContent>();

public static GUIContent GetContent(string textAndTooltip)
{
if (string.IsNullOrEmpty(textAndTooltip))
Expand All @@ -38,6 +38,11 @@ public static GUIContent GetContent(string textAndTooltip)
}

// Serialization helpers
/// <summary>
/// To use with extreme caution. It not really get the property but try to find a field with similar name
/// Hence inheritance override of property is not supported.
/// Also variable rename will silently break the search.
/// </summary>
public static string FindProperty<T, TValue>(Expression<Func<T, TValue>> expr)
{
// Get the field path as a string
Expand Down Expand Up @@ -74,11 +79,15 @@ public static GUIContent GetContent(string textAndTooltip)
}

// UI Helpers

public static void DrawMultipleFields(string label, SerializedProperty[] ppts, GUIContent[] lbls)
{
DrawMultipleFields(GetContent(label), ppts, lbls);
}

public static void DrawMultipleFields(GUIContent label, SerializedProperty[] ppts, GUIContent[] lbls)
{
GUILayout.BeginHorizontal();
EditorGUILayout.PrefixLabel(GetContent(label));
EditorGUILayout.PrefixLabel(label);
GUILayout.BeginVertical();
var labelWidth = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 45;
Expand Down Expand Up @@ -112,6 +121,11 @@ public static void DrawSplitter(bool isBoxed = false)
}

public static void DrawHeader(string title)
{
DrawHeader(GetContent(title));
}

public static void DrawHeader(GUIContent title)
{
var backgroundRect = GUILayoutUtility.GetRect(1f, 17f);

Expand All @@ -136,9 +150,27 @@ public static void DrawHeader(string title)
EditorGUI.LabelField(labelRect, title, EditorStyles.boldLabel);
}

public static bool DrawHeaderFoldout(string title, bool state, bool isBoxed = false)
/// <summary> Draw a foldout header </summary>
/// <param name="title"> The title of the header </param>
/// <param name="state"> The state of the header </param>
/// <param name="isBoxed"> [optional] is the eader contained in a box style ? </param>
/// <param name="isAdvanced"> [optional] Delegate used to draw the right state of the advanced button. If null, no button drawn. </param>
/// <param name="switchAdvanced"> [optional] Callback call when advanced button clicked. Should be used to toggle its state. </param>
public static bool DrawHeaderFoldout(string title, bool state, bool isBoxed = false, Func<bool> isAdvanced = null, Action switchAdvanced = null)
{
var backgroundRect = GUILayoutUtility.GetRect(1f, 17f);
return DrawHeaderFoldout(GetContent(title), state, isBoxed, isAdvanced, switchAdvanced);
}

/// <summary> Draw a foldout header </summary>
/// <param name="title"> The title of the header </param>
/// <param name="state"> The state of the header </param>
/// <param name="isBoxed"> [optional] is the eader contained in a box style ? </param>
/// <param name="isAdvanced"> [optional] Delegate used to draw the right state of the advanced button. If null, no button drawn. </param>
/// <param name="switchAdvanced"> [optional] Callback call when advanced button clicked. Should be used to toggle its state. </param>
public static bool DrawHeaderFoldout(GUIContent title, bool state, bool isBoxed = false, Func<bool> isAdvanced = null, Action switchAdvanced = null)
{
const float height = 17f;
var backgroundRect = GUILayoutUtility.GetRect(1f, height);

var labelRect = backgroundRect;
labelRect.xMin += 16f;
Expand All @@ -148,6 +180,34 @@ public static bool DrawHeaderFoldout(string title, bool state, bool isBoxed = fa
foldoutRect.y += 1f;
foldoutRect.width = 13f;
foldoutRect.height = 13f;

var advancedRect = new Rect();
if (isAdvanced != null)
{
advancedRect = backgroundRect;
advancedRect.x += advancedRect.width - 16 - 1;
advancedRect.y -= 2;
advancedRect.height = 16;
advancedRect.width = 16;

GUIStyle styleAdvanced = new GUIStyle(GUI.skin.toggle);
styleAdvanced.normal.background = isAdvanced()
? Resources.Load<Texture2D>("Advanced_Pressed_mini")
: Resources.Load<Texture2D>("Advanced_UnPressed_mini");
styleAdvanced.onActive.background = styleAdvanced.normal.background;
styleAdvanced.onFocused.background = styleAdvanced.normal.background;
styleAdvanced.onNormal.background = styleAdvanced.normal.background;
styleAdvanced.onHover.background = styleAdvanced.normal.background;
styleAdvanced.active.background = styleAdvanced.normal.background;
styleAdvanced.focused.background = styleAdvanced.normal.background;
styleAdvanced.hover.background = styleAdvanced.normal.background;
EditorGUI.BeginChangeCheck();
GUI.Toggle(advancedRect, isAdvanced(), GUIContent.none, styleAdvanced);
if(EditorGUI.EndChangeCheck() && switchAdvanced != null)
{
switchAdvanced();
}
}

// Background rect should be full-width
backgroundRect.xMin = 0f;
Expand All @@ -172,7 +232,95 @@ public static bool DrawHeaderFoldout(string title, bool state, bool isBoxed = fa
state = GUI.Toggle(foldoutRect, state, GUIContent.none, EditorStyles.foldout);

var e = Event.current;
if (e.type == EventType.MouseDown && backgroundRect.Contains(e.mousePosition) && e.button == 0)
if (e.type == EventType.MouseDown && backgroundRect.Contains(e.mousePosition) && !advancedRect.Contains(e.mousePosition) && e.button == 0)
{
state = !state;
e.Use();
}

return state;
}

/// <summary> Draw a foldout header </summary>
/// <param name="title"> The title of the header </param>
/// <param name="state"> The state of the header </param>
/// <param name="isBoxed"> [optional] is the eader contained in a box style ? </param>
/// <param name="isAdvanced"> [optional] Delegate used to draw the right state of the advanced button. If null, no button drawn. </param>
/// <param name="switchAdvanced"> [optional] Callback call when advanced button clicked. Should be used to toggle its state. </param>
public static bool DrawSubHeaderFoldout(string title, bool state, bool isBoxed = false, Func<bool> isAdvanced = null, Action switchAdvanced = null)
{
return DrawSubHeaderFoldout(GetContent(title), state, isBoxed, isAdvanced, switchAdvanced);
}

/// <summary> Draw a foldout header </summary>
/// <param name="title"> The title of the header </param>
/// <param name="state"> The state of the header </param>
/// <param name="isBoxed"> [optional] is the eader contained in a box style ? </param>
/// <param name="isAdvanced"> [optional] Delegate used to draw the right state of the advanced button. If null, no button drawn. </param>
/// <param name="switchAdvanced"> [optional] Callback call when advanced button clicked. Should be used to toggle its state. </param>
public static bool DrawSubHeaderFoldout(GUIContent title, bool state, bool isBoxed = false, Func<bool> isAdvanced = null, Action switchAdvanced = null)
{
const float height = 17f;
var backgroundRect = GUILayoutUtility.GetRect(1f, height);

var labelRect = backgroundRect;
labelRect.xMin += 16f;
labelRect.xMax -= 20f;

var foldoutRect = backgroundRect;
foldoutRect.y += 1f;
foldoutRect.x += 15 * EditorGUI.indentLevel; //GUI do not handle indent. Handle it here
foldoutRect.width = 13f;
foldoutRect.height = 13f;

var advancedRect = new Rect();
if (isAdvanced != null)
{
advancedRect = backgroundRect;
advancedRect.x += advancedRect.width - 16 - 1;
advancedRect.y -= 2;
advancedRect.height = 16;
advancedRect.width = 16;

GUIStyle styleAdvanced = new GUIStyle(GUI.skin.toggle);
styleAdvanced.normal.background = isAdvanced()
? Resources.Load<Texture2D>("Advanced_Pressed_mini")
: Resources.Load<Texture2D>("Advanced_UnPressed_mini");
styleAdvanced.onActive.background = styleAdvanced.normal.background;
styleAdvanced.onFocused.background = styleAdvanced.normal.background;
styleAdvanced.onNormal.background = styleAdvanced.normal.background;
styleAdvanced.onHover.background = styleAdvanced.normal.background;
styleAdvanced.active.background = styleAdvanced.normal.background;
styleAdvanced.focused.background = styleAdvanced.normal.background;
styleAdvanced.hover.background = styleAdvanced.normal.background;
EditorGUI.BeginChangeCheck();
GUI.Toggle(advancedRect, isAdvanced(), GUIContent.none, styleAdvanced);
if (EditorGUI.EndChangeCheck() && switchAdvanced != null)
{
switchAdvanced();
}
}

// Background rect should be full-width
backgroundRect.xMin = 0f;
backgroundRect.width += 4f;

if (isBoxed)
{
labelRect.xMin += 5;
foldoutRect.xMin += 5;
backgroundRect.xMin = EditorGUIUtility.singleLineHeight;
backgroundRect.width -= 3;
}

// Title
EditorGUI.LabelField(labelRect, title, EditorStyles.boldLabel);

// Active checkbox
state = GUI.Toggle(foldoutRect, state, GUIContent.none, EditorStyles.foldout);

var e = Event.current;
if (e.type == EventType.MouseDown && backgroundRect.Contains(e.mousePosition) && !advancedRect.Contains(e.mousePosition) && e.button == 0)
{
state = !state;
e.Use();
Expand All @@ -182,6 +330,11 @@ public static bool DrawHeaderFoldout(string title, bool state, bool isBoxed = fa
}

public static bool DrawHeaderToggle(string title, SerializedProperty group, SerializedProperty activeField, Action<Vector2> contextAction = null)
{
return DrawHeaderToggle(GetContent(title), group, activeField, contextAction);
}

public static bool DrawHeaderToggle(GUIContent title, SerializedProperty group, SerializedProperty activeField, Action<Vector2> contextAction = null)
{
var backgroundRect = GUILayoutUtility.GetRect(1f, 17f);

Expand Down Expand Up @@ -210,7 +363,7 @@ public static bool DrawHeaderToggle(string title, SerializedProperty group, Seri

// Title
using (new EditorGUI.DisabledScope(!activeField.boolValue))
EditorGUI.LabelField(labelRect, GetContent(title), EditorStyles.boldLabel);
EditorGUI.LabelField(labelRect, title, EditorStyles.boldLabel);

// Foldout
group.serializedObject.Update();
Expand Down
68 changes: 68 additions & 0 deletions Editor/ExpandedState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using UnityEditor;

namespace UnityEditor.Experimental.Rendering
{
/// <summary>Used in editor drawer part to store the state of expendable areas.</summary>
/// <typeparam name="TState">An enum to use to describe the state.</typeparam>
/// <typeparam name="TTarget">A type given to automatically compute the key.</typeparam>
public struct ExpandedState<TState, TTarget>
where TState : struct, IConvertible
{
/// <summary>Key is automatically computed regarding the target type given</summary>
public readonly string stateKey;

/// <summary>Constructor will create the key to store in the EditorPref the state given generic type passed.</summary>
/// <param name="defaultValue">If key did not exist, it will be created with this value for initialization.</param>
public ExpandedState(TState defaultValue, string prefix = "CoreRP")
{
stateKey = string.Format("{0}:{1}:UI_State", prefix, typeof(TTarget).Name);

//register key if not already there
if (!EditorPrefs.HasKey(stateKey))
{
EditorPrefs.SetInt(stateKey, (int)(object)defaultValue);
}
}

uint expandedState { get { return (uint)EditorPrefs.GetInt(stateKey); } set { EditorPrefs.SetInt(stateKey, (int)value); } }

/// <summary>Get or set the state given the mask.</summary>
public bool this[TState mask]
{
get { return GetExpandedAreas(mask); }
set { SetExpandedAreas(mask, value); }
}

/// <summary>Accessor to the expended state of this specific mask.</summary>
public bool GetExpandedAreas(TState mask)
{
// note on cast:
// - to object always ok
// - to int ok because of IConvertible. Cannot directly go to uint
return (expandedState & (uint)(int)(object)mask) > 0;
}

/// <summary>Setter to the expended state.</summary>
public void SetExpandedAreas(TState mask, bool value)
{
uint state = expandedState;
// note on cast:
// - to object always ok
// - to int ok because of IConvertible. Cannot directly go to uint
uint workMask = (uint)(int)(object)mask;

if (value)
{
state |= workMask;
}
else
{
workMask = ~workMask;
state &= workMask;
}

expandedState = state;
}
}
}
11 changes: 11 additions & 0 deletions Editor/ExpandedState.cs.meta

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

22 changes: 21 additions & 1 deletion Editor/PropertyFetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ public SerializedProperty Find(string str)
{
return obj.FindProperty(str);
}


/// <summary>
/// To use with extreme caution. It not really get the property but try to find a field with similar name
/// Hence inheritance override of property is not supported.
/// Also variable rename will silently break the search.
/// </summary>
public SerializedProperty Find<TValue>(Expression<Func<T, TValue>> expr)
{
string path = CoreEditorUtils.FindProperty(expr);
Expand Down Expand Up @@ -46,6 +51,11 @@ public SerializedProperty Find(string str)
return obj.FindPropertyRelative(str);
}

/// <summary>
/// To use with extreme caution. It not really get the property but try to find a field with similar name
/// Hence inheritance override of property is not supported.
/// Also variable rename will silently break the search.
/// </summary>
public SerializedProperty Find<TValue>(Expression<Func<T, TValue>> expr)
{
string path = CoreEditorUtils.FindProperty(expr);
Expand All @@ -60,12 +70,22 @@ public void Dispose()

public static class PropertyFetcherExtensions
{
/// <summary>
/// To use with extreme caution. It not really get the property but try to find a field with similar name
/// Hence inheritance override of property is not supported.
/// Also variable rename will silently break the search.
/// </summary>
public static SerializedProperty Find<TSource, TValue>(this SerializedObject obj, Expression<Func<TSource, TValue>> expr)
{
var path = CoreEditorUtils.FindProperty(expr);
return obj.FindProperty(path);
}

/// <summary>
/// To use with extreme caution. It not really get the property but try to find a field with similar name
/// Hence inheritance override of property is not supported.
/// Also variable rename will silently break the search.
/// </summary>
public static SerializedProperty Find<TSource, TValue>(this SerializedProperty obj, Expression<Func<TSource, TValue>> expr)
{
var path = CoreEditorUtils.FindProperty(expr);
Expand Down
8 changes: 8 additions & 0 deletions Editor/Resources.meta

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

Binary file added Editor/Resources/Advanced_Pressed_mini.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit a8b88ee

Please sign in to comment.