unity – Render Mode "Screen Space – Camera" inflates the prefabricated buttons so that they no longer fit on the canvas, help

When referring to a previous publication (link) and when using the solution, I found a situation that I do not understand when when I set the canvas in "Screen space – Camera" instead of "Screen space – Overlay" as it has Having set the original post, my buttons in the context menu inflate to a size that is larger than the canvas itself. I try to manually change the size of the prefabricated button to a reasonable size, however, it seems that the width will not allow me to modify it. And changing the rendering to Overlay itself will require a good amount of reworking of existing assets for things to work properly.

So my question is this, what does it take to keep the "Screen space – Camera" as the rendering mode, but still have the size of the buttons accordingly?

Paste previous content for reference:

Create content panel
(This panel will be a container for our context menu buttons)

Create new UI panel
Set the anchor in the lower left
Set the width to 300 (as desired)
Add a new Vertical Design Group component to a panel and set Secondary alignment in the upper center, Expand secondary force to width (not height)
Add a new Content Size Fitter component to a panel and set Vertical Fit to Min Size
Save it as prefabricated
(At this point, our Panel will be reduced to one line. It is normal. This panel will accept buttons as secondary elements, align them vertically and stretch to the height of the summary content)

Create sample button
(This button will be instantiated and customized to show context menu items)

Create new UI button

Set the anchor in the upper left corner
Add a new component Design element to a button, set Minimum height to 30, Preferred height to 30

Save it as prefabricated

Create ContextMenu.cs script

(This script has a method that creates and displays the context menu)

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

(System.Serializable)
public class ContextMenuItem
{
    // this class - just a box to some data

    public string text;             // text to display on button
    public Button button;           // sample button prefab
    public Action action;    // delegate to method that needs to be executed when button is clicked

    public ContextMenuItem(string text, Button button, Action action)
    {
        this.text = text;
        this.button = button;
        this.action = action;
    }
}

public class ContextMenu : MonoBehaviour
{
    public Image contentPanel;              // content panel prefab
    public Canvas canvas;                   // link to main canvas, where will be Context Menu

    private static ContextMenu instance;    // some kind of singleton here

    public static ContextMenu Instance
    {
        get
        {
            if(instance == null)
            {
                instance = FindObjectOfType(typeof(ContextMenu)) as ContextMenu;
                if(instance == null)
                {
                    instance = new ContextMenu();
                }
            }
            return instance;
        }
    }

    public void CreateContextMenu(List items, Vector2 position)
    {
        // here we are creating and displaying Context Menu

        Image panel = Instantiate(contentPanel, new Vector3(position.x, position.y, 0), Quaternion.identity) as Image;
        panel.transform.SetParent(canvas.transform);
        panel.transform.SetAsLastSibling();
        panel.rectTransform.anchoredPosition = position;

        foreach(var item in items)
        {
            ContextMenuItem tempReference = item;
            Button button = Instantiate(item.button) as Button;
            Text buttonText = button.GetComponentInChildren(typeof(Text)) as Text;
            buttonText.text = item.text;
            button.onClick.AddListener(delegate { tempReference.action(panel); });
            button.transform.SetParent(panel.transform);
        }
    }
}

Attach this script to a Canvas and complete the fields. Drag and drop the prefabricated ContentPanel to the corresponding space, and drag Canvas to the Canvas slot.

Create ItemController.cs script

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class ItemController : MonoBehaviour
{
    public Button sampleButton;                         // sample button prefab
    private List contextMenuItems;     // list of items in menu

    void Awake()
    {
        // Here we are creating and populating our future Context Menu.
        // I do it in Awake once, but as you can see, 
        // it can be edited at runtime anywhere and anytime.

        contextMenuItems = new List();
        Action equip = new Action(EquipAction);
        Action use = new Action(UseAction);
        Action drop = new Action(DropAction);

        contextMenuItems.Add(new ContextMenuItem("Equip", sampleButton, equip));
        contextMenuItems.Add(new ContextMenuItem("Use", sampleButton, use));
        contextMenuItems.Add(new ContextMenuItem("Drop", sampleButton, drop));
    }

    void OnMouseOver()
    {
        if(Input.GetMouseButtonDown(1))
        {
            Vector3 pos = Camera.main.WorldToScreenPoint(transform.position);
            ContextMenu.Instance.CreateContextMenu(contextMenuItems, new Vector2(pos.x, pos.y));
        }

    }

    void EquipAction(Image contextPanel)
    {
        Debug.Log("Equipped");
        Destroy(contextPanel.gameObject);
    }

    void UseAction(Image contextPanel)
    {
        Debug.Log("Used");
        Destroy(contextPanel.gameObject);
    }

    void DropAction(Image contextPanel)
    {
        Debug.Log("Dropped");
        Destroy(contextPanel.gameObject);
    }
}

Create a sample object in the scene (i.e., Cube), place it to be visible to the camera and attach this script to it. Drag and drop prebuilt sampleButton to the corresponding slot.

Website design: should visitors see all links and buttons (which only registered users can use)?

We are developing a website that requires registration to use some functions.

My friend thinks that visitors (unregistered users) should not even see the links for those functions, because it is confusing.

I think they should see the links and, when clicked, they should be redirected to the login / registration page, because it will encourage them to register.

What is the best way to handle this?

Forms – Alternatives to check boxes and radio buttons in web-based surveys?

The challenge with your suggestion for the replacement of check boxes and radio boxes is that there is no visual distinction between the two types of behaviors. The best user interface design always sets the user's expectations BEFORE they have to interact with the control. I still don't have enough representative to comment on erikrojo's answer, but that certainly has the benefit of taking advantage of the familiar idiomatic expressions, while enjoying a larger hit zone.

A slider, as Glen suggests, has the benefit of modeling itself in real-world user touch interfaces that can have only one state at a time: there is no ambiguity, as is the case with radio buttons. Unfortunately, the slider also comes with its own implementation and usability challenges, and it is much harder to design in the context of a form with a diverse set of control.

A dial is a variant of a slider that is better integrated into a design (usually more compact), with a significant usability impact (the movement of the control is rotary, but the user's mouse input tends to be axonometric, and this can lead to confusion between different implementations)

A different approach could be to design an additional component for single-selection and multi-selection controls that accurately inform the user of how many selections he has available to make. I will try to explain the visual using elements from the real world, and then I could abstract it into a digital representation in any way I want. Consider a bank of light bulbs. If I have 5 possible answers, and I can select all, some or none, then I have 5 bulbs, all of them lit. When I click on my answer buttons (not on the bulbs, they are not directly interactible) a light bulb goes out and the button I clicked is selected. As I continue to select additional responses, more bulbs go out.

Continuing with this concept, if I have a multiple choice and single answer question, then there is only one bulb in the bank. From the beginning, I am clear that I receive an answer.

Obviously, the use of light bulbs on its interface will look silly (or maybe not?), But the idea is understood: we set expectations immediately on how many selections / answers the user will be allowed to ask for each question. A disadvantage of this approach would be that the user may feel that he has to "use" all his options before continuing. This could be easily mitigated by making it clear that after the user has made his first selection (even if multiple answers are possible), the next question becomes active or available. This could be done in many ways, from disabling / hiding the next question, to simply displaying a check mark or other indicator that the requirements for the current question have been met.

unit: use of a timer together with two Arduino input buttons

newbie here

So I am using two buttons (connected to an Arduino Uno) as input for my game. The player has to press both buttons at the same time for the character to move in the game. I want the player to press and hold the buttons for a different time in each level. I have a working Arduino and a working Unity timer and a player script, but I can't get the code to do what I want.

Please help anyway

The Arduino code:

#include
#include 

const int ledPin = 13; // choose the pin for the LED
const int button1 = 2; // choose the input pin (for 1st pushbutton)
const int button2 = 3; // choose the input pin (for 2nd pushbutton)


  int ledState = LOW;         // the current state of the output pin
  int buttonState;             // the current reading from the input pin
  int lastButtonState = HIGH;   // the previous reading from the input pin
  unsigned long lastDebounceTime = 0;  // the last time the output pin was toggled
  unsigned long debounceDelay = 50;    // the debounce time; increase if the output flickers
void setup() 
{
  Serial.begin(9600); // Start the serial transmission
  digitalWrite(ledPin, ledState);
  pinMode(ledPin, OUTPUT); // declare LED as output
  pinMode(button1, INPUT); // declare pushbutton as input
  pinMode(button2, INPUT); // declare pushbutton as input

}

void loop()
{
  int valA = digitalRead(button1); // read button stateint 
 int  valB = digitalRead(button2); // read button state
   if (valA == LOW &&valB == LOW ) // check if the input is HIGH for both buttons -this can be changed to ||(or) or !(not)
  {
    digitalWrite(ledPin, HIGH); // turn LED on if both switches are pressed
    Serial.println("0");
      delay(20);
  }
    else
    {
      digitalWrite(ledPin, LOW); // turnLED off}}
      Serial.println("1");
    }
 int reading = digitalRead(INPUT);
 if (reading != lastButtonState) {

    lastDebounceTime = millis();
  }

  if ((millis() - lastDebounceTime) > debounceDelay) {

    if (reading != buttonState) {
      buttonState = reading;


      if (buttonState == LOW) {
        ledState = !ledState;
      }
    }
  }


  digitalWrite(ledPin, ledState);


  lastButtonState = reading;
}

The timer script:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class Timer : MonoBehaviour
{
    Image timerBar;
    //public int maxTime = 5;
    public int timeLeft;
    public Text countdownText;

    // Use this for initialization
    void Start()
    {
        StartCoroutine("LoseTime");
        timerBar = GetComponent();
    }

    // Update is called once per frame
    void Update()
    {
        countdownText.text = ("Time Left = " + timeLeft);

        if (timeLeft <= 0)
        {
            //StopCoroutine("LoseTime");
            //countdownText.text = "Times Up!";
            Invoke("ChangeLevel", 0.1f);
        }
       /* else if (timeLeft > 0)
        {
            timerBar.fillAmount = timeLeft / maxTime;
        }*/

    }

    IEnumerator LoseTime()
    {
        while (true)
        {
            yield return new WaitForSeconds(1);
            timeLeft--;
        }

    }
    void ChangeLevel()
    {

        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
    }
}

The player controller script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO.Ports;

public class PlayerController : MonoBehaviour
{
    SerialPort sp = new SerialPort("\\.\COM4", 9600);
    //player = GameObject.FindWithTag("Player").GetComponent().material;

    public float Speed;
    public Vector2 height;
    public float xMin, xMax, yMin, yMax;

    void Awake()
    {
        //player = GameObject.FindWithTag("Player");
    }
    void Start()
    {
        if (!sp.IsOpen)
        { // If the erial port is not open 
            sp.Open(); // Open 
        }
        sp.ReadTimeout = 1; // Timeout for reading
    }

    void Update()
    {

        if (sp.IsOpen)
        { // Check to see if the serial port is open 
            try
            {

                string value = sp.ReadLine();//To("Button"); //Read the information
                int button = int.Parse(value);
                //float amount = float.Parse(value);
                //transform.Translate(Speed * Time.deltaTime, 0f, 0f);  //walk

                if (button == 0) //*Input.GetKeyDown(KeyCode.Space*/)  //jump
                {
                    GetComponent().AddForce(height, ForceMode2D.Impulse);
                }
                GetComponent().position = new Vector3
                (
                    Mathf.Clamp(GetComponent().position.x, xMin, xMax),
                    Mathf.Clamp(GetComponent().position.y, yMin, yMax)
                );
            }
            catch (System.Exception)
            {


            }
        }
        void ApplicationQuit()
        {
            if (sp != null)
            {

                {
                    sp.Close();
                }
            }
        }
    }
}

Any advice and assistance will be appreciated.

Using two buttons as input to Unity from arduino

newbie here

So I am trying to use two buttons of an Arduino Uno to move a character in Unity. Both buttons must be pressed for the character to move. At this moment I have made the code work, but the character does not move immediately and when it moves it makes a great leap. This is not what I want him to do; I want the input to work as well as if the input came from a keyboard.

This is the Arduino code:

#include
#include 

const int ledPin = 13; // choose the pin for the LED
const int button1 = 2; // choose the input pin (for 1st pushbutton)
const int button2 = 3; // choose the input pin (for 2nd pushbutton)


  int ledState = LOW;         // the current state of the output pin
  int buttonState;             // the current reading from the input pin
  int lastButtonState = HIGH;   // the previous reading from the input pin
  unsigned long lastDebounceTime = 0;  // the last time the output pin was toggled
  unsigned long debounceDelay = 50;    // the debounce time; increase if the output flickers
void setup() 
{
  Serial.begin(9600); // Start the serial transmission
  digitalWrite(ledPin, ledState);
  pinMode(ledPin, OUTPUT); // declare LED as output
  pinMode(button1, INPUT); // declare pushbutton as input
  pinMode(button2, INPUT); // declare pushbutton as input

}

void loop()
{
  int valA = digitalRead(button1); // read button stateint 
 int  valB = digitalRead(button2); // read button state
   if (valA == LOW &&valB == LOW ) // check if the input is HIGH for both buttons -this can be changed to ||(or) or !(not)
  {
    digitalWrite(ledPin, HIGH); // turn LED on if both switches are pressed
    Serial.println("0");
      delay(20);
  }
    else
    {
      digitalWrite(ledPin, LOW); // turnLED off}}
      Serial.println("1");
    }
 int reading = digitalRead(INPUT);
 if (reading != lastButtonState) {

    lastDebounceTime = millis();
  }

  if ((millis() - lastDebounceTime) > debounceDelay) {

    if (reading != buttonState) {
      buttonState = reading;


      if (buttonState == LOW) {
        ledState = !ledState;
      }
    }
  }


  digitalWrite(ledPin, ledState);


  lastButtonState = reading;
}

This is the Unity Player Controller script:

    using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO.Ports;

public class PlayerController : MonoBehaviour
{
    SerialPort sp = new SerialPort("\\.\COM4", 9600);
    //player = GameObject.FindWithTag("Player").GetComponent().material;

    public float Speed;
    public Vector2 height;
    public float xMin, xMax, yMin, yMax;

    void Awake()
    {
        //player = GameObject.FindWithTag("Player");
    }
    void Start()
    {
        if (!sp.IsOpen)
        { // If the erial port is not open 
            sp.Open(); // Open 
        }
        sp.ReadTimeout = 1; // Timeout for reading
    }

    void Update()
    {

        if (sp.IsOpen)
        { // Check to see if the serial port is open 
            try
            {

                string value = sp.ReadLine();//To("Button"); //Read the information
                int button = int.Parse(value);
                //float amount = float.Parse(value);
                //transform.Translate(Speed * Time.deltaTime, 0f, 0f);  //walk

                if (button == 0) //*Input.GetKeyDown(KeyCode.Space*/)  //jump
                {
                    GetComponent().AddForce(height, ForceMode2D.Impulse);
                }
                GetComponent().position = new Vector3
                (
                    Mathf.Clamp(GetComponent().position.x, xMin, xMax),
                    Mathf.Clamp(GetComponent().position.y, yMin, yMax)
                );
            }
            catch (System.Exception)
            {


            }
        }
        void ApplicationQuit()
        {
            if (sp != null)
            {

                {
                    sp.Close();
                }
            }
        }
    }
}

Any assistance will be greatly appreciated.
I have also attached an image of the public variables that belong to my player controllerenter the description of the image here

buttons – color to download and upload

In addition to the down or up arrow, there is a color convention to distinguish between unloading and loading.

I have two buttons like these

enter the description of the image here

and these too

enter the description of the image here

But I feel that there is not enough visual difference for the actions. I thought of blue or red to download, but I'm not 100% sure they are correct.

Use of buttons in Firmata (Arduino + Processing) URGENT

1) How can I make the buttonState (change from a momentary switch to an interlock switch through the code?)
2) How can I make the button, when pressed, show different images depending on whether all dials are 0 and if they are not?
3) How can I make images appear in layers? Then, the images controlled by dial one will appear above those controlled by dial 1, etc.

Note that the dials work well and, through this code, I can make the screen change color only momentarily and not depend on the dials.

The code has two tabs in a single sketch. Both are as follows:

MONA LISA

import processing.serial.*;

import cc.arduino.*;


PImage monalisa; //declaring main MONALISA image

//declaring background images
PImage goodimage, badimage;

int dial1, dial2, dial3, dial4;
int A0;
PImage imgs (); 
int totalImages=48;

boolean  triggered=false;
int buttonState = 1;
int lastButtonState = -1; // this is set to something it couldn't possibly be for input so the logic works in the getSerialInput() function



void setup(){
  setUpArduino();
size(1000,1600);
monalisa= loadImage("Mona_Lisa.jpg"); //connecting the name monalisa to the image

imgs=new PImage(totalImages);

//load all images
for(int i=1; i 0) && (potState02>0) && (potState03>0 && (potState04>0)));
//loadImage("goodimage.jpg");
//// image(goodimage,0, 0, width, height); 

// }
//    }
// else {
// loadImage ("badimage.jpg");
////image(badimage,0, 0, monalisa.width/4, monalisa.height/4); }
//        println("on");
//      }// else {
        //triggered=false; //otherwise false
        //println("off");
      }
      ////////take note of your closing brackets.
    }


  //else {   
  //  lastButtonState = buttonState; // now update  lastButton so you can see if  a state has been repeatedly pushed
  //}

  //notice how the on/off println continues to repeatedly  print. Ok for certain graphics but perhaps bad
  //for triggering video that loops or certain audio
  //println("buttonState: ", buttonState);

//use your extra boolean to control things
if (buttonState==0){
 { if ((potState01 > 20) && (potState02>20) && (potState03>20) && (potState04>20));
 //if((triggered==true) && (potState01 > 20) && (potState02>20) && (potState03>20) && (potState04>20));
//loadImage("goodimage.jpg");
  background(255,0,0);
 }
}
//  else {background(0,255,0)};

//}



}
//fill(255,0,0);

//else{
//fill(255);


//  if (buttonState == 1) { // IMPORTANT!!! This is now 1 instead of 0 in class, as we are now using the INPUT_PULLUP workaround in the setUpSerial() function
//    if (buttonState != lastButtonState) { // this line and next manage problem of nasty constant trigerring
//      lastButtonState = buttonState;
//      println("on");
//{if((potState01 > 0) && (potState02>0) && (potState03>0 && (potState04>0)));
// loadImage("goodimage.jpg");
//  // image(goodimage,0, 0, width, height); 

// }
//    }
// else {
// loadImage ("badimage.jpg");
//  //image(badimage,0, 0, monalisa.width/4, monalisa.height/4); }

//  }
//}

//  else {
//    println("off");
//    lastButtonState = -1; // ensures we can push the button again and again
//  }



////  if (buttonState==0){
//// if((potState01 > 0) && (potState02>0) && (potState03>0 && (potState04>0)));
//// loadImage("goodimage.jpg");
//// }
////else {
//  loadImage ("badimage.jpg");


---------------------------------------------------------
Arduino Input


import processing.serial.*;
import cc.arduino.*;

Arduino arduino;
int buttonState01;
float potState01, potState02, potState03, potState04;

void setUpArduino() {
  // Prints out the available serial ports.
  printArray(Arduino.list());

  // Modify this line, by changing the "0" to the index of the serial
  // port corresponding to your Arduino board (as it appears in the list
  // printed by the line above).
  arduino = new Arduino(this, Arduino.list()(0), 57600);

  // Set the Arduino digital pins as inputs.
  for (int i = 0; i <= 13; i++) {
    arduino.pinMode(i, Arduino.INPUT_PULLUP);
  }
}

void checkArduinoInput() {
  // BUTTONS
  //logic of switches reversed. 
  //1 when no contact
  //0 when pushed
  buttonState=arduino.digitalRead(2);

  // POTS
  potState01 = arduino.analogRead(0);
  potState02 = arduino.analogRead(1);
  potState03 = arduino.analogRead(2);
  potState04 = arduino.analogRead(3);
}

c #: script field of the list of units with +/- buttons in the editor

I am using Unity 2018.4.11f1 LTS. I have a script with an audience List countryside.

In the Property inspector, Unity provides a UI to this field where it specifies the size of the list and then assigns items:

public List receivers;

enter the description of the image here

My question is: is there a way (perhaps a different kind of field) for Unity to provide an editor user interface that consists of a +/- button where you can add and remove items, instead of a user interface based on the size of the list?

Something else on the line of p. Eg what does it give you UnityEvents:

enter the description of the image here

c #: script field of the list of units with +/- buttons in the editor

I am using Unity 2018.4.11f1 LTS. I have a script with an audience List countryside.

In the Property inspector, Unity provides a UI to this field where it specifies the size of the list and then assigns items:

public List receivers;

enter the description of the image here

My question is: is there a way (perhaps a different kind of field) for Unity to provide an editor user interface that consists of a +/- button where you can add and remove items, instead of a user interface based on the size of the list?

Something else on the line of p. Eg what does it give you UnityEvents:

enter the description of the image here

buttons: Where to place an "Activity log" on a page with a fairly high information density?

Rule Maker Page

Hears!

I am designing a rule creation tool and I am trying to figure out where to put a "Activity Log" cost, basically a place where the user can click and see a complete list of edits made to a specific rule, as well as their time stamps

You are currently in the "Queue" button (see screenshot), which, when clicked, shows a modal list of all changes in the rule. However, this does not seem correct, because the rest of those CTAs in the upper right are reserved for explicit actions, not necessarily "locations" where the user will be taken.

So, I wonder where else this feature can be on the page where it makes sense in terms of best practices of UI + principles. It doesn't really matter if it opens on one modal page or another.

Also, turning it into a third tab next to "Live" and "Draft" is not viable because, before making a draft, there is a small "+ Create draft" button next to the "Live" tab, which creates the tab Draft – so tightening the activity log there with that interaction is a bit complicated.

Anyway, I hope everything makes sense. Thanks for taking a look! Looking forward to your entry 🙂