Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
Fixed some issues with the MixedRealityServiceProfileInspector (#478)
Browse files Browse the repository at this point in the history
* Fixed the parent profile property not correctly being set

Fixed the type reference property drawer try repair buttons to render correctly

* Updated element to display when a configuration doesn't need a profile
  • Loading branch information
StephenHodgson authored Mar 30, 2020
1 parent eb4ad2d commit 60307f4
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 7 deletions.
12 changes: 12 additions & 0 deletions Inspectors/Profiles/BaseMixedRealityProfileInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using UnityEngine;
using XRTK.Definitions;
using XRTK.Inspectors.Extensions;
using XRTK.Inspectors.Utilities;
using XRTK.Services;
using XRTK.Utilities.Async;

Expand Down Expand Up @@ -35,6 +36,17 @@ protected virtual void OnEnable()
ThisProfile = profile;
}

protected void RenderHeader()
{
MixedRealityInspectorUtility.RenderMixedRealityToolkitLogo();

if (ThisProfile.ParentProfile != null &&
GUILayout.Button("Back to parent profile"))
{
Selection.activeObject = ThisProfile.ParentProfile;
}
}

/// <summary>
/// Renders a <see cref="BaseMixedRealityProfile"/>.
/// </summary>
Expand Down
40 changes: 37 additions & 3 deletions Inspectors/Profiles/MixedRealityServiceProviderProfileInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace XRTK.Inspectors.Profiles
[CustomEditor(typeof(BaseMixedRealityServiceProfile<>))]
public class MixedRealityServiceProfileInspector : BaseMixedRealityProfileInspector
{
private readonly GUIContent ProfileContent = new GUIContent("Profile", "The configuration profile for this service.");
private ReorderableList configurationList;
private int currentlySelectedConfigurationOption;

Expand Down Expand Up @@ -120,6 +121,8 @@ private void DrawConfigurationOptionElement(Rect rect, int index, bool isActive,

foreach (var parameterInfo in parameters)
{
if (parameterInfo.ParameterType.IsAbstract) { continue; }

if (parameterInfo.ParameterType.IsSubclassOf(typeof(BaseMixedRealityProfile)))
{
profileType = parameterInfo.ParameterType;
Expand All @@ -141,7 +144,7 @@ private void DrawConfigurationOptionElement(Rect rect, int index, bool isActive,

if (profileType != null)
{
EditorGUI.LabelField(profileLabelRect, "Profile");
EditorGUI.LabelField(profileLabelRect, ProfileContent);
var isNullProfile = configurationProfileProperty.objectReferenceValue == null;

var buttonWidth = isNullProfile ? 20f : 42f;
Expand All @@ -150,7 +153,26 @@ private void DrawConfigurationOptionElement(Rect rect, int index, bool isActive,
var profileObjectRect = new Rect(profilePosition, profileHeight, profileObjectWidth - scrollOffset, EditorGUIUtility.singleLineHeight);
var buttonRect = new Rect(profilePosition + profileObjectWidth - scrollOffset, profileHeight, buttonWidth, EditorGUIUtility.singleLineHeight);

configurationProfileProperty.objectReferenceValue = EditorGUI.ObjectField(profileObjectRect, configurationProfileProperty.objectReferenceValue, profileType, false);
var newProfileObjectReference = EditorGUI.ObjectField(profileObjectRect, configurationProfileProperty.objectReferenceValue, profileType, false);

if (newProfileObjectReference is BaseMixedRealityProfile newProfile)
{
var newProfileType = newProfile.GetType();
if (newProfileType == profileType ||
newProfileType.IsSubclassOf(profileType))
{
configurationProfileProperty.objectReferenceValue = newProfileObjectReference;
}
else
{
Debug.LogError($"{newProfileObjectReference.name} does not derive from {profileType.Name}!");
}
}
else if (newProfileObjectReference is null)
{
configurationProfileProperty.objectReferenceValue = null;
}

update = GUI.Button(buttonRect, isNullProfile ? NewProfileContent : CloneProfileContent);

if (update)
Expand All @@ -167,7 +189,19 @@ private void DrawConfigurationOptionElement(Rect rect, int index, bool isActive,
}
else
{
EditorGUI.PropertyField(profileRect, configurationProfileProperty);
EditorGUI.LabelField(profileRect, "No Configuration Profile needed");
}

if (configurationProfileProperty.objectReferenceValue != null)
{
var renderedProfile = configurationProfileProperty.objectReferenceValue as BaseMixedRealityProfile;
Debug.Assert(renderedProfile != null);

if (renderedProfile.ParentProfile == null ||
renderedProfile.ParentProfile != ThisProfile)
{
renderedProfile.ParentProfile = ThisProfile;
}
}

if (update ||
Expand Down
12 changes: 8 additions & 4 deletions Inspectors/PropertyDrawers/TypeReferencePropertyDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class TypeReferencePropertyDrawer : PropertyDrawer
private static readonly Dictionary<string, Type> TypeMap = new Dictionary<string, Type>();
private static readonly int ControlHint = typeof(TypeReferencePropertyDrawer).GetHashCode();
private static readonly GUIContent TempContent = new GUIContent();
private static readonly GUIContent RepairContent = new GUIContent("Repair", "Try to repair the reference");
private static readonly Color EnabledColor = Color.white;
private static readonly Color DisabledColor = Color.Lerp(Color.white, Color.clear, 0.5f);

Expand Down Expand Up @@ -287,15 +288,18 @@ private static void DrawTypeSelectionControl(Rect position, SerializedProperty s
}
else
{
const float leftPadding = 8f;
const float iconSize = 24f;
const float buttonWidth = 40f;
var errorContent = EditorGUIUtility.IconContent("d_console.erroricon.sml");
GUI.Label(new Rect(position.width, position.y, position.width, position.height), errorContent);
GUI.Label(new Rect(EditorGUIUtility.currentViewWidth - iconSize - leftPadding, position.y, iconSize, iconSize), errorContent);

var dropdownPosition = new Rect(position.x, position.y, position.width - 90, position.height);
var buttonPosition = new Rect(position.width - 75, position.y, 75, position.height);
var dropdownPosition = new Rect(position.x, position.y, position.width - buttonWidth - 28f, position.height);
var buttonPosition = new Rect(EditorGUIUtility.currentViewWidth - buttonWidth - leftPadding - iconSize, position.y, buttonWidth, position.height);

DrawTypeSelectionControl(dropdownPosition, label, ref reference, filter);

if (GUI.Button(buttonPosition, "Try Repair", EditorStyles.miniButton))
if (GUI.Button(buttonPosition, RepairContent, EditorStyles.miniButton))
{
TypeSearch(referenceProperty, ref reference, filter, true);
}
Expand Down

0 comments on commit 60307f4

Please sign in to comment.