protected override GameObject CreateButton(SimpleMenuCollectionButton template) { GameObject newButton = base.CreateButton(template); // Update the button's icon and text // If the button doesn't have these components, ignore these settings CompoundButtonIcon icon = newButton.GetComponent <CompoundButtonIcon>(); if (icon != null) { icon.IconName = template.Icon; } CompoundButtonText text = newButton.GetComponent <CompoundButtonText>(); if (text != null) { text.Text = template.Text; } // Set the display order of the button using the transform order newButton.transform.SetSiblingIndex(template.Index); return(newButton); }
public void Initialize(AppBar newParentToolBar, AppBar.ButtonTemplate newTemplate, ButtonIconProfile newCustomProfile) { template = newTemplate; customIconProfile = newCustomProfile; parentToolBar = newParentToolBar; cButton = GetComponent <CompoundButton>(); cButton.MainRenderer.enabled = false; text = GetComponent <CompoundButtonText>(); text.Text = template.Text; icon = GetComponent <CompoundButtonIcon>(); highlightMeshRenderer = cButton.GetComponent <CompoundButtonMesh>().Renderer; if (customIconProfile != null) { icon.Profile = customIconProfile; icon.IconName = string.Empty; } icon.IconName = template.Icon; initialized = true; Hide(); if (newTemplate.EventTarget != null) { // Register the button with its target interactable newTemplate.EventTarget.Registerinteractable(gameObject); } else { // Register the button with the parent app bar newParentToolBar.Registerinteractable(gameObject); } }
protected override void DrawCustomFooter() { CompoundButtonIcon iconButton = (CompoundButtonIcon)target; if (iconButton != null && iconButton.Profile != null) { iconButton.IconName = iconButton.Profile.DrawIconSelectField(iconButton.IconName); } }
public override void setProperties(AppData.uniqueIDDevice.UIContainerData UIE) { text = GetComponent <CompoundButtonText>(); text.Text = UIE.displayText; icon = GetComponent <CompoundButtonIcon>(); icon.IconName = UIE.specificContainerData1; //finalizes in base class base.setProperties(UIE); }
// Load image from an url and use it as the button icon IEnumerator loadImageFromUrl(string url, GameObject button) { urlLogo = new Texture2D(4, 4, TextureFormat.DXT1, false); using (WWW www = new WWW(url)) { // Retrieve the image yield return(www); // Convert the image to a texture www.LoadImageIntoTexture(urlLogo); CompoundButtonIcon icon = button.GetComponent <CompoundButtonIcon>(); icon.iconOverride = urlLogo; icon.OverrideIcon = true; icon.IconName = "Ready"; float aspect_ratio = CalculateAspectRatio(urlLogo.width, urlLogo.height); // Scale the icon icon.IconMeshFilter.transform.localScale = new Vector3(2.5f, 2.5f / aspect_ratio, 1f); } }
public static void SetButtonState(CompoundButton button, bool active) { CompoundButtonIcon icon = button.GetComponent <CompoundButtonIcon>(); if (icon == null) { Debug.LogWarning("Missing CompoundButtonIcon on " + button.name); return; } MeshRenderer iconRenderer = icon.IconMeshFilter.GetComponent <MeshRenderer>(); if (iconRenderer == null) { Debug.LogWarning("Missing MeshRenderer on CompoundButtonIcon.IconMeshFilter attached to " + button.name); return; } // using material, not sharedMaterial, deliberately: we only change color of this material instance Color newColor = active ? ButtonActiveColor : ButtonInactiveColor; //Debug.Log("changing color of " + button.name + " to " + newColor.ToString()); // both _EmissiveColor and _Color (Albedo in editor) should be set to make proper effect. iconRenderer.material.SetColor("_EmissiveColor", newColor); iconRenderer.material.SetColor("_Color", newColor); }
public override void OnInspectorGUI() { AppBar appBar = (AppBar)target; appBar.DisplayType = (AppBar.AppBarDisplayTypeEnum)EditorGUILayout.EnumPopup("Display Type", appBar.DisplayType); if (appBar.DisplayType == AppBar.AppBarDisplayTypeEnum.Manipulation) { HUXEditorUtils.BeginSectionBox("Bounding box"); appBar.BoundingBox = HUXEditorUtils.SceneObjectField <BoundingBoxManipulate>(null, appBar.BoundingBox); if (appBar.BoundingBox == null) { HUXEditorUtils.WarningMessage("Manipulation state will not function correctly at runtime without a bounding box. (If you're using BoundingBoxTarget this is not a problem.)"); } HUXEditorUtils.EndSectionBox(); } HUXEditorUtils.BeginSectionBox("App bar options"); appBar.HoverOffsetYScale = EditorGUILayout.Slider("Hover Offset (Y)", appBar.HoverOffsetYScale, -1f, 2f); appBar.HoverOffsetZ = EditorGUILayout.Slider("Hover Offset (Z)", appBar.HoverOffsetZ, 0f, 2f); appBar.SquareButtonPrefab = (GameObject)EditorGUILayout.ObjectField("Button Prefab", appBar.SquareButtonPrefab, typeof(GameObject)); GUI.color = (appBar.CustomButtonIconProfile == null) ? HUXEditorUtils.DisabledColor : HUXEditorUtils.DefaultColor; appBar.CustomButtonIconProfile = (ButtonIconProfile)EditorGUILayout.ObjectField("Custom Icon Profile", appBar.CustomButtonIconProfile, typeof(ButtonIconProfile)); HUXEditorUtils.DrawSubtleMiniLabel("(Leave blank to use the button's default profile)"); GUI.color = HUXEditorUtils.DefaultColor; if (appBar.SquareButtonPrefab == null) { HUXEditorUtils.ErrorMessage("You must specify a button prefab"); HUXEditorUtils.EndSectionBox(); return; } CompoundButtonIcon icon = appBar.SquareButtonPrefab.GetComponent <CompoundButtonIcon>(); if (icon == null) { HUXEditorUtils.ErrorMessage("You must use a button prefab that has a CompoundButtonIcon component"); HUXEditorUtils.EndSectionBox(); return; } HUXEditorUtils.BeginSubSectionBox("Default buttons"); GUI.color = appBar.UseHide ? HUXEditorUtils.DefaultColor : HUXEditorUtils.DisabledColor; appBar.UseHide = EditorGUILayout.Toggle("Show / Hide Buttons", appBar.UseHide); GUI.color = appBar.UseAdjust ? HUXEditorUtils.DefaultColor : HUXEditorUtils.DisabledColor; appBar.UseAdjust = EditorGUILayout.Toggle("Adjust / Done Buttons", appBar.UseAdjust); GUI.color = appBar.UseRemove ? HUXEditorUtils.DefaultColor : HUXEditorUtils.DisabledColor; appBar.UseRemove = EditorGUILayout.Toggle("Remove Button", appBar.UseRemove); GUI.color = HUXEditorUtils.DefaultColor; HUXEditorUtils.EndSubSectionBox(); HUXEditorUtils.BeginSubSectionBox("Custom buttons"); HUXEditorUtils.DrawSubtleMiniLabel("Up to " + AppBar.MaxCustomButtons + " allowed. Un-named buttons will be ignored."); //HUXEditorUtils.DrawProfileField <ButtonIconProfile> (appBar.CustomButtonIconProfile) // Get the profile we'll be using for our icons ButtonIconProfile profile = appBar.CustomButtonIconProfile; if (profile == null) { profile = icon.Profile; if (profile == null) { HUXEditorUtils.ErrorMessage("The button prefab does not specify an icon profile. Can't continue."); HUXEditorUtils.EndSectionBox(); return; } } AppBar.ButtonTemplate[] buttons = appBar.Buttons; if (buttons.Length != AppBar.MaxCustomButtons) { System.Array.Resize <AppBar.ButtonTemplate>(ref buttons, AppBar.MaxCustomButtons); } int numCustomButtons = appBar.UseHide ? 0 : -1; for (int i = 0; i < buttons.Length; i++) { buttons[i] = DrawButtonEditor(buttons[i], profile, ref numCustomButtons, "buttons", i); } appBar.Buttons = buttons; HUXEditorUtils.EndSubSectionBox(); // Force the buttons to refresh based on the options we've specified appBar.EditorRefreshTemplates(); HUXEditorUtils.BeginSubSectionBox("App bar preview"); HUXEditorUtils.DrawSubtleMiniLabel("An approximation of what the final bar will look like. 'Hidden' and 'Manipulation' states depend on default button settings and may not be available."); previewState = (AppBar.AppBarStateEnum)EditorGUILayout.EnumPopup(previewState); List <AppBar.ButtonTemplate> buttonList = new List <AppBar.ButtonTemplate>(); buttonList.AddRange(appBar.DefaultButtons); buttonList.AddRange(buttons); if (previewState == AppBar.AppBarStateEnum.Default) { buttonList.Sort(delegate(AppBar.ButtonTemplate b1, AppBar.ButtonTemplate b2) { return(b1.DefaultPosition.CompareTo(b2.DefaultPosition)); }); } else { buttonList.Sort(delegate(AppBar.ButtonTemplate b1, AppBar.ButtonTemplate b2) { return(b1.ManipulationPosition.CompareTo(b2.ManipulationPosition)); }); } scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, false, false, GUILayout.MaxHeight(previewButtonSize + 15f)); EditorGUILayout.BeginHorizontal(); bool drewOneButton = false; for (int i = 0; i < buttonList.Count; i++) { drewOneButton |= DrawPreviewButton(buttonList[i], previewState, appBar.UseHide, appBar.UseAdjust, appBar.UseRemove); } if (!drewOneButton) { HUXEditorUtils.WarningMessage("This state has no buttons due to the options you've chosen. It won't be permitted during play mode."); } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndScrollView(); HUXEditorUtils.EndSubSectionBox(); HUXEditorUtils.EndSectionBox(); HUXEditorUtils.SaveChanges(appBar); }
void ClickToOpen() { CompoundButtonIcon iconButton = (CompoundButtonIcon)target; UnityEditor.Selection.activeObject = iconButton.Profile; }
public override void OnInspectorGUI() { CompoundButtonIcon iconButton = (CompoundButtonIcon)target; iconButton.DisableIcon = EditorGUILayout.Toggle("Disable icon", iconButton.DisableIcon); if (iconButton.DisableIcon) { HUXEditorUtils.SaveChanges(target); return; } profileProp.objectReferenceValue = HUXEditorUtils.DrawProfileField <ButtonIconProfile>(profileProp.objectReferenceValue as ButtonIconProfile); //iconButton.Profile = HUXEditorUtils.DrawProfileField<ButtonIconProfile>(iconButton.Profile); if (iconButton.Profile == null) { HUXEditorUtils.SaveChanges(target); return; } HUXEditorUtils.BeginSectionBox("Icon settings"); if (UnityEditor.Selection.gameObjects.Length == 1) { iconButton.IconRenderer = HUXEditorUtils.DropDownComponentField <MeshRenderer>("Icon renderer", iconButton.IconRenderer, iconButton.transform); if (iconButton.IconRenderer == null) { HUXEditorUtils.ErrorMessage("You must specify an icon renderer", null); HUXEditorUtils.EndSectionBox(); HUXEditorUtils.SaveChanges(target); return; } if (iconButton.Profile.IconMaterial == null) { HUXEditorUtils.ErrorMessage("You must specify an icon material in the profile", null); HUXEditorUtils.EndSectionBox(); HUXEditorUtils.SaveChanges(target); return; } if (iconButton.Profile.IconMesh == null) { HUXEditorUtils.ErrorMessage("You must specify an icon mesh in the profile", null); HUXEditorUtils.EndSectionBox(); HUXEditorUtils.SaveChanges(target); return; } // Icon profiles provide their own fields for the icon name iconButton.Alpha = EditorGUILayout.Slider("Icon transparency", iconButton.Alpha, 0f, 1f); iconButton.IconName = iconButton.Profile.DrawIconSelectField(iconButton.IconName); } else { EditorGUILayout.LabelField("(This section not supported for multiple objects)", EditorStyles.miniLabel); } HUXEditorUtils.EndSectionBox(); HUXEditorUtils.DrawProfileInspector(iconButton.Profile, iconButton); // Check to see if the icon is valid - if it's not, show the placeholder /*Texture2D icon = iconButton.IconRenderer.sharedMaterial.mainTexture as Texture2D; * if (icon == null || icon == iconButton.IconProfile._IconNotFound_) * { * HUXEditorUtils.WarningMessage( * "Texture '" + iconButton.IconName + "' was not found in the selected profile. A substitute will be displayed until an icon file has been added to the profile.", * "Click to open profile", * ClickToOpen); * }*/ HUXEditorUtils.SaveChanges(iconButton, iconButton.Profile); serializedObject.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { SimpleMenuCollection menu = (SimpleMenuCollection)target; HUXEditorUtils.BeginSectionBox("Menu settings"); menu.DisplayTitle = EditorGUILayout.Toggle("Display Title", menu.DisplayTitle); if (menu.DisplayTitle) { //menu.TitleText.font = (Font)EditorGUILayout.ObjectField("Title font", menu.TitleText.font, typeof(Font), false); menu.Title = EditorGUILayout.TextArea(menu.Title); menu.TitleText = HUXEditorUtils.DropDownComponentField <TextMesh>("Title TextMesh", menu.TitleText, menu.transform); } menu.DisplaySubtitle = EditorGUILayout.Toggle("Display Subtitle", menu.DisplaySubtitle); if (menu.DisplaySubtitle) { //menu.TitleText.font = (Font)EditorGUILayout.ObjectField("Title font", menu.TitleText.font, typeof(Font), false); menu.Subtitle = EditorGUILayout.TextArea(menu.Subtitle); menu.SubtitleText = HUXEditorUtils.DropDownComponentField <TextMesh>("Subtitle TextMesh", menu.SubtitleText, menu.transform); } menu.ButtonPrefab = (GameObject)EditorGUILayout.ObjectField("Button prefab", menu.ButtonPrefab, typeof(GameObject), false); menu.ParentCollection = HUXEditorUtils.DropDownComponentField <ObjectCollection>("Collection parent", menu.ParentCollection, menu.transform); if (menu.ButtonPrefab == null) { HUXEditorUtils.ErrorMessage("You must specify a button prefab"); HUXEditorUtils.EndSectionBox(); return; } if (menu.ParentCollection == null) { HUXEditorUtils.ErrorMessage("This menu needs a collection component to work", AddCollection, "Fix"); HUXEditorUtils.EndSectionBox(); return; } bool showIcon = false; bool showText = false; CompoundButtonIcon icon = menu.ButtonPrefab.GetComponent <CompoundButtonIcon>(); showIcon = icon != null; CompoundButtonText text = menu.ButtonPrefab.GetComponent <CompoundButtonText>(); showText = text != null; ButtonIconProfile profile = null; if (icon != null) { profile = icon.IconProfile; } HUXEditorUtils.BeginSubSectionBox("Buttons"); HUXEditorUtils.DrawSubtleMiniLabel("Up to " + SimpleMenuCollection.MaxButtons + " allowed. Un-named buttons will be ignored."); SimpleMenuCollectionButton[] buttons = menu.Buttons; HashSet <string> buttonNamesSoFar = new HashSet <string>(); int numButtons = 0; for (int i = 0; i < buttons.Length; i++) { if (!buttons[i].IsEmpty) { numButtons++; } DrawButtonEditor(buttons[i], showIcon, showText, profile, "buttons", i, buttonNamesSoFar); } HUXEditorUtils.EndSubSectionBox(); menu.EditorRefreshButtons(); HUXEditorUtils.BeginSubSectionBox("Menu preview"); HUXEditorUtils.DrawSubtleMiniLabel("An approximation of what the menu will look like."); List <SimpleMenuCollectionButton> buttonsList = new List <SimpleMenuCollectionButton>(buttons); buttonsList.Sort(delegate(SimpleMenuCollectionButton b1, SimpleMenuCollectionButton b2) { return(b1.Index.CompareTo(b2.Index)); }); scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, false, false, GUILayout.MinHeight(previewButtonSizeY * numButtons + 50f)); EditorGUILayout.BeginVertical(); bool drewOneButton = false; foreach (SimpleMenuCollectionButton button in buttonsList) { drewOneButton |= DrawPreviewButton(button, showText); } if (!drewOneButton) { HUXEditorUtils.WarningMessage("This state has no buttons due to the options you've chosen. It won't be permitted during play mode."); } EditorGUILayout.EndVertical(); EditorGUILayout.EndScrollView(); HUXEditorUtils.EndSubSectionBox(); HUXEditorUtils.EndSectionBox(); HUXEditorUtils.SaveChanges(menu); }
public override void OnInspectorGUI() { ButtonIconProfileTexture iconProfile = (ButtonIconProfileTexture)target; CompoundButtonIcon iconButton = (CompoundButtonIcon)targetComponent; HUXEditorUtils.BeginProfileBox(); HUXEditorUtils.BeginSectionBox("Material & mesh properties"); iconProfile._IconNotFound_ = (Texture2D)EditorGUILayout.ObjectField("Icon not found texture", iconProfile._IconNotFound_, typeof(Texture2D), false, GUILayout.MaxHeight(35f), GUILayout.MaxHeight(35f)); iconProfile.IconMesh = (Mesh)EditorGUILayout.ObjectField("Icon mesh", iconProfile.IconMesh, typeof(Mesh), false); iconProfile.IconMaterial = (Material)EditorGUILayout.ObjectField("Icon material", iconProfile.IconMaterial, typeof(Material), false); iconProfile.AlphaColorProperty = HUXEditorUtils.MaterialPropertyName(iconProfile.AlphaColorProperty, iconProfile.IconMaterial, ShaderUtil.ShaderPropertyType.Color, false); iconProfile.AlphaTransitionSpeed = EditorGUILayout.Slider("Alpha Transition Speed", iconProfile.AlphaTransitionSpeed, 0f, 2f); HUXEditorUtils.EndSectionBox(); HUXEditorUtils.BeginSectionBox("Textures defined in profile"); if (iconButton == null || showTextures) { var properties = iconProfile.GetType().GetFields(); foreach (var property in properties) { if (property.FieldType == typeof(Texture2D) && !property.Name.StartsWith("_")) { Texture2D iconVal = (Texture2D)property.GetValue(iconProfile); iconVal = (Texture2D)EditorGUILayout.ObjectField(property.Name, iconVal, typeof(Texture2D), false, GUILayout.MaxHeight(textureSize)); property.SetValue(iconProfile, iconVal); } } HUXEditorUtils.EndSectionBox(); HUXEditorUtils.BeginSectionBox("Custom texture array"); if (GUILayout.Button("Add custom icon")) { System.Array.Resize <Texture2D>(ref iconProfile.CustomIcons, iconProfile.CustomIcons.Length + 1); } for (int i = 0; i < iconProfile.CustomIcons.Length; i++) { Texture2D icon = iconProfile.CustomIcons[i]; icon = (Texture2D)EditorGUILayout.ObjectField(icon != null ? icon.name : "(Empty)", icon, typeof(Texture2D), false, GUILayout.MaxHeight(textureSize)); iconProfile.CustomIcons[i] = icon; } if (iconButton != null) { if (GUILayout.Button("Hide icon textures")) { showTextures = false; } } } else { if (GUILayout.Button("Show icon textures")) { showTextures = true; } } HUXEditorUtils.EndSectionBox(); HUXEditorUtils.EndProfileBox(); HUXEditorUtils.SaveChanges(target, serializedObject); }