public void Migrate(GameObject gameObject) { #if UNITY_EDITOR ButtonConfigHelper bch = gameObject.GetComponent <ButtonConfigHelper>(); bch.EditorUpgradeCustomIcon(); #endif }
public IEnumerator TestPressableButtonHololens2Prefab() { GameObject buttonObject = InstantiateButtonFromPath(Vector3.zero, Quaternion.identity, TestButtonUtilities.PressableHoloLens2PrefabPath); ButtonConfigHelper bch = buttonObject.GetComponent <ButtonConfigHelper>(); bch.MainLabelText = "MainLabelText"; Assert.AreEqual(bch.MainLabelText, "MainLabelText"); bch.SeeItSayItLabelText = "SeeItSayItLabelText"; Assert.AreEqual(bch.SeeItSayItLabelText, "SeeItSayItLabelText"); bch.IconStyle = ButtonIconStyle.Char; bch.IconStyle = ButtonIconStyle.None; bch.IconStyle = ButtonIconStyle.Quad; bch.IconStyle = ButtonIconStyle.Sprite; bch.SeeItSayItLabelEnabled = false; bch.SetCharIcon(0); bch.SetQuadIcon(null); bch.SetSpriteIcon(null); bch.SetCharIconByName("EmptyIcon"); bch.SetQuadIconByName("EmptyIcon"); bch.SetSpriteIconByName("EmptyIcon"); bch.ForceRefresh(); bch.OnClick.AddListener(() => { Debug.Log("OnClick"); }); bch.IconSet = null; yield break; }
public bool CanMigrate(GameObject gameObject) { #if UNITY_EDITOR ButtonConfigHelper bch = gameObject.GetComponent <ButtonConfigHelper>(); return(bch != null && bch.EditorCheckForCustomIcon()); #else return(false); #endif }
GameObject CreateButton(Vector3 coordinate, string displayText, string iconName, GameObject parentButton, GameObject buttonType, string buttonTag, float scale) { GameObject button = Instantiate(buttonType); button.transform.parent = parentButton.transform; button.transform.localScale = new Vector3(scale, scale, scale); button.transform.localPosition = coordinate; button.transform.localRotation = Quaternion.identity; button.tag = buttonTag; ButtonConfigHelper configHelper = button.GetComponent <ButtonConfigHelper>(); configHelper.MainLabelText = displayText; configHelper.SeeItSayItLabelEnabled = false; configHelper.SetQuadIconByName(iconName); return(button); }
public void ManipulateScrew() { ButtonConfigHelper buttonConfig = GameObject.Find(Constants.SCREW_MANIPULATE_BUTTON).GetComponentInChildren <ButtonConfigHelper>(); if (manipulating) { manipulating = false; buttonConfig.SetQuadIconByName(Constants.ICON_HAND_GESTURE); } else { manipulating = true; buttonConfig.SetQuadIconByName(Constants.ICON_STOP_HAND_GESTURE); } SetCurrObjectManipulator(screws[screwIndex], manipulating); }
public void ButtonMigrationTest() { Type migrationHandlerType = typeof(ButtonConfigHelperMigrationHandler); Material testMat = AssetDatabase.LoadAssetAtPath <Material>("Assets/MRTK/SDK/Features/UX/Interactable/Materials/HolographicButtonIconHome.mat"); Material testDefaultMat = AssetDatabase.LoadAssetAtPath <Material>("Assets/MRTK/SDK/Features/UX/Interactable/Materials/HolographicButtonIconStar.mat"); GameObject buttonGameObject = SetUpGameObjectWithComponentOfType(typeof(ButtonConfigHelper)); GameObject buttonQuad = GameObject.CreatePrimitive(PrimitiveType.Quad); buttonQuad.transform.parent = buttonGameObject.transform; MeshRenderer quadRenderer = buttonQuad.GetComponent <MeshRenderer>(); quadRenderer.sharedMaterial = testMat; ButtonConfigHelper buttonConfig = buttonGameObject.GetComponent <ButtonConfigHelper>(); ButtonIconSet testIconSet = new ButtonIconSet(); buttonConfig.IconStyle = ButtonIconStyle.Quad; buttonConfig.IconSet = testIconSet; buttonConfig.EditorSetDefaultIconSet(testIconSet); buttonConfig.EditorSetIconQuadRenderer(quadRenderer); buttonConfig.EditorSetDefaultQuadMaterial(testDefaultMat); migrationTool.TryAddObjectForMigration(migrationHandlerType, buttonGameObject); string testCustomIconSetFolder = System.IO.Path.Combine("Assets", "MixedRealityToolkit.Generated.Test"); AssetDatabase.DeleteAsset(testCustomIconSetFolder); AssetDatabase.CreateFolder("Assets", "MixedRealityToolkit.Generated.Test"); buttonConfig.EditorUpgradeCustomIcon(null, testCustomIconSetFolder, true); AssetDatabase.Refresh(); ButtonIconSet generatedIconSet = AssetDatabase.LoadAssetAtPath <ButtonIconSet>(System.IO.Path.Combine("Assets", "MixedRealityToolkit.Generated.Test", "CustomIconSets", "CustomIconSet.asset")); Assert.IsNotNull(generatedIconSet); Assert.IsTrue(generatedIconSet.QuadIcons.Length == 1); AssetDatabase.DeleteAsset(testCustomIconSetFolder); }
/// <summary> /// Test adding a config helper to a game object and attempting to modify it. /// </summary> public IEnumerator TestAddButtonConfigHelperAtRuntime() { GameObject newGameObject = new GameObject("ButtonTest"); ButtonConfigHelper bch = newGameObject.AddComponent <ButtonConfigHelper>(); bch.MainLabelText = "Test Text"; bch.SeeItSayItLabelText = "Test Text"; bch.IconStyle = ButtonIconStyle.Char; bch.IconStyle = ButtonIconStyle.None; bch.IconStyle = ButtonIconStyle.Quad; bch.IconStyle = ButtonIconStyle.Sprite; bch.SeeItSayItLabelEnabled = false; bch.SetCharIcon(0); bch.SetQuadIcon(null); bch.SetSpriteIcon(null); bch.SetCharIconByName("EmptyIcon"); bch.SetQuadIconByName("EmptyIcon"); bch.SetSpriteIconByName("EmptyIcon"); bch.ForceRefresh(); bch.OnClick.AddListener(() => { Debug.Log("OnClick"); }); bch.IconSet = null; yield break; }
public override void OnInspectorGUI() { cb = (ButtonConfigHelper)target; bool labelFoldout = SessionState.GetBool(LabelFoldoutKey, true); bool basicEventsFoldout = SessionState.GetBool(BasicEventsFoldoutKey, true); bool iconFoldout = SessionState.GetBool(IconFoldoutKey, true); bool showComponents = SessionState.GetBool(ShowComponentsKey, false); bool showSpeechCommand = SessionState.GetBool(ShowSpeechCommandKey, true); if (cb.EditorCheckForCustomIcon()) { using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox)) { EditorGUILayout.LabelField("Custom Icon Migration", EditorStyles.boldLabel); EditorGUILayout.HelpBox(customIconUpgradeMessage, MessageType.Error); using (new EditorGUILayout.HorizontalScope()) { if (GUILayout.Button("Use migration tool to upgrade buttons")) { if (!EditorApplication.ExecuteMenuItem("Mixed Reality/Toolkit/Utilities/Migration Window")) { EditorUtility.DisplayDialog("Package Required", "You need to install the MRTK tools (Microsoft.MixedRealityToolkit.Unity.Tools) package to use the Migration Tool", "OK"); } } InspectorUIUtility.RenderDocumentationButton(upgradeDocUrl); } } } showComponents = EditorGUILayout.Toggle("Show Component References", showComponents); ButtonIconStyle oldStyle = (ButtonIconStyle)iconStyleProp.intValue; using (new EditorGUI.IndentLevelScope(1)) { using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox)) { labelFoldout = EditorGUILayout.Foldout(labelFoldout, "Labels", true); if (labelFoldout) { EditorGUI.BeginChangeCheck(); if (showComponents) { EditorGUILayout.PropertyField(mainLabelTextProp); } if (mainLabelTextProp.objectReferenceValue != null) { Component mainLabelText = (Component)mainLabelTextProp.objectReferenceValue; bool mainLabelTextActive = EditorGUILayout.Toggle("Enable Main Label", mainLabelText.gameObject.activeSelf); if (mainLabelText.gameObject.activeSelf != mainLabelTextActive) { mainLabelText.gameObject.SetActive(mainLabelTextActive); EditorUtility.SetDirty(mainLabelText.gameObject); } if (mainLabelText.gameObject.activeSelf) { SerializedObject labelTextObject = new SerializedObject(mainLabelText); SerializedProperty textProp = labelTextObject.FindProperty("m_text"); EditorGUILayout.PropertyField(textProp, new GUIContent("Main Label Text")); EditorGUILayout.Space(); if (EditorGUI.EndChangeCheck()) { labelTextObject.ApplyModifiedProperties(); } } } if (showComponents) { EditorGUILayout.PropertyField(seeItSayItLabelProp); } if (seeItSayItLabelProp.objectReferenceValue != null) { GameObject seeItSayItLabel = (GameObject)seeItSayItLabelProp.objectReferenceValue; bool seeItSayItLabelActive = EditorGUILayout.Toggle("Enable See it / Say it Label", seeItSayItLabel.activeSelf); if (seeItSayItLabel.activeSelf != seeItSayItLabelActive) { seeItSayItLabel.SetActive(seeItSayItLabelActive); EditorUtility.SetDirty(seeItSayItLabel); } if (seeItSayItLabel.activeSelf) { var sisiChanged = false; EditorGUI.BeginChangeCheck(); if (showComponents) { EditorGUILayout.PropertyField(seeItSayItLabelTextProp); } showSpeechCommand = EditorGUILayout.Toggle("Display Speech Command", showSpeechCommand); SerializedObject sisiLabelTextObject = new SerializedObject(seeItSayItLabelTextProp.objectReferenceValue); SerializedProperty sisiTextProp = sisiLabelTextObject.FindProperty("m_text"); if (!showSpeechCommand) { EditorGUILayout.PropertyField(sisiTextProp, new GUIContent("See it / Say it Label")); EditorGUILayout.Space(); } else { if (interactableProp.objectReferenceValue != null) { SerializedObject interactableObject = new SerializedObject(interactableProp.objectReferenceValue); SerializedProperty voiceCommandProperty = interactableObject.FindProperty("voiceCommand"); if (string.IsNullOrEmpty(voiceCommandProperty.stringValue)) { EditorGUILayout.HelpBox("No valid speech command provided to the interactable", MessageType.Warning); } else { string sisiText = string.Format("Say \"{0}\"", voiceCommandProperty.stringValue); if (sisiTextProp.stringValue != sisiText) { sisiTextProp.stringValue = sisiText; sisiChanged = true; } } } else { EditorGUILayout.HelpBox("There is no interactable linked to the button config helper. One is needed to display the appropriate speech command", MessageType.Warning); } } sisiChanged |= EditorGUI.EndChangeCheck(); if (sisiChanged) { sisiLabelTextObject.ApplyModifiedProperties(); } } } } } } using (new EditorGUI.IndentLevelScope(1)) { using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox)) { basicEventsFoldout = EditorGUILayout.Foldout(basicEventsFoldout, "Basic Events", true); if (basicEventsFoldout) { EditorGUI.BeginChangeCheck(); if (showComponents) { EditorGUILayout.PropertyField(interactableProp); } if (interactableProp.objectReferenceValue != null) { SerializedObject interactableObject = new SerializedObject(interactableProp.objectReferenceValue); SerializedProperty onClickProp = interactableObject.FindProperty("OnClick"); EditorGUILayout.PropertyField(onClickProp); if (EditorGUI.EndChangeCheck()) { interactableObject.ApplyModifiedProperties(); } } } } } using (new EditorGUI.IndentLevelScope(1)) { using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox)) { iconFoldout = EditorGUILayout.Foldout(iconFoldout, "Icon", true); ButtonIconSet iconSet = (ButtonIconSet)iconSetProp.objectReferenceValue; if (iconFoldout) { EditorGUILayout.PropertyField(iconStyleProp); switch (cb.IconStyle) { case ButtonIconStyle.Char: DrawIconCharEditor(showComponents, iconSet); break; case ButtonIconStyle.Quad: DrawIconQuadEditor(showComponents, iconSet); break; case ButtonIconStyle.Sprite: DrawIconSpriteEditor(showComponents, iconSet); break; } EditorGUILayout.Space(); } } } SessionState.SetBool(LabelFoldoutKey, labelFoldout); SessionState.SetBool(BasicEventsFoldoutKey, basicEventsFoldout); SessionState.SetBool(IconFoldoutKey, iconFoldout); SessionState.SetBool(ShowComponentsKey, showComponents); SessionState.SetBool(ShowSpeechCommandKey, showSpeechCommand); serializedObject.ApplyModifiedProperties(); if (oldStyle != (ButtonIconStyle)iconStyleProp.intValue) { cb.ForceRefresh(); } }
private void GetBindingsForButton() { ButtonHelper = GetComponent <ButtonConfigHelper>(); ButtonHelper.OnClick.AddListener(Toggle); }
public override void OnInspectorGUI() { cb = (ButtonConfigHelper)target; bool labelFoldout = SessionState.GetBool(LabelFoldoutKey, true); bool basicEventsFoldout = SessionState.GetBool(BasicEventsFoldoutKey, true); bool iconFoldout = SessionState.GetBool(IconFoldoutKey, true); bool showComponents = SessionState.GetBool(ShowComponentsKey, false); if (cb.EditorCheckForCustomIcon()) { using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox)) { EditorGUILayout.LabelField("Custom Icon Migration", EditorStyles.boldLabel); EditorGUILayout.HelpBox(customIconUpgradeMessage, MessageType.Error); using (new EditorGUILayout.HorizontalScope()) { if (GUILayout.Button("Use migration tool to upgrade buttons")) { EditorApplication.ExecuteMenuItem("Mixed Reality Toolkit/Utilities/Migration Window"); } InspectorUIUtility.RenderDocumentationButton(upgradeDocUrl); } } } showComponents = EditorGUILayout.Toggle("Show Component References", showComponents); ButtonIconStyle oldStyle = (ButtonIconStyle)iconStyleProp.enumValueIndex; using (new EditorGUI.IndentLevelScope(1)) { using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox)) { labelFoldout = EditorGUILayout.Foldout(labelFoldout, "Labels", true); if (labelFoldout) { EditorGUI.BeginChangeCheck(); if (showComponents) { EditorGUILayout.PropertyField(mainLabelTextProp); } if (mainLabelTextProp.objectReferenceValue != null) { Component mainLabelText = (Component)mainLabelTextProp.objectReferenceValue; bool mainLabelTextActive = EditorGUILayout.Toggle("Enable Main Label", mainLabelText.gameObject.activeSelf); if (mainLabelText.gameObject.activeSelf != mainLabelTextActive) { mainLabelText.gameObject.SetActive(mainLabelTextActive); EditorUtility.SetDirty(mainLabelText.gameObject); } if (mainLabelText.gameObject.activeSelf) { SerializedObject labelTextObject = new SerializedObject(mainLabelText); SerializedProperty textProp = labelTextObject.FindProperty("m_text"); EditorGUILayout.PropertyField(textProp, new GUIContent("Main Label Text")); EditorGUILayout.Space(); if (EditorGUI.EndChangeCheck()) { labelTextObject.ApplyModifiedProperties(); } } } if (showComponents) { EditorGUILayout.PropertyField(seeItSayItLabelProp); } if (seeItSayItLabelProp.objectReferenceValue != null) { GameObject seeItSayItLabel = (GameObject)seeItSayItLabelProp.objectReferenceValue; bool seeItSayItLabelActive = EditorGUILayout.Toggle("Enable See it / Say it Label", seeItSayItLabel.activeSelf); if (seeItSayItLabel.activeSelf != seeItSayItLabelActive) { seeItSayItLabel.SetActive(seeItSayItLabelActive); EditorUtility.SetDirty(seeItSayItLabel.gameObject); } if (seeItSayItLabel.activeSelf) { if (showComponents) { EditorGUILayout.PropertyField(seeItSatItLabelTextProp); } EditorGUI.BeginChangeCheck(); SerializedObject sisiLabelTextObject = new SerializedObject(seeItSatItLabelTextProp.objectReferenceValue); SerializedProperty sisiTextProp = sisiLabelTextObject.FindProperty("m_text"); EditorGUILayout.PropertyField(sisiTextProp, new GUIContent("See it / Say it Label")); EditorGUILayout.Space(); if (EditorGUI.EndChangeCheck()) { sisiLabelTextObject.ApplyModifiedProperties(); } } } } } } using (new EditorGUI.IndentLevelScope(1)) { using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox)) { basicEventsFoldout = EditorGUILayout.Foldout(basicEventsFoldout, "Basic Events", true); if (basicEventsFoldout) { EditorGUI.BeginChangeCheck(); if (showComponents) { EditorGUILayout.PropertyField(interactableProp); } SerializedObject interactableObject = new SerializedObject(interactableProp.objectReferenceValue); SerializedProperty onClickProp = interactableObject.FindProperty("OnClick"); EditorGUILayout.PropertyField(onClickProp); if (EditorGUI.EndChangeCheck()) { interactableObject.ApplyModifiedProperties(); } } } } using (new EditorGUI.IndentLevelScope(1)) { using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox)) { iconFoldout = EditorGUILayout.Foldout(iconFoldout, "Icon", true); ButtonIconSet iconSet = (ButtonIconSet)iconSetProp.objectReferenceValue; if (iconFoldout) { EditorGUILayout.PropertyField(iconStyleProp); switch (cb.IconStyle) { case ButtonIconStyle.Char: DrawIconCharEditor(showComponents, iconSet); break; case ButtonIconStyle.Quad: DrawIconQuadEditor(showComponents, iconSet); break; case ButtonIconStyle.Sprite: DrawIconSpriteEditor(showComponents, iconSet); break; } EditorGUILayout.Space(); } } } SessionState.SetBool(LabelFoldoutKey, labelFoldout); SessionState.SetBool(BasicEventsFoldoutKey, basicEventsFoldout); SessionState.SetBool(IconFoldoutKey, iconFoldout); SessionState.SetBool(ShowComponentsKey, showComponents); serializedObject.ApplyModifiedProperties(); if (oldStyle != (ButtonIconStyle)iconStyleProp.enumValueIndex) { cb.ForceRefresh(); } }
// Start is called before the first frame update void Start() { interactableScript = GetComponent <Interactable>(); buttonConfigHelper = GetComponent <ButtonConfigHelper>(); interactableScript.OnClick.AddListener(OnToggle); }
/// <inheritdoc /> public void Migrate(GameObject gameObject) { ButtonConfigHelper bch = gameObject.GetComponent <ButtonConfigHelper>(); bch.EditorUpgradeCustomIcon(); }
/// <inheritdoc /> public bool CanMigrate(GameObject gameObject) { ButtonConfigHelper bch = gameObject.GetComponent <ButtonConfigHelper>(); return(bch != null && bch.EditorCheckForCustomIcon()); }