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; }
private void DrawIconSpriteEditor(bool showComponents, ButtonIconSet iconSet) { if (showComponents) { EditorGUILayout.PropertyField(iconSpriteRendererProp); } Sprite currentIconSprite = null; if (iconQuadTextureProp.objectReferenceValue != null) { currentIconSprite = iconSpriteProp.objectReferenceValue as Sprite; } else { if (iconSpriteRendererProp.objectReferenceValue != null) { currentIconSprite = ((SpriteRenderer)iconSpriteRendererProp.objectReferenceValue).sprite; } else { EditorGUILayout.HelpBox("This button has no icon quad renderer assigned.", MessageType.Warning); return; } } EditorGUILayout.Space(); EditorGUILayout.PropertyField(iconSetProp); if (iconSet != null) { Sprite newIconSprite; if (iconSet.EditorDrawSpriteIconSelector(currentIconSprite, out newIconSprite, 1)) { iconSpriteProp.objectReferenceValue = newIconSprite; cb.SetSpriteIcon(newIconSprite); } } else { EditorGUILayout.HelpBox("No icon set assigned. You can specify custom icons manually by assigning them to the field below:", MessageType.Info); EditorGUILayout.PropertyField(iconSpriteProp); } }
/// <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; }
private void DrawIconSpriteEditor(bool showComponents, ButtonIconSet iconSet) { if (showComponents) { EditorGUILayout.PropertyField(iconSpriteRendererProp); } Sprite currentIconSprite = null; if (iconQuadTextureProp.objectReferenceValue != null) { currentIconSprite = iconSpriteProp.objectReferenceValue as Sprite; } else { if (iconSpriteRendererProp.objectReferenceValue != null) { currentIconSprite = ((SpriteRenderer)iconSpriteRendererProp.objectReferenceValue).sprite; } else { EditorGUILayout.HelpBox("This button has no icon quad renderer assigned.", MessageType.Warning); return; } } EditorGUILayout.Space(); EditorGUILayout.PropertyField(iconSetProp); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button(EditorGUIUtility.IconContent("d_Refresh"), EditorStyles.miniButtonRight, GUILayout.Width(24f))) { iconSet.UpdateSpriteIconTextures(); } EditorGUILayout.EndHorizontal(); if (iconSet == null) { EditorGUILayout.HelpBox("No icon set assigned. You can specify custom icons manually by assigning them to the field below:", MessageType.Info); EditorGUILayout.PropertyField(iconQuadTextureProp); return; } if (iconSet.SpriteIcons == null || iconSet.SpriteIcons.Length == 0) { EditorGUILayout.HelpBox("No sprite icons assigned to the icon set. You can specify custom icons manually by assigning them to the field below:", MessageType.Info); EditorGUILayout.PropertyField(iconQuadTextureProp); return; } Sprite newIconSprite; bool foundSprite; if (iconSet.EditorDrawSpriteIconSelector(currentIconSprite, out foundSprite, out newIconSprite, 1)) { iconSpriteProp.objectReferenceValue = newIconSprite; cb.SetSpriteIcon(newIconSprite); } if (!foundSprite) { EditorGUILayout.HelpBox(missingIconWarningMessage, MessageType.Warning); EditorGUILayout.PropertyField(iconSpriteProp); } }