Unity 4.6 hide / unhide button using C# script - button

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);
}
}
}

Related

How to execute a platform (Android) specific method within a ButtonOnClick() using a Xamarin.Forms custom renderer.

Introduction:
I am starting with code from:
https://github.com/xamarin/xamarin-forms-samples/tree/master/CustomRenderers/Entry/Android
to study custom renderers. I am doing this because there is code that only executes on the android platform. Lets call this "androidMethod()" and belongs in the Android codebase (not the shared library). I have noticed that most of the examples I have found have utilized customRenderers for making platform specific UI modifications (like the example in the link) but I intend to make no changes to the UI, rather I am trying to place a platform specific method in a Xamarin.Forms ButtonOnClick() method as the code below indicates.
The code below is similar to the code you will find in the MyEntryRenderer.cs from the link but you will see that it was modified to apply to a button instead of an entry.
MyButtonRenderer.cs:
using Xamarin.Forms.Platform.Android;
using Xamarin.Forms;
using CustomRenderer;
using CustomRenderer.Android;
using Android.Content;
[assembly: ExportRenderer(typeof(MyButton), typeof(MyButtonRenderer))]
namespace CustomRenderer.Android
{
class MyButtonRenderer : ButtonRenderer
{
private Button androidButton;
public MyButtonRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
base.OnElementChanged(e);
if (Control != null)
{
//I want to be able to do something like this:
ButtonOnClick(androidMethod());
}
}
}
}
How do I get androidMethod(); to execute in this context. The samples I find are limited so please try to limit your response to something that would be compatible with the example. Thankyou!
if you want to execute a platform specific method, I would use DepenencyService instead of a Custom Renderer

dialogPostRun method in RunBaseReport

I have a RunBaseReport which contains overrided dialog method where I'm adding couple of my controls. One of those controls is a combobox.
Controls enabled() property should be changed when I'm modifying combobox.
So basically I need to know when the value of my dfReportType dialog field changes.
public Object dialog(Object dialog)
{
DialogRunbase dialog = dialog;
;
//adding my combobox
dfReportType = dialog.addFieldValue(typeid(ReportType), ReportType:DefaultType);
//adding some other controls here
return dialog;
}
According to many articles that I found I need to override dialogPostRun Method and do something like this:
public void dialogPostRun(DialogRunbase dialog)
{
super(dialog);
dialog.dialogForm().formRun().controlMethodOverload(true);
dialog.dialogForm().formRun().controlMethodOverloadObject(this);
}
But unfortunately I don't have this method in RunBaseReport class.
Which should be there according to msdn .
Are there any other workarounds?
I'm currently on AX 2012 but I still looked at it. I have the method available in the context menu, but not on the first column. I have to go over "Plus..." to find the method in the second column.
Well, there is no dialogPostRun method in Report object that inherits RunBaseReport, but we have this method in Class that inherits RunBaseReport.
So that was my mistake. I used report object instead of class.
If you want to make custom dialog for the report but you also want to use all default controls you should:
Create class
Inherit RunBaseReport
Override dialog, getFromDialog etc.
Override lastValueElementName method
public identifiername lastValueElementName()
{
//just put name of your report object
return reportStr(YourReportName);
}
Don't forget to add main() method if you going to make call from menuItem.

Activating/Deactivating GameObject Not Working

I can't seem to get my button to activate gameobject. At the moment, I have the gameobject deactivating in the scene, but my button doesn't activate the gameobject. What am I'm missing in my coding? The script is currently not attach to the gameobject.
#pragma strict
public var myObject :GameObject;
if (GUI.Button(new Rect(1120,930,100,50),"3D OBJECT"))
{
myObject.SetActive(true);
}
I dont understand your question well but,
first of all if you want to use GUI you must do it in OnGUI function.
Like:
function OnGUI () {
if (GUI.Button(new Rect(1120,930,100,50),"3D OBJECT"))
{
myObject.SetActive(true);
}
}
By the way i strongly recommend you that: Use Unity UI for GUI purposes.

Button in edit view in Unity

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");
}
}

Animate busy cursor in flex?

I find out how to replace the busy cursor here: http://livedocs.adobe.com/flex/3/html/cursormgr_3.html
However, how do you animate an image for the cursor?
Use an animated asset created in the Flash IDE and embed it within your Flex app.
You can also create them programmatically, e.g. by extending flash.display.Sprite:
Class SampleCursor:
public class SampleCursor extends Sprite
public function SampleCursor() {
addEventListener(Event.ENTER_FRAME, drawCursor);
}
public function drawCursor(e:Event):void {
// Draw cursor using graphics context
// ...
}
{
And in your Application you just register this class as a cursor (same for other types of cursors like bitmap or flash assets):
cursorManager.removeAllCursors();
cursorManager.setCursor(SampleCursor);
Hope that helps.

Resources