Skip to content

Commit

Permalink
Move some codepaths away from MixedRealityToolkitFiles (#10956)
Browse files Browse the repository at this point in the history
* Update test icon

* Formatting

* Move some codepaths away from MixedRealityToolkitFiles

* Update ControllerPopupWindow.cs
  • Loading branch information
keveleigh authored Aug 31, 2022
1 parent f5c599f commit 7ebc9b3
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,9 @@ public virtual BaseMixedRealityProfile DefaultProfile
return AssetDatabase.LoadAssetAtPath<BaseMixedRealityProfile>(System.IO.Path.Combine(folder, DefaultProfilePath));
}
}
else
else if (EditorProjectUtilities.FindRelativeDirectory(PackageFolder, out string folder))
{
string folder;
if (EditorProjectUtilities.FindRelativeDirectory(PackageFolder, out folder))
{
return AssetDatabase.LoadAssetAtPath<BaseMixedRealityProfile>(System.IO.Path.Combine(folder, DefaultProfilePath));
}
return AssetDatabase.LoadAssetAtPath<BaseMixedRealityProfile>(System.IO.Path.Combine(folder, DefaultProfilePath));
}

// If we get here, there was an issue finding the profile.
Expand Down
24 changes: 18 additions & 6 deletions Assets/MRTK/Core/Definitions/Devices/ControllerMappingLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.MixedReality.Toolkit.Utilities.Editor;
using System;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
#endif
Expand Down Expand Up @@ -255,10 +256,8 @@ public static Texture2D GetControllerTextureScaled(Type controllerType, Handedne

private static Texture2D GetControllerTextureCached(Type controllerType, Handedness handedness, string suffix)
{
Texture2D texture;

var key = new Tuple<Type, Handedness, string>(controllerType, handedness, suffix);
if (cachedTextures.TryGetValue(key, out texture))
if (cachedTextures.TryGetValue(key, out Texture2D texture))
{
return texture;
}
Expand Down Expand Up @@ -303,10 +302,23 @@ private static Texture2D GetControllerTextureInternal(string relativeTexturePath

string themeSuffix = EditorGUIUtility.isProSkin ? "_white" : "_black";

string fullTexturePath = MixedRealityToolkitFiles.MapRelativeFilePath(MixedRealityToolkitModuleType.StandardAssets, $"{relativeTexturePath}{handednessSuffix}{themeSuffix}{suffix}.png");
return (Texture2D)AssetDatabase.LoadAssetAtPath(fullTexturePath, typeof(Texture2D));
string textureName = $"{Path.GetFileName(relativeTexturePath)}{handednessSuffix}{themeSuffix}{suffix}";
string[] textureGuids = AssetDatabase.FindAssets(textureName);
string texturePath = string.Empty;
foreach (string guid in textureGuids)
{
string tempPath = AssetDatabase.GUIDToAssetPath(guid);
// Ensure the path we're looking at contains the exact file name we're looking for
if (tempPath.Contains(textureName + ".png"))
{
texturePath = tempPath;
break;
}
}

return (Texture2D)AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D));
}

#endif // UNITY_EDITOR
}
}
}
29 changes: 22 additions & 7 deletions Assets/MRTK/Core/Definitions/Utilities/ArticulatedHandPose.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using UnityEngine;

#if UNITY_EDITOR
using Microsoft.MixedReality.Toolkit.Utilities.Editor;
using UnityEditor;
#endif

namespace Microsoft.MixedReality.Toolkit.Utilities
Expand Down Expand Up @@ -237,19 +237,34 @@ public static ArticulatedHandPose GetGesturePose(GestureId gesture)
public static void LoadGesturePoses()
{
string[] gestureNames = Enum.GetNames(typeof(GestureId));
string basePath = Path.Combine("InputSimulation", "ArticulatedHandPoses");
for (int i = 0; i < gestureNames.Length; ++i)
{
string relPath = Path.Combine(basePath, String.Format("ArticulatedHandPose_{0}.json", gestureNames[i]));
string absPath = MixedRealityToolkitFiles.MapRelativeFilePath(MixedRealityToolkitModuleType.Services, relPath);
LoadGesturePose((GestureId)i, absPath);
string gestureFileName = string.Format("ArticulatedHandPose_{0}", gestureNames[i]);
string[] gestureGuids = AssetDatabase.FindAssets(gestureFileName);
string gesturePath = string.Empty;
foreach (string guid in gestureGuids)
{
string tempPath = AssetDatabase.GUIDToAssetPath(guid);
if (tempPath.Contains("InputSimulation")
&& tempPath.Contains("ArticulatedHandPoses")
&& tempPath.Contains(gestureFileName + ".json"))
{
gesturePath = tempPath;
break;
}
}

if (!string.IsNullOrWhiteSpace(gesturePath))
{
LoadGesturePose((GestureId)i, gesturePath);
}
}
}

[Obsolete("Use SimulatedArticulatedHandPoses class or other custom class")]
private static ArticulatedHandPose LoadGesturePose(GestureId gesture, string filePath)
{
if (!string.IsNullOrEmpty(filePath))
if (!string.IsNullOrWhiteSpace(filePath))
{
var pose = new ArticulatedHandPose();
pose.FromJson(File.ReadAllText(filePath));
Expand Down Expand Up @@ -350,4 +365,4 @@ public void FromJson(string json)
dict.ToJointPoses(localJointPoses);
}
}
}
}
19 changes: 10 additions & 9 deletions Assets/MRTK/Core/Inspectors/ControllerPopupWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ namespace Microsoft.MixedReality.Toolkit.Editor
{
public class ControllerPopupWindow : EditorWindow
{
private const string EditorWindowOptionsPath = "Inspectors/Data/EditorWindowOptions.json";
// Inspectors/Data/EditorWindowOptions.json
private const string EditorWindowOptionsGuid = "28091d5ea9b5739419a221a06fa1ec89";
private const float InputActionLabelWidth = 128f;

/// <summary>
/// Used to enable editing the input axis label positions on controllers
/// Used to enable editing the input axis label positions on controllers.
/// </summary>
private static readonly bool EnableWysiwyg = false;

Expand Down Expand Up @@ -188,12 +189,12 @@ private void OnFocus()
}

/// <summary>
/// Displays the controller mapping window for the specified controller mapping
/// Displays the controller mapping window for the specified controller mapping.
/// </summary>
/// <param name="controllerMapping"> The controller mapping being modified</param>
/// <param name="interactionsList"> The underlying serialized property being modified</param>
/// <param name="handedness"> The handedness of the controller </param>
/// <param name="mappedControllers"> The list of controller types affected by this mapping</param>
/// <param name="controllerMapping">The controller mapping being modified.</param>
/// <param name="interactionsList">The underlying serialized property being modified.</param>
/// <param name="handedness">The handedness of the controller.</param>
/// <param name="mappedControllers">The list of controller types affected by this mapping.</param>
public static void Show(MixedRealityControllerMapping controllerMapping, SerializedProperty interactionsList, Handedness handedness = Handedness.None, List<string> mappedControllers = null)
{
if (window != null)
Expand Down Expand Up @@ -262,7 +263,7 @@ public static void Show(MixedRealityControllerMapping controllerMapping, Seriali
}

/// <summary>
/// Use this to repaint the popup window
/// Use this to repaint the pop-up window.
/// </summary>
public static void RepaintWindow()
{
Expand Down Expand Up @@ -786,7 +787,7 @@ private static void RenderAxisPopup(SerializedProperty axisCode, float customLab

private static string ResolveEditorWindowOptionsPath()
{
return MixedRealityToolkitFiles.MapRelativeFilePathToAbsolutePath(EditorWindowOptionsPath);
return Path.GetFullPath(AssetDatabase.GUIDToAssetPath(EditorWindowOptionsGuid));
}
}
}
3 changes: 1 addition & 2 deletions Assets/MRTK/Core/Utilities/Editor/EditorProjectUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ public static bool FindRelativeDirectory(string packageDirectory, out string pat
/// </param>
internal static bool FindRelativeDirectory(string directoryPathToSearch, string directoryName, out string path)
{
string absolutePath;
if (FindDirectory(directoryPathToSearch, directoryName, out absolutePath))
if (FindDirectory(directoryPathToSearch, directoryName, out string absolutePath))
{
path = MixedRealityToolkitFiles.GetAssetDatabasePath(absolutePath);
return true;
Expand Down

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

14 changes: 3 additions & 11 deletions Assets/MRTK/Tests/TestUtilities/TestUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
using UnityEngine;

#if UNITY_EDITOR
using Microsoft.MixedReality.Toolkit.Utilities.Editor;
using Microsoft.MixedReality.Toolkit.Editor;
using Microsoft.MixedReality.Toolkit.Utilities.Editor;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -416,16 +416,8 @@ public static void AssertGreaterOrEqual(float observed, float expected, string m
[MenuItem("Mixed Reality/Toolkit/Utilities/Update/Icons/Tests")]
private static void UpdateTestScriptIcons()
{
Texture2D icon = null;

foreach (string iconPath in MixedRealityToolkitFiles.GetFiles(MixedRealityToolkitModuleType.StandardAssets, "Icons"))
{
if (iconPath.EndsWith("test_icon.png"))
{
icon = AssetDatabase.LoadAssetAtPath<Texture2D>(iconPath);
break;
}
}
// test_icon.png
Texture2D icon = AssetDatabase.LoadAssetAtPath<Texture2D>(AssetDatabase.GUIDToAssetPath("731058d908be67544b92b0341f29d906"));

if (icon == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using Microsoft.CSharp;
using Microsoft.MixedReality.Toolkit.Utilities;
using Microsoft.MixedReality.Toolkit.Utilities.Editor;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -278,41 +277,29 @@ public string SampleCode
#region paths

private string ExtensionsFolder => Path.Combine("Assets", DefaultGeneratedFolderName, DefaultExtensionsFolderName);
private string ServiceTemplatePath => MixedRealityToolkitFiles.MapRelativeFilePath(MixedRealityToolkitModuleType.Tools, "ExtensionServiceCreator/Templates/ExtensionScriptTemplate.txt");
private string ServiceConstructorTemplatePath => MixedRealityToolkitFiles.MapRelativeFilePath(MixedRealityToolkitModuleType.Tools, "ExtensionServiceCreator/Templates/ExtensionConstructorTemplate.txt");
private string InspectorTemplatePath => MixedRealityToolkitFiles.MapRelativeFilePath(MixedRealityToolkitModuleType.Tools, "ExtensionServiceCreator/Templates/ExtensionInspectorTemplate.txt");
private string InterfaceTemplatePath => MixedRealityToolkitFiles.MapRelativeFilePath(MixedRealityToolkitModuleType.Tools, "ExtensionServiceCreator/Templates/ExtensionInterfaceTemplate.txt");
private string ProfileTemplatePath => MixedRealityToolkitFiles.MapRelativeFilePath(MixedRealityToolkitModuleType.Tools, "ExtensionServiceCreator/Templates/ExtensionProfileTemplate.txt");
// ExtensionServiceCreator/Templates/ExtensionScriptTemplate.txt
private string ServiceTemplatePath => AssetDatabase.GUIDToAssetPath("bd6d5de0b9c435345a4e4e25dda3afd1");
// ExtensionServiceCreator/Templates/ExtensionConstructorTemplate.txt
private string ServiceConstructorTemplatePath => AssetDatabase.GUIDToAssetPath("41b9c612c56dddd4691c98456dc221f2");
// ExtensionServiceCreator/Templates/ExtensionInspectorTemplate.txt
private string InspectorTemplatePath => AssetDatabase.GUIDToAssetPath("2283bd5be15f3074fa8839ef90573636");
// ExtensionServiceCreator/Templates/ExtensionInterfaceTemplate.txt
private string InterfaceTemplatePath => AssetDatabase.GUIDToAssetPath("1179733a8171c7a49bb1cbdc1ff0c04c");
// ExtensionServiceCreator/Templates/ExtensionProfileTemplate.txt
private string ProfileTemplatePath => AssetDatabase.GUIDToAssetPath("d67b9bbb1a49ad743a30f55e814007b9");

#endregion

private string ServiceFieldName => Char.ToLowerInvariant(ServiceName[0]) + ServiceName.Substring(1);
private string ProfileFieldName => Char.ToLowerInvariant(ProfileName[0]) + ProfileName.Substring(1);
private string ServiceFieldName => char.ToLowerInvariant(ServiceName[0]) + ServiceName.Substring(1);
private string ProfileFieldName => char.ToLowerInvariant(ProfileName[0]) + ProfileName.Substring(1);

private string ServiceFolderPath
{
get { return ServiceFolderObject != null ? AssetDatabase.GetAssetPath(ServiceFolderObject) : string.Empty; }
}
private string ServiceFolderPath => ServiceFolderObject != null ? AssetDatabase.GetAssetPath(ServiceFolderObject) : string.Empty;

private string InspectorFolderPath
{
get { return InspectorFolderObject != null ? AssetDatabase.GetAssetPath(InspectorFolderObject) : string.Empty; }
}
private string InspectorFolderPath => InspectorFolderObject != null ? AssetDatabase.GetAssetPath(InspectorFolderObject) : string.Empty;

private string InterfaceFolderPath
{
get { return InterfaceFolderObject != null ? AssetDatabase.GetAssetPath(InterfaceFolderObject) : string.Empty; }
}
private string InterfaceFolderPath => InterfaceFolderObject != null ? AssetDatabase.GetAssetPath(InterfaceFolderObject) : string.Empty;

private string ProfileFolderPath
{
get { return ProfileFolderObject != null ? AssetDatabase.GetAssetPath(ProfileFolderObject) : string.Empty; }
}

private string ProfileAssetFolderPath
{
get { return ProfileAssetFolderObject != null ? AssetDatabase.GetAssetPath(ProfileAssetFolderObject) : string.Empty; }
}
private string ProfileFolderPath => ProfileFolderObject != null ? AssetDatabase.GetAssetPath(ProfileFolderObject) : string.Empty;

private string ServiceTemplate;
private string ServiceConstructorTemplate;
Expand Down

0 comments on commit 7ebc9b3

Please sign in to comment.