Skip to content

Commit

Permalink
Convert ISetTooltipVisibility to IProvides/UsesSetTooltipVisibility
Browse files Browse the repository at this point in the history
  • Loading branch information
mtschoen committed Jun 10, 2019
1 parent 910daf9 commit 0f711f0
Show file tree
Hide file tree
Showing 29 changed files with 183 additions and 71 deletions.
1 change: 1 addition & 0 deletions Editor/TooltipsEditor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Unity.Labs.EditorXR.Interfaces;
using Unity.Labs.Utils;
using UnityEngine;

Expand Down
5 changes: 3 additions & 2 deletions Editor/Unity.Labs.EditorXR.Editor.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"references": [
"Unity.Labs.EditorXR",
"Unity.TextMeshPro",
"Unity.Labs.Utils"
"Unity.Labs.Utils",
"Unity.Labs.EditorXR.Interfaces"
],
"optionalUnityReferences": [],
"includePlatforms": [
Expand All @@ -15,4 +16,4 @@
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": []
}
}
8 changes: 8 additions & 0 deletions Interfaces/Capability.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
@@ -1,6 +1,6 @@
using UnityEngine;

namespace UnityEditor.Experimental.EditorVR
namespace Unity.Labs.EditorXR.Interfaces
{
/// <summary>
/// Decorates classes that provide positioning information for tooltips
Expand Down
8 changes: 8 additions & 0 deletions Interfaces/Entity.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
@@ -1,4 +1,4 @@
namespace UnityEditor.Experimental.EditorVR
namespace Unity.Labs.EditorXR.Interfaces
{
/// <summary>
/// Decorates classes which can specify tool tip information
Expand Down
File renamed without changes.
32 changes: 32 additions & 0 deletions Interfaces/Providers/IProvidesSetTooltipVisibility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using Unity.Labs.ModuleLoader;

namespace Unity.Labs.EditorXR.Interfaces
{
/// <summary>
/// Provide access to tooltip visibility
/// </summary>
public interface IProvidesSetTooltipVisibility : IFunctionalityProvider
{
/// <summary>
/// Show a Tooltip. Calling ShowTooltip on an ITooltip that was just shown will update its placement and timing
/// </summary>
/// <param name="tooltip">The tooltip to show</param>
/// <param name="persistent">Whether the tooltip should stay visible regardless of raycasts</param>
/// <param name="duration">If the tooltip is shown persistently, and duration is less than 0, hide after the
/// duration, in seconds. If duration greater than 0, placement is updated but timing is not affected. If
/// duration is exactly 0, tooltip stays visible until explicitly hidden</param>
/// <param name="placement">(Optional) The ITooltipPlacement object used to place the tooltip. If no placement
/// is specified, we assume the ITooltip is a component and use its own Transform</param>
/// <param name="becameVisible">(Optional) Called as soon as the tooltip becomes visible</param>
void ShowTooltip(ITooltip tooltip, bool persistent = false, float duration = 0f,
ITooltipPlacement placement = null, Action becameVisible = null);

/// <summary>
/// Hide the given Tooltip
/// </summary>
/// <param name="tooltip">The tooltip to hide</param>
/// <param name="persistent">Whether to hide the tooltip if it was shown with the persistent argument set to true</param>
void HideTooltip(ITooltip tooltip, bool persistent = false);
}
}

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
@@ -1,47 +1,48 @@
using System;

namespace UnityEditor.Experimental.EditorVR
{
/// <summary>
/// Provides access to the ability to show or hide a Tooltip
/// </summary>
public interface ISetTooltipVisibility
{
}

public static class ISetTooltipVisibilityMethods
{
internal delegate void ShowTooltipDelegate(ITooltip tooltip, bool persistent = false, float duration = 0f,
ITooltipPlacement placement = null, Action becameVisible = null);

internal static ShowTooltipDelegate showTooltip { get; set; }
internal static Action<ITooltip, bool> hideTooltip { get; set; }

/// <summary>
/// Show a Tooltip. Calling ShowTooltip on an ITooltip that was just shown will update its placement and timing
/// </summary>
/// <param name="tooltip">The tooltip to show</param>
/// <param name="persistent">Whether the tooltip should stay visible regardless of raycasts</param>
/// <param name="duration">If the tooltip is shown persistently, and duration is less than 0, hide after the
/// duration, in seconds. If duration greater than 0, placement is updated but timing is not affected. If
/// duration is exactly 0, tooltip stays visible until explicitly hidden</param>
/// <param name="placement">(Optional) The ITooltipPlacement object used to place the tooltip. If no placement
/// is specified, we assume the ITooltip is a component and use its own Transform</param>
/// <param name="becameVisible">(Optional) Called as soon as the tooltip becomes visible</param>
public static void ShowTooltip(this ISetTooltipVisibility obj, ITooltip tooltip, bool persistent = false,
float duration = 0f, ITooltipPlacement placement = null, Action becameVisible = null)
{
showTooltip(tooltip, persistent, duration, placement, becameVisible);
}

/// <summary>
/// Hide the given Tooltip
/// </summary>
/// <param name="tooltip">The tooltip to hide</param>
/// <param name="persistent">Whether to hide the tooltip if it was shown with the persistent argument set to true</param>
public static void HideTooltip(this ISetTooltipVisibility obj, ITooltip tooltip, bool persistent = false)
{
hideTooltip(tooltip, persistent);
}
}
}
using System;
using Unity.Labs.ModuleLoader;

namespace Unity.Labs.EditorXR.Interfaces
{
/// <summary>
/// Gives decorated class control of tooltip visibility
/// </summary>
public interface IUsesSetTooltipVisibility : IFunctionalitySubscriber<IProvidesSetTooltipVisibility>
{
}

public static class UsesSetTooltipVisibilityMethods
{
/// <summary>
/// Show a Tooltip. Calling ShowTooltip on an ITooltip that was just shown will update its placement and timing
/// </summary>
/// <param name="user">The functionality user</param>
/// <param name="tooltip">The tooltip to show</param>
/// <param name="persistent">Whether the tooltip should stay visible regardless of raycasts</param>
/// <param name="duration">If the tooltip is shown persistently, and duration is less than 0, hide after the
/// duration, in seconds. If duration greater than 0, placement is updated but timing is not affected. If
/// duration is exactly 0, tooltip stays visible until explicitly hidden</param>
/// <param name="placement">(Optional) The ITooltipPlacement object used to place the tooltip. If no placement
/// is specified, we assume the ITooltip is a component and use its own Transform</param>
/// <param name="becameVisible">(Optional) Called as soon as the tooltip becomes visible</param>
public static void ShowTooltip(this IUsesSetTooltipVisibility user, ITooltip tooltip, bool persistent = false,
float duration = 0f, ITooltipPlacement placement = null, Action becameVisible = null)
{
#if !FI_AUTOFILL
user.provider.ShowTooltip(tooltip, persistent, duration, placement, becameVisible);
#endif
}

/// <summary>
/// Hide the given Tooltip
/// </summary>
/// <param name="user">The functionality user</param>
/// <param name="tooltip">The tooltip to hide</param>
/// <param name="persistent">Whether to hide the tooltip if it was shown with the persistent argument set to true</param>
public static void HideTooltip(this IUsesSetTooltipVisibility user, ITooltip tooltip, bool persistent = false)
{
#if !FI_AUTOFILL
user.provider.ShowTooltip(tooltip, persistent);
#endif
}
}
}
12 changes: 12 additions & 0 deletions Interfaces/Subscribers/IUsesSetTooltipVisibility.cs.meta

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

1 change: 1 addition & 0 deletions Runtime/Menus/MainMenu/MainMenu.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Unity.Labs.EditorXR.Interfaces;
using Unity.Labs.Utils;
using UnityEditor.Experimental.EditorVR.Core;
using UnityEditor.Experimental.EditorVR.Proxies;
Expand Down
1 change: 1 addition & 0 deletions Runtime/Menus/MainMenu/Scripts/MainMenuButton.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Unity.Labs.EditorXR.Interfaces;
using UnityEditor.Experimental.EditorVR.Modules;
using UnityEngine;
using UnityEngine.Events;
Expand Down
1 change: 1 addition & 0 deletions Runtime/Menus/MainMenu/Scripts/MainMenuItemAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Unity.Labs.EditorXR.Interfaces;

namespace UnityEditor.Experimental.EditorVR
{
Expand Down
8 changes: 7 additions & 1 deletion Runtime/Menus/RadialMenu/Scripts/RadialMenuSlot.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections;
using Unity.Labs.EditorXR.Interfaces;
using Unity.Labs.ModuleLoader;
using Unity.Labs.Utils;
using UnityEditor.Experimental.EditorVR.Extensions;
using UnityEditor.Experimental.EditorVR.Helpers;
Expand All @@ -9,7 +11,7 @@

namespace UnityEditor.Experimental.EditorVR.Menus
{
sealed class RadialMenuSlot : MonoBehaviour, ISetTooltipVisibility, ITooltip, ITooltipPlacement, IRayEnterHandler, IRayExitHandler
sealed class RadialMenuSlot : MonoBehaviour, IUsesSetTooltipVisibility, ITooltip, ITooltipPlacement, IRayEnterHandler, IRayExitHandler
{
static readonly Vector3 k_HiddenLocalScale = new Vector3(1f, 0f, 1f);
const float k_IconHighlightedLocalYOffset = 0.006f;
Expand Down Expand Up @@ -237,6 +239,10 @@ public Sprite icon

public event Action hovered;

#if !FI_AUTOFILL
IProvidesSetTooltipVisibility IFunctionalitySubscriber<IProvidesSetTooltipVisibility>.provider { get; set; }
#endif

void Awake()
{
m_MaskMaterial = MaterialUtils.GetMaterialClone(m_MaskRenderer);
Expand Down
1 change: 1 addition & 0 deletions Runtime/Menus/RadialMenu/Scripts/RadialMenuUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Unity.Labs.EditorXR.Interfaces;
using UnityEditor.Experimental.EditorVR.Extensions;
using UnityEditor.Experimental.EditorVR.Utilities;
using UnityEngine;
Expand Down
8 changes: 7 additions & 1 deletion Runtime/Menus/ToolsMenu/ToolsMenuButton/ToolsMenuButton.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections;
using System.Text;
using Unity.Labs.EditorXR.Interfaces;
using Unity.Labs.ModuleLoader;
using Unity.Labs.Utils;
using UnityEditor.Experimental.EditorVR.Extensions;
using UnityEditor.Experimental.EditorVR.Helpers;
Expand All @@ -11,7 +13,7 @@

namespace UnityEditor.Experimental.EditorVR.Menus
{
sealed class ToolsMenuButton : MonoBehaviour, IToolsMenuButton, ITooltip, ITooltipPlacement, ISetTooltipVisibility
sealed class ToolsMenuButton : MonoBehaviour, IToolsMenuButton, ITooltip, ITooltipPlacement, IUsesSetTooltipVisibility
{
static Color s_FrameOpaqueColor;

Expand Down Expand Up @@ -432,6 +434,10 @@ public Vector3 primaryUIContentContainerLocalScale

public event Action hovered;

#if !FI_AUTOFILL
IProvidesSetTooltipVisibility IFunctionalitySubscriber<IProvidesSetTooltipVisibility>.provider { get; set; }
#endif

void Awake()
{
m_OriginalLocalPosition = transform.localPosition;
Expand Down
7 changes: 5 additions & 2 deletions Runtime/Scripts/Actions/ActionMenuItemAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
namespace UnityEditor.Experimental.EditorVR
using System;
using Unity.Labs.EditorXR.Interfaces;

namespace UnityEditor.Experimental.EditorVR
{
/// <summary>
/// Attribute used to tag Action classes in order to be added to VR menus
/// </summary>
public class ActionMenuItemAttribute : System.Attribute, ITooltip
public class ActionMenuItemAttribute : Attribute, ITooltip
{
internal const string DefaultActionSectionName = "DefaultActions";
internal string name;
Expand Down
4 changes: 3 additions & 1 deletion Runtime/Scripts/Data/ActionMenuData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace UnityEditor.Experimental.EditorVR
using Unity.Labs.EditorXR.Interfaces;

namespace UnityEditor.Experimental.EditorVR
{
/// <summary>
/// Used for passing action data for menu purposes
Expand Down
3 changes: 2 additions & 1 deletion Runtime/Scripts/Modules/TooltipModule/Tooltip.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEngine;
using Unity.Labs.EditorXR.Interfaces;
using UnityEngine;

namespace UnityEditor.Experimental.EditorVR.UI
{
Expand Down
22 changes: 16 additions & 6 deletions Runtime/Scripts/Modules/TooltipModule/TooltipModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace UnityEditor.Experimental.EditorVR.Modules
{
sealed class TooltipModule : ScriptableSettings<TooltipModule>, IInitializableModule, IModuleBehaviorCallbacks,
IModuleDependency<MultipleRayInputModule>, IUsesViewerScale
IModuleDependency<MultipleRayInputModule>, IUsesViewerScale, IProvidesSetTooltipVisibility
{
class TooltipData
{
Expand Down Expand Up @@ -101,9 +101,6 @@ public void ConnectDependency(MultipleRayInputModule dependency)
public void LoadModule()
{
m_TooltipScale = m_TooltipPrefab.transform.localScale;

ISetTooltipVisibilityMethods.showTooltip = ShowTooltip;
ISetTooltipVisibilityMethods.hideTooltip = HideTooltip;
}

public void UnloadModule() { }
Expand Down Expand Up @@ -313,7 +310,7 @@ void OnRayExited(GameObject gameObject, RayEventData eventData)
}
}

void ShowTooltip(ITooltip tooltip, bool persistent = false, float duration = 0f, ITooltipPlacement placementOverride = null, Action becameVisible = null)
public void ShowTooltip(ITooltip tooltip, bool persistent = false, float duration = 0f, ITooltipPlacement placementOverride = null, Action becameVisible = null)
{
if (!IsValidTooltip(tooltip))
return;
Expand Down Expand Up @@ -394,7 +391,7 @@ static bool IsValidTooltip(ITooltip tooltip)
return !string.IsNullOrEmpty(tooltip.tooltipText);
}

void HideTooltip(ITooltip tooltip, bool persistent = false)
public void HideTooltip(ITooltip tooltip, bool persistent = false)
{
TooltipData tooltipData;
if (m_Tooltips.TryGetValue(tooltip, out tooltipData))
Expand Down Expand Up @@ -483,5 +480,18 @@ public void OnBehaviorStart() { }
public void OnBehaviorDisable() { }

public void OnBehaviorDestroy() { }

public void LoadProvider() { }

public void ConnectSubscriber(object obj)
{
#if !FI_AUTOFILL
var visibilitySubscriber = obj as IFunctionalitySubscriber<IProvidesSetTooltipVisibility>;
if (visibilitySubscriber != null)
visibilitySubscriber.provider = this;
#endif
}

public void UnloadProvider() { }
}
}
3 changes: 2 additions & 1 deletion Runtime/Scripts/Proxies/AffordanceTooltip.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEngine;
using Unity.Labs.EditorXR.Interfaces;
using UnityEngine;

namespace UnityEditor.Experimental.EditorVR.Proxies
{
Expand Down
3 changes: 2 additions & 1 deletion Runtime/Scripts/Proxies/AffordanceTooltipPlacement.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Unity.Labs.Utils.GUI;
using Unity.Labs.EditorXR.Interfaces;
using Unity.Labs.Utils.GUI;
using UnityEngine;

namespace UnityEditor.Experimental.EditorVR.Proxies
Expand Down
Loading

0 comments on commit 0f711f0

Please sign in to comment.