Button in edit view in Unity - button

I'd like to know if there is a way to add a button in scene view when in edit mode in unity.
I'd like to choose an option from the gameobject menu and then deactivate it when the button on scene is clicked (before pressing run)
Is this possible please?

I think you are asking about Unity3D game engine. Well, by means of Editor scripts you can add a button in Editor mode. For example:
using UnityEngine;
using UnityEditor;
using System.Collections;
public class LevelChunksAnalyser : MonoBehaviour {
[MenuItem("Level Chunks/Update Metadata")]
public static void UpdateLevelChunksMetadata()
{
Debug.Log("Yo");
}
}

Related

Image Button for Xamarin.MacOS

Is there an Image Button Renderer in Xamarin.MacOS?
I am using Xamarin.Forms and all my image buttons in the common code are not shown at all in Xamarin.MacOS. Is Image Button supported in Xamarin.MacOS?
Is there an Image Button Renderer in Xamarin.MacOS?
Unfortunately, after checking the source code of Xamarin.Forms.Platform.macOS, there is no ImageButtonRenderer there now. I guess the reason that there is no control is the similar with ImageButton. I'm not sure whehter designer will add this in the future. Whatever, now it not exists.
Is Image Button supported in Xamarin.MacOS?
From the above said, MacOS has no control like ImageButton of Forms. Therefore, if used ImageButton in Xamarin Froms, it will not show in Xamarin.MacOS.
However, there is a workaround. You could use Button in Forms, and add Image in ButtonRenderer in Xamarin.MacOS. Because NSButton has a Image property.
For example, the code of ButtonRenderer as follows:
[assembly: ExportRenderer (typeof(MyButton), typeof(MyButtonRenderer))]
namespace CustomRenderer.MacOS
{
public class MyButtonRenderer : ButtonRenderer
{
protected override void OnElementChanged (ElementChangedEventArgs<Button> e)
{
base.OnElementChanged (e);
if (Control != null) {
// do whatever you want to the UITextField here!
Control.Image= NSImage.ImageNamed("tree")
Control.ImageScaling = NSImageScale.AxesIndependently;
}
}
}
}
The image source (tree.png) is the same way with iOS to be added in Resource folder, and set Propertied : Build Action -> BundleResource.

Image tint Button Android Xamarin Forms

I try to create a CustomRenderer for Android inherit to ButtonRenderer with an Image. I want change color of Image programmatically like TintColor on iOS.
For example, my CustomRenderer iOS :
public class IconButtonRenderer : ButtonRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
base.OnElementChanged(e);
var button = e.NewElement;
}
public override void Draw(CoreGraphics.CGRect rect)
{
base.Draw(rect);
// Here I change color of Image in Red.
Control.ImageView.Image = Control.ImageView.Image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);
Control.ImageView.TintColor = UIColor.Red;
}
}
On Android:
Control is an Android.Widget.Button and not have Image property but Xamarin.Forms.Button has property Image and use Android.Widget.Button for Android.
How I can access image with format Android for change color?
Image tint Button Android Xamarin Forms
Orignal Image
Solution 1 :
As #Mathias Kirkegaard said, in your ButtonRenderer you could use SetColorFilter to change color :
Control.Background.SetColorFilter(Android.Graphics.Color.Blue, PorterDuff.Mode.SrcIn);
It did work in native Android, but has some problem in Xamarin.Forms, it only changes the Button background color like this: effect. Hope someone could find a solution, and if I find a solution to solve this issue I will come back and update my answer.
Solution 2 :
You could use the plugin : Tinted Image and add a click event to implement the same feature.
Install the Plugin.CrossPlatformTintedImage nuget package
Initialize the renderer in your iOS, Android, and UWP projects as shown below:
Xamarin.Forms.Init();
TintedImageRenderer.Init();
In Xaml:
<ContentPage
...
xmlns:controls="clr-namespace:Plugin.CrossPlatformTintedImage.Abstractions;assembly=Plugin.CrossPlatformTintedImage.Abstractions"
...>
...
<controls:TintedImage x:Name="buttonImage" TintColor="Blue" Source="redDis.png"/>
...
</ContentPage>
In code, Adding a Tap Gesture Gesture Recognizer :
var tapGestureRecognizer = new TapGestureRecognizer();
tapGestureRecognizer.Tapped += (s, e) =>
{
// handle the tap
};
buttonImage.GestureRecognizers.Add(tapGestureRecognizer);
Effect after adding a click event on Tinted Image
Solution 3 :
If you need to use ImageButton, you could refer to this solution. I didn't test it but you could use the ImageButton from XLab.
XLab ImageButton Source code
XLab ImageButtonRenderer Source code
On a button you can use "SetColorFilter(color)"
You might be able to get the color using the ContextCompat:
var color = new Color(ContextCompat.GetColor(Context, Resource.Color.Green));
and then apply it:
yourButton.SetColorFilter(color)
Not sure whether you need to use an ImageButton rather than a simple Button.

Adding a button to a dialog

Are AX dialog buttons limited to OK and Cancel?
Is it possible to add a custom button to the dialog?
I have the following code for my dialog:
static void mitTabPage(Args _args)
{
Dialog dialog;
DialogGroup dialoggroup, dialoggroup2;
DialogField dialogfield, dialogfield2;
;
dialog = new Dialog ("A new Dialog");
dialog.addTabPage("Brand Id's");
dialoggroup = dialog.addGroup("Brand Id's");
dialogfield = dialog.addField(extendedTypeStr(SYCCarBrandId));
dialog.addTabPage("Owners");
dialoggroup2 = dialog.addGroup("Owners");
dialogfield2 = dialog.addField(extendedTypeStr(SYCOwner));
dialog.run();
}
I'd like to add another button to the dialog. How can I do that?
The Dialog framework is a simple framework for prompting users to obtain some data/settings then performing some action or canceling.
For what you're trying to do, it most likely doesn't make sense to use the dialog framework and instead you could/should create another form if you need additional functionality.
However, if you do insist on using the Dialog framework for this, you would add a runtime button and use registerOverrideMethod.
See following links:
https://msdn.microsoft.com/en-us/library/dialogfield.registeroverridemethod.aspx
https://blogs.msdn.microsoft.com/axsupport/2015/06/07/using-x-to-add-a-control-at-runtime/

Android TV: Disable collapsing on info_field on ImageCardView

I'm working with Android TV for the first time and I'm learning to use Leanback by modifying the example tv app that is provided.
The issue I'm having is that when I press left on the first item in the lists the navigation drawer opens and focus goes to the headers in the navigation drawer. When this happens, the info_field view in the ImageCardViews collapse behind the image.
What happens: The info field on the ImageCardView hides when I open the navigation drawer.
What I want to Happen: The info field remains visible when I open the navigation drawer.
I'm sure there's a way to do this because I've seen it in some Android TV apps, like Twitch. What's the best way to have the info_field visible when the navigation drawer is open?
I've worked out how to do it. In the CardPresenter, in onCreateViewHolder, when creating the ImageCardView I've overridden the BaseCardView method, setActivated(boolean activated) to always pass 'true' into it's super. And then call setActivated so that it's activated from the beginning. Like this:
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
ImageCardView cardView = new ImageCardView(parent.getContext()) {
#Override
public void setActivated(boolean activated) {
super.setActivated(true);
}
#Override
public void setSelected(boolean selected) {
updateCardBackgroundColor(this, selected);
super.setSelected(selected);
}
};
cardView.setActivated(true);
cardView.setFocusable(true);
cardView.setFocusableInTouchMode(true);
return new ViewHolder(cardView)
}
So that did the trick for me. The ImageCardView never collapses.
I think if you look at this SO post you'll get most of the way there. The info view hides due to what leanback calls "expanding".
Try just calling enableMainFragmentScaling(false); in your BrowseFragment and see if that does what you want. If it doesn't feel like exactly what you want, refer to the post I linked to.
Additionally, if you've tried what I recommend in the linked SO post, you could also call the API on the BaseCardView setInfoVisibility() and pass it CARD_REGION_VISIBLE_ALWAYS. This just requires calling on a reference to your card which shouldn't need an override of the Presenter or Card.

Unity 4.6 hide / unhide button using C# script

I've been working on a project in Unity 4.6 where it is necessary to hide and unhide buttons using C# script. Does anyone have an example on how to do this?
When a gameObject or component is set to inactive using SetActive(false) you cannot use any of the "Find" or "GetComponent" type functions. The only way you can reactivate the gameobject or component is to have a reference to it.
In your project could you store the keys in a list or array on startup? you could then iterate through the collection and reactive the disabled keys as needed.
If you want to show/hide a GUI object, and don't want to disable it just
Add CanvasGroup to the object
Set its alpha to 1 or 0 for show/hide CanvasGroup: GetComponent<CanvasGroup>().alpha = 1;
using UnityEngine;
using UnityEngine.UI;
public class Showandhide : MonoBehaviour {
public GameObject button;//assign the button object here
private bool isShowing;
void Update()
{
if (Input.GetKeyDown("escape"))
{
isShowing = !isShowing;
button.SetActive(isShowing);
}
}
}

Resources