Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.render-pipelines.core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ The version number for this package has increased due to a version update of a r
### Fixed
- Fixed black pixel issue in AMD FidelityFX RCAS implementation
- Fixed a critical issue on android devices & lens flares. Accidentally creating a 16 bit texture was causing gpus not supporting them to fail.
- Fixed serialization of DebugStateFlags, the internal Enum was not being serialized.

## [12.0.0] - 2021-01-11

Expand Down
30 changes: 27 additions & 3 deletions com.unity.render-pipelines.core/Editor/Debugging/DebugState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ public override int GetHashCode()
{
int hash = 13;
hash = hash * 23 + m_QueryPath.GetHashCode();
if (m_Value != null)
hash = hash * 23 + m_Value.GetHashCode();
hash = hash * 23 + value.GetHashCode();
return hash;
}
}
Expand Down Expand Up @@ -145,7 +144,32 @@ public sealed class DebugStateInt : DebugState<int> { }
/// Flags Debug State.
/// </summary>
[Serializable, DebugState(typeof(DebugUI.BitField))]
public sealed class DebugStateFlags : DebugState<Enum> { }
public sealed class DebugStateFlags : DebugState<Enum>
{
[SerializeField]
private SerializableEnum m_SerializableEnum;

/// <summary>
/// Value of the Debug Item
/// </summary>
public override Enum value
{
get => m_SerializableEnum?.value ?? default;
set => m_SerializableEnum.value = value;
}

/// <summary>
/// Set the value of the Debug Item.
/// </summary>
/// <param name="value">Input value.</param>
/// <param name="field">Debug Item field.</param>
public override void SetValue(object value, DebugUI.IValueField field)
{
if (m_SerializableEnum == null)
m_SerializableEnum = new SerializableEnum((field as DebugUI.BitField).enumType);
base.SetValue(value, field);
}
}

/// <summary>
/// Unsigned Integer Debug State.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,7 @@ public void ApplyStates(bool forceApplyAll = false)

void ApplyState(string queryPath, DebugState state)
{
if (state == null ||
state.GetValue() == null ||
!(DebugManager.instance.GetItem(queryPath) is DebugUI.IValueField widget))
if (!(DebugManager.instance.GetItem(queryPath) is DebugUI.IValueField widget))
return;

widget.SetValue(state.GetValue());
Expand Down
46 changes: 46 additions & 0 deletions com.unity.render-pipelines.core/Runtime/Common/SerializableEnum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
namespace UnityEngine.Rendering
{
using System;
using UnityEngine;

/// <summary>
/// Class to serizalize Enum as string and recover it's state
/// </summary>
[Serializable]
public class SerializableEnum
{
[SerializeField]
private string m_EnumValueAsString;

[SerializeField]
private Type m_EnumType;

/// <summary>
/// Value of enum
/// </summary>
public Enum value
{
get
{
if (Enum.TryParse(m_EnumType, m_EnumValueAsString, out object result))
return (Enum)result;

return default(Enum);
}
set
{
m_EnumValueAsString = value.ToString();
}
}

/// <summary>
/// Construct an enum to be serialized with a type
/// </summary>
/// <param name="enumType">The underliying type of the enum</param>
public SerializableEnum(Type enumType)
{
m_EnumType = enumType;
m_EnumValueAsString = Enum.GetNames(enumType)[0];
}
}
}

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