Initial commit

This commit is contained in:
Thorbjoern
2025-05-26 00:46:28 +02:00
commit e5bca03433
3896 changed files with 1434297 additions and 0 deletions
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ebddc14e41f0117489ec33fb0c24a865
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,169 @@
#if TEXT_MESH_PRO_PRESENT || (UGUI_2_0_PRESENT && UNITY_6000_0_OR_NEWER)
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit.Samples.SpatialKeyboard;
namespace UnityEditor.XR.Interaction.Toolkit.Samples.SpatialKeyboard
{
[CustomPropertyDrawer(typeof(XRKeyboardConfig.KeyMapping))]
public class KeyMappingPropertyDrawer : PropertyDrawer
{
class SerializedPropertyFields
{
public SerializedProperty character;
public SerializedProperty shiftCharacter;
public SerializedProperty displayCharacter;
public SerializedProperty shiftDisplayCharacter;
public SerializedProperty displayIcon;
public SerializedProperty shiftDisplayIcon;
public SerializedProperty overrideDefaultKeyFunction;
public SerializedProperty keyFunction;
public SerializedProperty keyCode;
public SerializedProperty disabled;
public void FindProperties(SerializedProperty property)
{
character = property.FindPropertyRelative("m_Character");
shiftCharacter = property.FindPropertyRelative("m_ShiftCharacter");
displayCharacter = property.FindPropertyRelative("m_DisplayCharacter");
shiftDisplayCharacter = property.FindPropertyRelative("m_ShiftDisplayCharacter");
displayIcon = property.FindPropertyRelative("m_DisplayIcon");
shiftDisplayIcon = property.FindPropertyRelative("m_ShiftDisplayIcon");
overrideDefaultKeyFunction = property.FindPropertyRelative("m_OverrideDefaultKeyFunction");
keyFunction = property.FindPropertyRelative("m_KeyFunction");
keyCode = property.FindPropertyRelative("m_KeyCode");
disabled = property.FindPropertyRelative("m_Disabled");
}
}
/// <summary>
/// Contents of GUI elements used by this editor.
/// </summary>
protected static class Contents
{
public static readonly GUIContent character = EditorGUIUtility.TrTextContent("Character", "Character for this key in non-shifted state. This string will be passed to the keyboard and appended to the keyboard text string or processed as a keyboard command.");
public static readonly GUIContent shiftCharacter = EditorGUIUtility.TrTextContent("Shift Character", "Character for this key in a shifted state. This string will be passed to the keyboard and appended to the keyboard text string or processed as a keyboard command.");
public static readonly GUIContent displayCharacter = EditorGUIUtility.TrTextContent("Display Character", "Display character for this key in a non-shifted state. This string will be displayed on the key text field. If empty, character will be used as a fallback.");
public static readonly GUIContent shiftDisplayCharacter = EditorGUIUtility.TrTextContent("Shift Display Character", "Display character for this key in a shifted state. This string will be displayed on the key text field. If empty, shift character will be used as a fallback.");
public static readonly GUIContent displayIcon = EditorGUIUtility.TrTextContent("Display Icon", "Display icon for this key in a non-shifted state. This icon will be displayed on the key image field. If empty, the display character or character will be used as a fallback.");
public static readonly GUIContent shiftDisplayIcon = EditorGUIUtility.TrTextContent("Shift Display Icon", "Display icon for this key in a shifted state. This icon will be displayed on the key image field. If empty, the shift display character or shift character will be used as a fallback.");
public static readonly GUIContent overrideDefaultKeyFunction = EditorGUIUtility.TrTextContent("Override Default Key Function", "If true, this will expose a key function property to override the default key function of this config.");
public static readonly GUIContent keyFunction = EditorGUIUtility.TrTextContent("Key Function", "KeyFunction used for this key. The function callback will be called on key press and used to communicate with the keyboard API.");
public static readonly GUIContent keyCode = EditorGUIUtility.TrTextContent("Key Code", "(Optional) KeyCode used for this key. Used with Key Function to support already defined KeyCode values.");
public static readonly GUIContent disabled = EditorGUIUtility.TrTextContent("Disabled", "If true, the key button interactable property will be set to false.");
}
readonly SerializedPropertyFields m_Fields = new SerializedPropertyFields();
/// <summary>
/// See <see cref="PropertyDrawer"/>.
/// </summary>
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
if (property.isExpanded)
{
// 1 Foldout header + 3 boldLabel headers + 10 or 9 PropertyField
m_Fields.FindProperties(property);
var numLines = m_Fields.overrideDefaultKeyFunction.boolValue ? 14 : 13;
return EditorGUIUtility.singleLineHeight * numLines + EditorGUIUtility.standardVerticalSpacing * (numLines - 1);
}
return EditorGUIUtility.singleLineHeight;
}
/// <summary>
/// See <see cref="PropertyDrawer"/>.
/// </summary>
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
// Don't make child fields be indented
var indent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;
var propertyRect = position;
propertyRect.height = EditorGUIUtility.singleLineHeight;
m_Fields.FindProperties(property);
property.isExpanded = EditorGUI.Foldout(propertyRect, property.isExpanded, GetPreviewString(m_Fields), true);
// Draw expanded properties
if (property.isExpanded)
{
var yDelta = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
propertyRect.y += yDelta;
// Character settings
EditorGUI.LabelField(propertyRect, "Character Settings", EditorStyles.boldLabel);
propertyRect.y += yDelta;
using (new EditorGUI.IndentLevelScope())
{
EditorGUI.PropertyField(propertyRect, m_Fields.character, Contents.character);
propertyRect.y += yDelta;
EditorGUI.PropertyField(propertyRect, m_Fields.shiftCharacter, Contents.shiftCharacter);
propertyRect.y += yDelta;
}
// Display settings
EditorGUI.LabelField(propertyRect, "Display Settings", EditorStyles.boldLabel);
propertyRect.y += yDelta;
using (new EditorGUI.IndentLevelScope())
{
EditorGUI.PropertyField(propertyRect, m_Fields.displayCharacter, Contents.displayCharacter);
propertyRect.y += yDelta;
EditorGUI.PropertyField(propertyRect, m_Fields.shiftDisplayCharacter, Contents.shiftDisplayCharacter);
propertyRect.y += yDelta;
EditorGUI.PropertyField(propertyRect, m_Fields.displayIcon, Contents.displayIcon);
propertyRect.y += yDelta;
EditorGUI.PropertyField(propertyRect, m_Fields.shiftDisplayIcon, Contents.shiftDisplayIcon);
propertyRect.y += yDelta;
}
// Function settings
EditorGUI.LabelField(propertyRect, "Function Settings", EditorStyles.boldLabel);
propertyRect.y += yDelta;
using (new EditorGUI.IndentLevelScope())
{
EditorGUI.PropertyField(propertyRect, m_Fields.overrideDefaultKeyFunction, Contents.overrideDefaultKeyFunction);
propertyRect.y += yDelta;
if (m_Fields.overrideDefaultKeyFunction.boolValue)
{
using (new EditorGUI.IndentLevelScope())
{
EditorGUI.PropertyField(propertyRect, m_Fields.keyFunction, Contents.keyFunction);
propertyRect.y += yDelta;
}
}
EditorGUI.PropertyField(propertyRect, m_Fields.keyCode, Contents.keyCode);
propertyRect.y += yDelta;
EditorGUI.PropertyField(propertyRect, m_Fields.disabled, Contents.disabled);
propertyRect.y += yDelta;
}
}
// Set indent back to what it was
EditorGUI.indentLevel = indent;
EditorGUI.EndProperty();
}
static string GetPreviewString(SerializedPropertyFields fields)
{
if (fields.overrideDefaultKeyFunction.boolValue)
{
var keyFunctionName = fields.keyFunction.objectReferenceValue != null
? fields.keyFunction.objectReferenceValue.name
: "None";
return $"{fields.character.stringValue} [{keyFunctionName}]";
}
return fields.character.stringValue;
}
}
}
#endif
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bf84391e5296de6468c2c36a85c6ee65
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,184 @@
using UnityEngine.XR.Interaction.Toolkit.Samples.SpatialKeyboard;
using UnityEngine;
namespace UnityEditor.XR.Interaction.Toolkit.Samples.SpatialKeyboard
{
/// <summary>
/// Custom editor for a <see cref="KeyboardOptimizer"/>.
/// </summary>
[CustomEditor(typeof(KeyboardOptimizer), true), CanEditMultipleObjects]
public class KeyboardOptimizerEditor : BaseInteractionEditor
{
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="KeyboardOptimizer.optimizeOnStart"/>.</summary>
protected SerializedProperty m_OptimizeOnStart;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="KeyboardOptimizer.batchGroupParentTransform"/>.</summary>
protected SerializedProperty m_BatchGroupParentTransform;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="KeyboardOptimizer.buttonParentTransform"/>.</summary>
protected SerializedProperty m_ButtonParentTransform;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="KeyboardOptimizer.imageParentTransform"/>.</summary>
protected SerializedProperty m_ImageParentTransform;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="KeyboardOptimizer.textParentTransform"/>.</summary>
protected SerializedProperty m_TextParentTransform;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="KeyboardOptimizer.iconParentTransform"/>.</summary>
protected SerializedProperty m_IconParentTransform;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="KeyboardOptimizer.highlightParentTransform"/>.</summary>
protected SerializedProperty m_HighlightParentTransform;
KeyboardOptimizer m_KeyboardTarget;
/// <summary>
/// Contents of GUI elements used by this editor.
/// </summary>
protected static class Contents
{
/// <summary><see cref="GUIContent"/> for <see cref="KeyboardOptimizer.optimizeOnStart"/>.</summary>
public static readonly GUIContent optimizeOnStart = EditorGUIUtility.TrTextContent("Optimize On Start", "If enabled, the optimization will be called on Start.");
/// <summary><see cref="GUIContent"/> for the <see cref="KeyboardOptimizer.batchGroupParentTransform"/> property.</summary>
public static readonly GUIContent batchGroupParentTransform = EditorGUIUtility.TrTextContent("Batch Group Parent Transform", "The parent transform for batch groups.");
/// <summary><see cref="GUIContent"/> for the <see cref="KeyboardOptimizer.buttonParentTransform"/> property.</summary>
public static readonly GUIContent buttonParentTransform = EditorGUIUtility.TrTextContent("Button Parent Transform", "The parent transform for buttons.");
/// <summary><see cref="GUIContent"/> for the <see cref="KeyboardOptimizer.imageParentTransform"/> property.</summary>
public static readonly GUIContent imageParentTransform = EditorGUIUtility.TrTextContent("Image Parent Transform", "The parent transform for images.");
/// <summary><see cref="GUIContent"/> for the <see cref="KeyboardOptimizer.textParentTransform"/> property.</summary>
public static readonly GUIContent textParentTransform = EditorGUIUtility.TrTextContent("Text Parent Transform", "The parent transform for text elements.");
/// <summary><see cref="GUIContent"/> for the <see cref="KeyboardOptimizer.iconParentTransform"/> property.</summary>
public static readonly GUIContent iconParentTransform = EditorGUIUtility.TrTextContent("Icon Parent Transform", "The parent transform for icons.");
/// <summary><see cref="GUIContent"/> for the <see cref="KeyboardOptimizer.highlightParentTransform"/> property.</summary>
public static readonly GUIContent highlightParentTransform = EditorGUIUtility.TrTextContent("Highlight Parent Transform", "The parent transform for highlights.");
/// <summary><see cref="GUIContent"/> for Batch Transform References header label.</summary>
public static readonly GUIContent batchTransformReferencesHeader = EditorGUIUtility.TrTextContent("Batch Transform References");
/// <summary><see cref="GUIContent"/> for Optimize button.</summary>
public static readonly GUIContent optimizeButton = EditorGUIUtility.TrTextContent("Optimize", "This is the same as call Optimize() in the script.");
/// <summary><see cref="GUIContent"/> for Unoptimize button.</summary>
public static readonly GUIContent unoptimizeButton = EditorGUIUtility.TrTextContent("Unoptimize", "This is the same as call Unoptimize() in the script.");
/// <summary><see cref="GUIContent"/> for the Optimization header label.</summary>
public static readonly GUIContent optimizationHeader = EditorGUIUtility.TrTextContent("Optimization");
/// <summary><see cref="GUIContent"/> for the message label when multi-object editing.</summary>
public static readonly GUIContent optimizationOnlySingleObject = EditorGUIUtility.TrTextContent("Optimization is only available when a single GameObject is selected.");
/// <summary><see cref="GUIContent"/> for the message label when not in a scene.</summary>
public static readonly GUIContent optimizationOnlyInScene = EditorGUIUtility.TrTextContent("Optimization is only available with scene objects during runtime.");
/// <summary><see cref="GUIContent"/> for the message label when not in Play mode.</summary>
public static readonly GUIContent optimizationOnlyDuringRuntime = EditorGUIUtility.TrTextContent("Optimization is only available during runtime.");
}
/// <summary>
/// See <see cref="Editor"/>.
/// </summary>
protected void OnEnable()
{
m_OptimizeOnStart = serializedObject.FindProperty("m_OptimizeOnStart");
m_BatchGroupParentTransform = serializedObject.FindProperty("m_BatchGroupParentTransform");
m_ButtonParentTransform = serializedObject.FindProperty("m_ButtonParentTransform");
m_ImageParentTransform = serializedObject.FindProperty("m_ImageParentTransform");
m_TextParentTransform = serializedObject.FindProperty("m_TextParentTransform");
m_IconParentTransform = serializedObject.FindProperty("m_IconParentTransform");
m_HighlightParentTransform = serializedObject.FindProperty("m_HighlightParentTransform");
m_KeyboardTarget = (KeyboardOptimizer)target;
}
/// <inheritdoc />
/// <seealso cref="DrawBeforeProperties"/>
/// <seealso cref="DrawProperties"/>
/// <seealso cref="BaseInteractionEditor.DrawDerivedProperties"/>
protected override void DrawInspector()
{
DrawBeforeProperties();
DrawProperties();
DrawDerivedProperties();
DrawOptimizationControls();
}
/// <summary>
/// This method is automatically called by <see cref="DrawInspector"/> to
/// draw the section of the custom inspector before <see cref="DrawProperties"/>.
/// By default, this draws the read-only Script property.
/// </summary>
protected virtual void DrawBeforeProperties()
{
DrawScript();
}
/// <summary>
/// This method is automatically called by <see cref="DrawInspector"/> to
/// draw the property fields. Override this method to customize the
/// properties shown in the Inspector. This is typically the method overridden
/// when a derived behavior adds additional serialized properties
/// that should be displayed in the Inspector.
/// </summary>
protected virtual void DrawProperties()
{
EditorGUILayout.PropertyField(m_OptimizeOnStart, Contents.optimizeOnStart);
m_BatchGroupParentTransform.isExpanded = EditorGUILayout.BeginFoldoutHeaderGroup(m_BatchGroupParentTransform.isExpanded, Contents.batchTransformReferencesHeader);
if (m_BatchGroupParentTransform.isExpanded)
{
using (new EditorGUI.IndentLevelScope())
{
EditorGUILayout.PropertyField(m_BatchGroupParentTransform, Contents.batchGroupParentTransform);
EditorGUILayout.PropertyField(m_ButtonParentTransform, Contents.buttonParentTransform);
EditorGUILayout.PropertyField(m_ImageParentTransform, Contents.imageParentTransform);
EditorGUILayout.PropertyField(m_TextParentTransform, Contents.textParentTransform);
EditorGUILayout.PropertyField(m_IconParentTransform, Contents.iconParentTransform);
EditorGUILayout.PropertyField(m_HighlightParentTransform, Contents.highlightParentTransform);
}
}
EditorGUILayout.EndFoldoutHeaderGroup();
}
/// <summary>
/// This method is automatically called by <see cref="DrawInspector"/> to
/// draw the Optimization section.
/// </summary>
protected virtual void DrawOptimizationControls()
{
EditorGUILayout.Space();
EditorGUILayout.LabelField(Contents.optimizationHeader, EditorStyles.boldLabel);
var isOptimizationAvailable = true;
if (targets.Length > 1)
{
EditorGUILayout.HelpBox(Contents.optimizationOnlySingleObject.text, MessageType.None);
isOptimizationAvailable = false;
}
else if (!m_KeyboardTarget.gameObject.scene.IsValid())
{
EditorGUILayout.HelpBox(Contents.optimizationOnlyInScene.text, MessageType.None);
isOptimizationAvailable = false;
}
else if (!Application.isPlaying)
{
EditorGUILayout.HelpBox(Contents.optimizationOnlyDuringRuntime.text, MessageType.None);
isOptimizationAvailable = false;
}
using (new EditorGUILayout.HorizontalScope())
{
using (new EditorGUI.DisabledScope(!isOptimizationAvailable || m_KeyboardTarget.isCurrentlyOptimized))
{
if (GUILayout.Button(Contents.optimizeButton))
((KeyboardOptimizer)target).Optimize();
}
using (new EditorGUI.DisabledScope(!isOptimizationAvailable || !m_KeyboardTarget.isCurrentlyOptimized))
{
if (GUILayout.Button(Contents.unoptimizeButton))
((KeyboardOptimizer)target).Unoptimize();
}
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 83af6bccea6d14346953e77a76b181b2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,188 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Unity.XR.CoreUtils.Editor;
using UnityEditor.PackageManager;
using UnityEditor.PackageManager.Requests;
using UnityEditor.PackageManager.UI;
using UnityEditor.XR.Interaction.Toolkit.ProjectValidation;
using UnityEngine;
#if TEXT_MESH_PRO_PRESENT || (UGUI_2_0_PRESENT && UNITY_6000_0_OR_NEWER)
using TMPro;
#endif
namespace UnityEditor.XR.Interaction.Toolkit.Samples.SpatialKeyboard.Editor
{
/// <summary>
/// Unity Editor class which registers Project Validation rules for the Spatial Keyboard sample,
/// checking that required samples and packages are installed.
/// </summary>
static class SpatialKeyboardSampleProjectValidation
{
const string k_SampleDisplayName = "Spatial Keyboard";
const string k_Category = "XR Interaction Toolkit";
const string k_StarterAssetsSampleName = "Starter Assets";
const string k_ProjectValidationSettingsPath = "Project/XR Plug-in Management/Project Validation";
const string k_XRIPackageName = "com.unity.xr.interaction.toolkit";
#if UNITY_6000_0_OR_NEWER
const string k_UIPackageName = "com.unity.ugui";
#else
const string k_UIPackageName = "com.unity.textmeshpro";
#endif
static readonly BuildTargetGroup[] s_BuildTargetGroups =
((BuildTargetGroup[])Enum.GetValues(typeof(BuildTargetGroup))).Distinct().ToArray();
static AddRequest s_UIPackageAddRequest;
static readonly List<BuildValidationRule> s_BuildValidationRules = new List<BuildValidationRule>
{
new BuildValidationRule
{
Message = $"[{k_SampleDisplayName}] {k_StarterAssetsSampleName} sample from XR Interaction Toolkit ({k_XRIPackageName}) package must be imported or updated to use this sample. {GetImportSampleVersionMessage(k_Category, k_StarterAssetsSampleName, PackageVersionUtility.GetPackageVersion(k_XRIPackageName))}",
Category = k_Category,
CheckPredicate = () => ProjectValidationUtility.SampleImportMeetsMinimumVersion(k_Category, k_StarterAssetsSampleName, PackageVersionUtility.GetPackageVersion(k_XRIPackageName)),
FixIt = () =>
{
if (TryFindSample(k_XRIPackageName, string.Empty, k_StarterAssetsSampleName, out var sample))
{
sample.Import(Sample.ImportOptions.OverridePreviousImports);
}
},
FixItAutomatic = true,
Error = !ProjectValidationUtility.HasSampleImported(k_Category, k_StarterAssetsSampleName),
},
new BuildValidationRule
{
IsRuleEnabled = () => s_UIPackageAddRequest == null || s_UIPackageAddRequest.IsCompleted,
Message = $"[{k_SampleDisplayName}] UGUI ({k_UIPackageName}) package must be installed for this sample.",
Category = k_Category,
CheckPredicate = () => PackageVersionUtility.IsPackageInstalled(k_UIPackageName),
FixIt = () =>
{
s_UIPackageAddRequest = Client.Add(k_UIPackageName);
if (s_UIPackageAddRequest.Error != null)
{
Debug.LogError($"Package installation error: {s_UIPackageAddRequest.Error}: {s_UIPackageAddRequest.Error.message}");
}
},
FixItAutomatic = true,
Error = true,
},
#if TEXT_MESH_PRO_PRESENT || (UGUI_2_0_PRESENT && UNITY_6000_0_OR_NEWER)
new BuildValidationRule
{
IsRuleEnabled = () => PackageVersionUtility.IsPackageInstalled(k_UIPackageName),
Message = $"[{k_SampleDisplayName}] TextMesh Pro - TMP Essentials must be installed for this sample.",
HelpText = "Can be installed using Window > TextMeshPro > Import TMP Essential Resources or by clicking this Edit button and then Import TMP Essentials in the window that appears.",
Category = k_Category,
CheckPredicate = () => PackageVersionUtility.IsPackageInstalled(k_UIPackageName) && TextMeshProEssentialsInstalled(),
FixIt = () =>
{
TMP_PackageResourceImporterWindow.ShowPackageImporterWindow();
},
FixItAutomatic = false,
Error = true,
},
#endif
};
[InitializeOnLoadMethod]
static void RegisterProjectValidationRules()
{
// Delay evaluating conditions for issues to give time for Package Manager and UPM cache to fully initialize.
EditorApplication.delayCall += AddRulesAndRunCheck;
}
static void AddRulesAndRunCheck()
{
foreach (var buildTargetGroup in s_BuildTargetGroups)
{
BuildValidator.AddRules(buildTargetGroup, s_BuildValidationRules);
}
ShowWindowIfIssuesExist();
}
static void ShowWindowIfIssuesExist()
{
foreach (var validation in s_BuildValidationRules)
{
if (validation.CheckPredicate == null || !validation.CheckPredicate.Invoke())
{
ShowWindow();
return;
}
}
}
internal static void ShowWindow()
{
// Delay opening the window since sometimes other settings in the player settings provider redirect to the
// project validation window causing serialized objects to be nullified.
EditorApplication.delayCall += () =>
{
SettingsService.OpenProjectSettings(k_ProjectValidationSettingsPath);
};
}
static bool TryFindSample(string packageName, string packageVersion, string sampleDisplayName, out Sample sample)
{
sample = default;
if (!PackageVersionUtility.IsPackageInstalled(packageName))
return false;
IEnumerable<Sample> packageSamples;
try
{
packageSamples = Sample.FindByPackage(packageName, packageVersion);
}
catch (Exception e)
{
Debug.LogError($"Couldn't find samples of the {ToString(packageName, packageVersion)} package; aborting project validation rule. Exception: {e}");
return false;
}
if (packageSamples == null)
{
Debug.LogWarning($"Couldn't find samples of the {ToString(packageName, packageVersion)} package; aborting project validation rule.");
return false;
}
foreach (var packageSample in packageSamples)
{
if (packageSample.displayName == sampleDisplayName)
{
sample = packageSample;
return true;
}
}
Debug.LogWarning($"Couldn't find {sampleDisplayName} sample in the {ToString(packageName, packageVersion)} package; aborting project validation rule.");
return false;
}
static bool TextMeshProEssentialsInstalled()
{
// Matches logic in Project Settings window, see TMP_PackageResourceImporter.cs.
// For simplicity, we don't also copy the check if the asset needs to be updated.
return File.Exists("Assets/TextMesh Pro/Resources/TMP Settings.asset");
}
static string ToString(string packageName, string packageVersion)
{
return string.IsNullOrEmpty(packageVersion) ? packageName : $"{packageName}@{packageVersion}";
}
static string GetImportSampleVersionMessage(string packageFolderName, string sampleDisplayName, PackageVersion version)
{
if (ProjectValidationUtility.SampleImportMeetsMinimumVersion(packageFolderName, sampleDisplayName, version) || !ProjectValidationUtility.HasSampleImported(packageFolderName, sampleDisplayName))
return string.Empty;
return $"An older version of {sampleDisplayName} has been found. This may cause errors.";
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 50fef6c461e4ab04ebeadac7b7e61185
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,36 @@
#if TEXT_MESH_PRO_PRESENT || (UGUI_2_0_PRESENT && UNITY_6000_0_OR_NEWER)
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit.Samples.SpatialKeyboard;
namespace UnityEditor.XR.Interaction.Toolkit.Samples.SpatialKeyboard
{
/// <summary>
/// Custom editor for an <see cref="XRKeyboardConfig"/>.
/// </summary>
[CustomEditor(typeof(XRKeyboardConfig), true), CanEditMultipleObjects]
public class XRKeyboardConfigEditor : BaseInteractionEditor
{
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboardConfig.defaultKeyFunction"/>.</summary>
protected SerializedProperty m_DefaultKeyFunction;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboardConfig.keyMappings"/>.</summary>
protected SerializedProperty m_KeyMappings;
/// <summary>
/// See <see cref="Editor"/>.
/// </summary>
protected virtual void OnEnable()
{
m_DefaultKeyFunction = serializedObject.FindProperty("m_DefaultKeyFunction");
m_KeyMappings = serializedObject.FindProperty("m_KeyMappings");
}
/// <inheritdoc />
protected override void DrawInspector()
{
DrawScript();
EditorGUILayout.PropertyField(m_DefaultKeyFunction);
EditorGUILayout.PropertyField(m_KeyMappings);
}
}
}
#endif
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 336152d70bca65d49a424cea3b6cd4b8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,121 @@
#if TEXT_MESH_PRO_PRESENT || (UGUI_2_0_PRESENT && UNITY_6000_0_OR_NEWER)
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit.Samples.SpatialKeyboard;
namespace UnityEditor.XR.Interaction.Toolkit.Samples.SpatialKeyboard
{
/// <summary>
/// Custom editor for an <see cref="XRKeyboardDisplay"/>.
/// </summary>
[CustomEditor(typeof(XRKeyboardDisplay), true), CanEditMultipleObjects]
public class XRKeyboardDisplayEditor : BaseInteractionEditor
{
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboardDisplay.inputField"/>.</summary>
protected SerializedProperty m_InputField;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboardDisplay.keyboard"/>.</summary>
protected SerializedProperty m_Keyboard;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboardDisplay.useSceneKeyboard"/>.</summary>
protected SerializedProperty m_UseSceneKeyboard;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboardDisplay.updateOnKeyPress"/>.</summary>
protected SerializedProperty m_UpdateOnKeyPress;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboardDisplay.alwaysObserveKeyboard"/>.</summary>
protected SerializedProperty m_AlwaysObserveKeyboard;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboardDisplay.monitorInputFieldCharacterLimit"/>.</summary>
protected SerializedProperty m_MonitorInputFieldCharacterLimit;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboardDisplay.clearTextOnSubmit"/>.</summary>
protected SerializedProperty m_ClearTextOnSubmit;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboardDisplay.clearTextOnOpen"/>.</summary>
protected SerializedProperty m_ClearTextOnOpen;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboardDisplay.onKeyboardOpened"/>.</summary>
protected SerializedProperty m_OnKeyboardOpened;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboardDisplay.onKeyboardClosed"/>.</summary>
protected SerializedProperty m_OnKeyboardClosed;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboardDisplay.onKeyboardFocusChanged"/>.</summary>
protected SerializedProperty m_OnKeyboardFocusChanged;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboardDisplay.onTextSubmitted"/>.</summary>
protected SerializedProperty m_OnTextSubmitted;
/// <summary>
/// Contents of GUI elements used by this editor.
/// </summary>
protected static class Contents
{
public static readonly GUIContent inputField = EditorGUIUtility.TrTextContent("Input Field", "Input field linked to this display");
public static readonly GUIContent keyboard = EditorGUIUtility.TrTextContent("Keyboard", "Keyboard for this display to monitor and interact with. If empty this will default to the GlobalNonNativeKeyboard keyboard.");
public static readonly GUIContent useSceneKeyboard = EditorGUIUtility.TrTextContent("Use Scene Keyboard", "If true, this display will use the keyboard reference. If false or if the keyboard field is empty, this display will use global keyboard.");
public static readonly GUIContent updateOnKeyPress = EditorGUIUtility.TrTextContent("Update on Key Press", "If true, this display will update with each key press. If false, this display will update on OnTextSubmit.");
public static readonly GUIContent alwaysObserveKeyboard = EditorGUIUtility.TrTextContent("Always Observe Keyboard", "If true, this display will always subscribe to the keyboard updates. If false, this display will subscribe to keyboard when the input field gains focus.");
public static readonly GUIContent monitorInputFieldCharacterLimit = EditorGUIUtility.TrTextContent("Monitor Input Field Character Limit", "If true, this display will use the input field's character limit to limit the update text from the keyboard and will pass this into the keyboard when opening.");
public static readonly GUIContent clearTextOnSubmit = EditorGUIUtility.TrTextContent("Clear Text on Submit", "If true, this display will clear the input field text on text submit from the keyboard.");
public static readonly GUIContent clearTextOnOpen = EditorGUIUtility.TrTextContent("Clear Text on Open", "If true, this display will clear the input field text when the keyboard opens.");
public static readonly GUIContent keyboardEvents = EditorGUIUtility.TrTextContent("Keyboard Display Events", "Events associated with the keyboard display");
public static readonly GUIContent onKeyboardOpened = EditorGUIUtility.TrTextContent("On Keyboard Opened", "The event that is called when this display opens a keyboard.");
public static readonly GUIContent onKeyboardClosed = EditorGUIUtility.TrTextContent("On Keyboard Closed", "The event that is called when the keyboard this display is observing is closed.");
public static readonly GUIContent onKeyboardFocusChanged = EditorGUIUtility.TrTextContent("On Keyboard Focus Changed", "The event that is called when the keyboard changes focus and this display is not focused.");
public static readonly GUIContent onTextSubmitted = EditorGUIUtility.TrTextContent("On Text Submitted", "The event that is called when this display receives a text submitted event from the keyboard. Invoked with the keyboard text as a parameter.");
}
/// <summary>
/// See <see cref="Editor"/>.
/// </summary>
protected virtual void OnEnable()
{
m_InputField = serializedObject.FindProperty("m_InputField");
m_Keyboard = serializedObject.FindProperty("m_Keyboard");
m_UseSceneKeyboard = serializedObject.FindProperty("m_UseSceneKeyboard");
m_UpdateOnKeyPress = serializedObject.FindProperty("m_UpdateOnKeyPress");
m_AlwaysObserveKeyboard = serializedObject.FindProperty("m_AlwaysObserveKeyboard");
m_MonitorInputFieldCharacterLimit = serializedObject.FindProperty("m_MonitorInputFieldCharacterLimit");
m_ClearTextOnSubmit = serializedObject.FindProperty("m_ClearTextOnSubmit");
m_ClearTextOnOpen = serializedObject.FindProperty("m_ClearTextOnOpen");
m_OnKeyboardOpened = serializedObject.FindProperty("m_OnKeyboardOpened");
m_OnKeyboardClosed = serializedObject.FindProperty("m_OnKeyboardClosed");
m_OnKeyboardFocusChanged = serializedObject.FindProperty("m_OnKeyboardFocusChanged");
m_OnTextSubmitted = serializedObject.FindProperty("m_OnTextSubmitted");
}
/// <inheritdoc />
protected override void DrawInspector()
{
DrawScript();
EditorGUILayout.PropertyField(m_InputField, Contents.inputField);
EditorGUILayout.PropertyField(m_UseSceneKeyboard, Contents.useSceneKeyboard);
using (new EditorGUI.IndentLevelScope())
{
using (new EditorGUI.DisabledScope(!m_UseSceneKeyboard.boolValue || Application.isPlaying))
{
EditorGUILayout.PropertyField(m_Keyboard, Contents.keyboard);
}
}
EditorGUILayout.PropertyField(m_UpdateOnKeyPress, Contents.updateOnKeyPress);
EditorGUILayout.PropertyField(m_AlwaysObserveKeyboard, Contents.alwaysObserveKeyboard);
EditorGUILayout.PropertyField(m_MonitorInputFieldCharacterLimit, Contents.monitorInputFieldCharacterLimit);
EditorGUILayout.PropertyField(m_ClearTextOnSubmit, Contents.clearTextOnSubmit);
EditorGUILayout.PropertyField(m_ClearTextOnOpen, Contents.clearTextOnOpen);
DrawKeyboardEvents();
}
void DrawKeyboardEvents()
{
m_OnTextSubmitted.isExpanded = EditorGUILayout.Foldout(m_OnTextSubmitted.isExpanded, Contents.keyboardEvents, toggleOnLabelClick: true);
if (m_OnTextSubmitted.isExpanded)
{
EditorGUILayout.PropertyField(m_OnTextSubmitted, Contents.onTextSubmitted);
EditorGUILayout.PropertyField(m_OnKeyboardOpened, Contents.onKeyboardOpened);
EditorGUILayout.PropertyField(m_OnKeyboardClosed, Contents.onKeyboardClosed);
EditorGUILayout.PropertyField(m_OnKeyboardFocusChanged, Contents.onKeyboardFocusChanged);
}
}
}
}
#endif
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 933dba84a98d0a94facc4dd555755984
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,114 @@
#if TEXT_MESH_PRO_PRESENT || (UGUI_2_0_PRESENT && UNITY_6000_0_OR_NEWER)
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit.Samples.SpatialKeyboard;
namespace UnityEditor.XR.Interaction.Toolkit.Samples.SpatialKeyboard
{
/// <summary>
/// Custom editor for an <see cref="XRKeyboard"/>.
/// </summary>
[CustomEditor(typeof(XRKeyboard), true), CanEditMultipleObjects]
public class XRKeyboardEditor : BaseInteractionEditor
{
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboard.submitOnEnter"/>.</summary>
protected SerializedProperty m_SubmitOnEnter;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboard.closeOnSubmit"/>.</summary>
protected SerializedProperty m_CloseOnSubmit;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboard.doubleClickInterval"/>.</summary>
protected SerializedProperty m_DoubleClickInterval;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboard.subsetLayout"/>.</summary>
protected SerializedProperty m_SubsetLayout;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboard.onTextSubmitted"/>.</summary>
protected SerializedProperty m_OnTextSubmit;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboard.onTextUpdated"/>.</summary>
protected SerializedProperty m_OnTextUpdate;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboard.onKeyPressed"/>.</summary>
protected SerializedProperty m_OnKeyPressed;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboard.onShifted"/>.</summary>
protected SerializedProperty m_OnShift;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboard.onLayoutChanged"/>.</summary>
protected SerializedProperty m_OnLayoutChange;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboard.onOpened"/>.</summary>
protected SerializedProperty m_OnOpen;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboard.onClosed"/>.</summary>
protected SerializedProperty m_OnClose;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboard.onFocusChanged"/>.</summary>
protected SerializedProperty m_OnFocusChanged;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboard.onCharacterLimitReached"/>.</summary>
protected SerializedProperty m_OnCharacterLimitReached;
/// <summary>
/// Contents of GUI elements used by this editor.
/// </summary>
protected static class Contents
{
public static readonly GUIContent submitOnEnter = EditorGUIUtility.TrTextContent("Submit On Enter", "If true, On Text Submit will be invoked when the keyboard receives a return or enter command. Otherwise it will treat return or enter as a newline.");
public static readonly GUIContent closeOnSubmit = EditorGUIUtility.TrTextContent("Close On Submit", "If true, keyboard will close on enter or return command.");
public static readonly GUIContent doubleClickInterval = EditorGUIUtility.TrTextContent("Double Click Interval", "Interval in which a key pressed twice would be considered a double click.");
public static readonly GUIContent subsetLayout = EditorGUIUtility.TrTextContent("Subset Layout", "List of layouts this keyboard is able to switch between given the corresponding layout command.");
public static readonly GUIContent keyboardEvents = EditorGUIUtility.TrTextContent("Keyboard Events", "Events associated with the keyboard.");
public static readonly GUIContent onTextSubmit = EditorGUIUtility.TrTextContent("On Text Submitted", "Event invoked when keyboard submits text.");
public static readonly GUIContent onTextUpdate = EditorGUIUtility.TrTextContent("On Text Updated", "Event invoked when keyboard text is updated.");
public static readonly GUIContent onKeyPressed = EditorGUIUtility.TrTextContent("On Key Pressed", "Event invoked after a key is pressed.");
public static readonly GUIContent onShift = EditorGUIUtility.TrTextContent("On Shifted", "Event invoked after keyboard shift is changed.");
public static readonly GUIContent onLayoutChange = EditorGUIUtility.TrTextContent("On Layout Changed", "Event invoked when the keyboard is opened. Called with the keyboard and the new layout string key.");
public static readonly GUIContent onOpen = EditorGUIUtility.TrTextContent("On Opened", "Event invoked when the keyboard is opened.");
public static readonly GUIContent onClose = EditorGUIUtility.TrTextContent("On Closed", "Event invoked after the keyboard is closed.");
public static readonly GUIContent onFocusChanged = EditorGUIUtility.TrTextContent("On Focus Changed", "Event invoked when the keyboard changes or gains input field focus.");
public static readonly GUIContent onCharacterLimitReached = EditorGUIUtility.TrTextContent("On Character Limit Reached", "Event invoked when the keyboard tries to update text, but the character of the input field is reached.");
}
/// <summary>
/// See <see cref="Editor"/>.
/// </summary>
protected virtual void OnEnable()
{
m_SubmitOnEnter = serializedObject.FindProperty("m_SubmitOnEnter");
m_CloseOnSubmit = serializedObject.FindProperty("m_CloseOnSubmit");
m_DoubleClickInterval = serializedObject.FindProperty("m_DoubleClickInterval");
m_SubsetLayout = serializedObject.FindProperty("m_SubsetLayout");
m_OnTextSubmit = serializedObject.FindProperty("m_OnTextSubmitted");
m_OnTextUpdate = serializedObject.FindProperty("m_OnTextUpdated");
m_OnKeyPressed = serializedObject.FindProperty("m_OnKeyPressed");
m_OnShift = serializedObject.FindProperty("m_OnShifted");
m_OnLayoutChange = serializedObject.FindProperty("m_OnLayoutChanged");
m_OnOpen = serializedObject.FindProperty("m_OnOpened");
m_OnClose = serializedObject.FindProperty("m_OnClosed");
m_OnFocusChanged = serializedObject.FindProperty("m_OnFocusChanged");
m_OnCharacterLimitReached = serializedObject.FindProperty("m_OnCharacterLimitReached");
}
/// <inheritdoc />
protected override void DrawInspector()
{
DrawScript();
EditorGUILayout.PropertyField(m_SubmitOnEnter, Contents.submitOnEnter);
EditorGUILayout.PropertyField(m_CloseOnSubmit, Contents.closeOnSubmit);
EditorGUILayout.PropertyField(m_DoubleClickInterval, Contents.doubleClickInterval);
EditorGUILayout.PropertyField(m_SubsetLayout, Contents.subsetLayout);
DrawKeyboardEvents();
}
void DrawKeyboardEvents()
{
m_OnOpen.isExpanded = EditorGUILayout.Foldout(m_OnOpen.isExpanded, Contents.keyboardEvents, toggleOnLabelClick: true);
if (m_OnOpen.isExpanded)
{
EditorGUILayout.PropertyField(m_OnOpen, Contents.onOpen);
EditorGUILayout.PropertyField(m_OnClose, Contents.onClose);
EditorGUILayout.PropertyField(m_OnFocusChanged, Contents.onFocusChanged);
EditorGUILayout.PropertyField(m_OnTextSubmit, Contents.onTextSubmit);
EditorGUILayout.PropertyField(m_OnTextUpdate, Contents.onTextUpdate);
EditorGUILayout.PropertyField(m_OnKeyPressed, Contents.onKeyPressed);
EditorGUILayout.PropertyField(m_OnShift, Contents.onShift);
EditorGUILayout.PropertyField(m_OnLayoutChange, Contents.onLayoutChange);
EditorGUILayout.PropertyField(m_OnCharacterLimitReached, Contents.onCharacterLimitReached);
}
}
}
}
#endif
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a09373fc8a4b6ae4e9868ff02f9e336a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,152 @@
#if TEXT_MESH_PRO_PRESENT || (UGUI_2_0_PRESENT && UNITY_6000_0_OR_NEWER)
using UnityEditor.UI;
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit.Samples.SpatialKeyboard;
namespace UnityEditor.XR.Interaction.Toolkit.Samples.SpatialKeyboard
{
/// <summary>
/// Custom editor for an <see cref="XRKeyboardKey"/>.
/// </summary>
[CustomEditor(typeof(XRKeyboardKey), true), CanEditMultipleObjects]
public class XRKeyboardKeyEditor : ButtonEditor
{
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboardKey.keyFunction"/>.</summary>
protected SerializedProperty m_KeyFunction;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboardKey.keyCode"/>.</summary>
protected SerializedProperty m_KeyCode;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboardKey.character"/>.</summary>
protected SerializedProperty m_Character;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboardKey.displayCharacter"/>.</summary>
protected SerializedProperty m_DisplayCharacter;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboardKey.displayIcon"/>.</summary>
protected SerializedProperty m_DisplayIcon;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboardKey.shiftCharacter"/>.</summary>
protected SerializedProperty m_ShiftCharacter;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboardKey.shiftDisplayCharacter"/>.</summary>
protected SerializedProperty m_ShiftDisplayCharacter;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboardKey.shiftDisplayIcon"/>.</summary>
protected SerializedProperty m_ShiftDisplayIcon;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboardKey.updateOnKeyDown"/>.</summary>
protected SerializedProperty m_UpdateOnKeyDown;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboardKey.textComponent"/>.</summary>
protected SerializedProperty m_TextComponent;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboardKey.audioSource"/>.</summary>
protected SerializedProperty m_AudioSource;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboardKey.highlightComponent"/>.</summary>
protected SerializedProperty m_HighlightComponent;
/// <summary><see cref="SerializedProperty"/> of the <see cref="SerializeField"/> backing <see cref="XRKeyboardKey.iconComponent"/>.</summary>
protected SerializedProperty m_IconComponent;
/// <summary>
/// Contents of GUI elements used by this editor.
/// </summary>
protected static class Contents
{
public static readonly GUIContent keyFunction = EditorGUIUtility.TrTextContent("Key Function", "KeyFunction used for this key. The FunctionCallBack will be called on key press and used to communicate with the keyboard.");
public static readonly GUIContent keyCode = EditorGUIUtility.TrTextContent("Key Code", "(Optional) KeyCode used for this key. Used in conjunction with KeyCodeFunction or as a fallback for standard commands.");
public static readonly GUIContent character = EditorGUIUtility.TrTextContent("Character", "Character for this key in non-shifted state. This string will be passed to the keyboard and appended to the keyboard text string or processed as a keyboard command.");
public static readonly GUIContent displayCharacter = EditorGUIUtility.TrTextContent("Display Character", "Display character for this key in a non-shifted state. This string will be displayed on the key text field. If empty, character will be used as a fall back.");
public static readonly GUIContent displayIcon = EditorGUIUtility.TrTextContent("Display Icon", "Display icon for this key in a non-shifted state. This icon will be displayed on the key image field. If empty, the display character or character will be used as a fall back.");
public static readonly GUIContent shiftCharacter = EditorGUIUtility.TrTextContent("Shift Character", "Character for this key in a shifted state. This string will be passed to the keyboard and appended to the keyboard text string or processed as a keyboard command.");
public static readonly GUIContent shiftDisplayCharacter = EditorGUIUtility.TrTextContent("Shift Display Character", "Display character for this key in a shifted state. This string will be displayed on the key text field. If empty, shift character will be used as a fall back.");
public static readonly GUIContent shiftDisplayIcon = EditorGUIUtility.TrTextContent("Shift Display Icon", "Display icon for this key in a shifted state. This icon will be displayed on the key image field. If empty, the shift display character or shift character will be used as a fall back.");
public static readonly GUIContent updateOnDown = EditorGUIUtility.TrTextContent("Update on key down", "If true, the key pressed event will fire on button down. If false, the key pressed event will fire on OnClick.");
public static readonly GUIContent textComponent = EditorGUIUtility.TrTextContent("Text Component", "Text field used to display key character.");
public static readonly GUIContent audioSource = EditorGUIUtility.TrTextContent("Audio Source", "(Optional) Audio source played when key is pressed.");
public static readonly GUIContent highlightComponent = EditorGUIUtility.TrTextContent("Highlight Component", "(Optional) Image used to highlight key indicating and active state.");
public static readonly GUIContent iconComponent = EditorGUIUtility.TrTextContent("Icon Component", "(Optional) Image used for key icon, used as an alternative to a character.");
public static readonly GUIContent buttonSettings = EditorGUIUtility.TrTextContent("Button Settings", "Settings for the keyboard key button.");
}
/// <inheritdoc />
protected override void OnEnable()
{
base.OnEnable();
m_KeyFunction = serializedObject.FindProperty("m_KeyFunction");
m_KeyCode = serializedObject.FindProperty("m_KeyCode");
m_Character = serializedObject.FindProperty("m_Character");
m_DisplayCharacter = serializedObject.FindProperty("m_DisplayCharacter");
m_DisplayIcon = serializedObject.FindProperty("m_DisplayIcon");
m_ShiftCharacter = serializedObject.FindProperty("m_ShiftCharacter");
m_ShiftDisplayCharacter = serializedObject.FindProperty("m_ShiftDisplayCharacter");
m_ShiftDisplayIcon = serializedObject.FindProperty("m_ShiftDisplayIcon");
m_UpdateOnKeyDown = serializedObject.FindProperty("m_UpdateOnKeyDown");
m_TextComponent = serializedObject.FindProperty("m_TextComponent");
m_AudioSource = serializedObject.FindProperty("m_AudioSource");
m_HighlightComponent = serializedObject.FindProperty("m_HighlightComponent");
m_IconComponent = serializedObject.FindProperty("m_IconComponent");
}
/// <inheritdoc />
public override void OnInspectorGUI()
{
serializedObject.Update();
DrawCharacterSettings();
DrawDisplaySettings();
DrawFunctionSettings();
DrawComponentReferences();
// Draw basic key settings
EditorGUILayout.PropertyField(m_UpdateOnKeyDown, Contents.updateOnDown);
// Draw button settings if that section is expanded
m_UpdateOnKeyDown.isExpanded = EditorGUILayout.Foldout(m_UpdateOnKeyDown.isExpanded, Contents.buttonSettings, toggleOnLabelClick: true);
if (m_UpdateOnKeyDown.isExpanded)
{
using (new EditorGUI.IndentLevelScope())
{
base.OnInspectorGUI();
}
}
serializedObject.ApplyModifiedProperties();
}
void DrawCharacterSettings()
{
EditorGUILayout.LabelField("Character Settings", EditorStyles.boldLabel);
using (new EditorGUI.IndentLevelScope())
{
EditorGUILayout.PropertyField(m_Character, Contents.character);
EditorGUILayout.PropertyField(m_ShiftCharacter, Contents.shiftCharacter);
}
}
void DrawDisplaySettings()
{
EditorGUILayout.LabelField("Display Settings", EditorStyles.boldLabel);
using (new EditorGUI.IndentLevelScope())
{
EditorGUILayout.PropertyField(m_DisplayCharacter, Contents.displayCharacter);
EditorGUILayout.PropertyField(m_ShiftDisplayCharacter, Contents.shiftDisplayCharacter);
EditorGUILayout.PropertyField(m_DisplayIcon, Contents.displayIcon);
EditorGUILayout.PropertyField(m_ShiftDisplayIcon, Contents.shiftDisplayIcon);
}
}
void DrawFunctionSettings()
{
EditorGUILayout.LabelField("Function Settings", EditorStyles.boldLabel);
using (new EditorGUI.IndentLevelScope())
{
EditorGUILayout.PropertyField(m_KeyFunction, Contents.keyFunction);
EditorGUILayout.PropertyField(m_KeyCode, Contents.keyCode);
}
}
void DrawComponentReferences()
{
EditorGUILayout.LabelField("Component References", EditorStyles.boldLabel);
using (new EditorGUI.IndentLevelScope())
{
EditorGUILayout.PropertyField(m_TextComponent, Contents.textComponent);
EditorGUILayout.PropertyField(m_IconComponent, Contents.iconComponent);
EditorGUILayout.PropertyField(m_HighlightComponent, Contents.highlightComponent);
EditorGUILayout.PropertyField(m_AudioSource, Contents.audioSource);
}
}
}
}
#endif
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2af9f13e3aa49624c9ed2bafb94c7146
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,34 @@
{
"name": "Unity.XR.Interaction.Toolkit.Samples.SpatialKeyboard.Editor",
"rootNamespace": "UnityEditor.XR.Interaction.Toolkit.Samples.SpatialKeyboard.Editor",
"references": [
"Unity.TextMeshPro",
"Unity.XR.Interaction.Toolkit",
"Unity.XR.Interaction.Toolkit.Editor",
"Unity.XR.Interaction.Toolkit.Samples.SpatialKeyboard",
"Unity.XR.CoreUtils",
"Unity.XR.CoreUtils.Editor"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [
{
"name": "com.unity.textmeshpro",
"expression": "3.0.6",
"define": "TEXT_MESH_PRO_PRESENT"
},
{
"name": "com.unity.ugui",
"expression": "2.0.0",
"define": "UGUI_2_0_PRESENT"
}
],
"noEngineReferences": false
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: caec957259cc5814287297ecb624a01b
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: