Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Button UI Logic to block items when non interactable #256

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions Assets/Prefabs/UI/Canvas.prefab

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 20 additions & 20 deletions Assets/Prefabs/UI/Components/UIToggleButton.prefab

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 64 additions & 39 deletions Assets/Scripts/UI/Components/UIButtonLogic.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
Expand All @@ -10,27 +11,48 @@ namespace Netherlands3D.Twin
{
public class UIButtonLogic : MonoBehaviour
{

private Button button;

public Color BaseTextColor = Color.blue;
public Color HighlightedTextColor = Color.white;
public Color DisabledTextColor = Color.grey;
public TextMeshProUGUI ButtonText;
public GameObject Icon;
public Image Icon;

// Start is called before the first frame update
void Start()
private void Awake()
{
if (ButtonText != null)
button = GetComponent<Button>();
}

private void Start()
{
if (button.interactable)
{
ButtonText.overrideColorTags = true;
ButtonText.color = BaseTextColor;
if (ButtonText != null)
{
ButtonText.overrideColorTags = true;
ButtonText.color = BaseTextColor;
}
if (Icon != null)
{
Icon.color = BaseTextColor;
}
}
if(Icon != null)
else
{
Icon.GetComponent<Image>().color = BaseTextColor;
if (ButtonText != null)
{
ButtonText.overrideColorTags = true;
ButtonText.color = DisabledTextColor;
}
if (Icon != null)
{
Icon.color = DisabledTextColor;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dit stuk lijk je 2 keer te gebruiken ook in pointerup, kan je misschien gewoon een method maken zoals,

private void EnableButton()
{
bool interactable = button.interactable;
Color color = interactable ? BaseTextColor : DisabledTextColor;
if (ButtonText != null)
{
ButtonText.overrideColorTags = true;
ButtonText.color = color;
}
if (Icon != null)
{
Icon.color = color;
}
}

}


public void PointerDown()
{
if (ButtonText != null)
Expand All @@ -40,23 +62,38 @@ public void PointerDown()
}
if (Icon != null)
{
Icon.GetComponent<Image>().color = HighlightedTextColor;
Icon.color = HighlightedTextColor;
}
}

public void PointerUp()
{
if (ButtonText != null)
if(button.interactable)
{
ButtonText.overrideColorTags = true;
ButtonText.color = BaseTextColor;
if (ButtonText != null)
{
ButtonText.overrideColorTags = true;
ButtonText.color = BaseTextColor;
}
if (Icon != null)
{
Icon.color = BaseTextColor;
}
}
if (Icon != null)
else
{
Icon.GetComponent<Image>().color = BaseTextColor;
if (ButtonText != null)
{
ButtonText.overrideColorTags = true;
ButtonText.color = DisabledTextColor;
}
if (Icon != null)
{
Icon.color = DisabledTextColor;
}
}
DeselectClickedButton(this.gameObject);


DeselectClickedButton(gameObject);
}

private void DeselectClickedButton(GameObject button)
Expand All @@ -67,34 +104,22 @@ private void DeselectClickedButton(GameObject button)
}
}

public void ButtonState(bool Enabled )
public void Disable_Button()
{
if(Enabled == true)
if (ButtonText != null)
{
this.GetComponent<Button>().interactable = true;
{
ButtonText.overrideColorTags = true;
ButtonText.color = BaseTextColor;
}
if (Icon != null)
{
Icon.GetComponent<Image>().color = BaseTextColor;
}
ButtonText.overrideColorTags = true;
ButtonText.color = DisabledTextColor;
}

if(Enabled == false)
if (Icon != null)
{
this.GetComponent<Button>().interactable = false;
{
ButtonText.overrideColorTags = true;
ButtonText.color = DisabledTextColor;
}
if (Icon != null)
{
Icon.GetComponent<Image>().color = DisabledTextColor;
}
Icon.color = DisabledTextColor;
}
}

public void Enable_Button()
{
PointerUp();
}
}
}
Loading
Loading