android - 按钮单击在整个侵犯版权的按钮图像中不起作用

标签 android unity-game-engine

首先让我解释一下我的结构,有一个包含按钮脚本的背景图像,它用于知道用户何时单击按钮外部。

这是: enter image description here

然后每个图像都有一个按钮,用于启用其下面的按钮(绿色的表示升级)

最后是有问题的按钮: enter image description here

在游戏过程中,当我按下此按钮时,它只会工作到一半高度,如下图所示: enter image description here

如果下面没有更多按钮,首先我认为这是因为我有背景按钮,当我单击下面时,它被视为背景,但是当我停用背景按钮时,同样的事情仍然发生。

仅供进一步引用,这是游戏过程中的样子: enter image description here

该按钮仅在单击其图像时显示,当我在其框外单击时,我会执行 GameObject.SetActive(false);

因为我实际上认为这与 Unity UI 有关,所以我不认为需要任何代码,但如果需要,只需评论,我可能会发布(它是一个很长的代码)。

最佳答案

再简单不过了,还有普通的侵犯版权图像,

您显然在底部出现了额外的“4000(金币)”类型的版权侵权图像。

您在该图像和按钮上塞满了一些东西 - 一个挡住了另一个或类似的东西。

(几乎可以肯定,您正在调整“图像而不是按钮”或类似的东西的大小......但我们将为您省去处理这个问题的无聊。)

解决办法在这里

以您想要的任何方式重新设计您的图像,包括即时动态更改它们。

然后实际上在图像下有一个按钮,让它向各个方向展开。完全剥离按钮 - 删除按钮的图像和文本。

现在一切都将完美运行 - 除了空按钮不起作用。由于您可以通过在互联网上查找内容来避免所有工作,因此如下。这是一个神奇的脚本,您将其放在空按钮上,然后它们就会起作用

重要提示:

1) 当您添加空按钮时,首先留下纯白色 50% Alpha 图像,以便您可以看到按钮的位置。运行动态更改图像大小/添加/删除等的代码,您可以观察按钮的“透明灰色区域”是否保持正确。

2) 伙计,你必须使用这样的按钮预制件。然后你可以改变一个并同时改变它们。让它成为学习如何很好地使用预制件的机会

3) 对于所有侵犯版权的图像单元(现在是预制件),您几乎肯定必须使用 Unity 的(优秀的)响应式(Reactive)布局系统。您将必须了解水平和垂直布局组。

请记住,现在您无法生成非响应式界面。

再次回顾一下。 Unity 的按钮系统(虽然很优秀)非常幼稚 - 他们有“包含在”标准按钮上的图像的概念,更不用说标准按钮下面的可笑的文本元素了。

实际上,你很少会这样工作。您有“一大堆东西”(很可能是动态的、交换图像等),并且您想简单地通过将按钮组件放在上来“将其按钮化”那些图像的东西。

我已经为您提供了以下解决方案,用于将 Unity 的(优秀)按钮转换为成熟的、严肃的工程“drop on”按钮。享受吧!

/* Touchable.cs

So: basically use this to make invisible buttons.

Often it's much better to have your IMAGES
(any combination or layout you want),
as totally normal images.

Then, UNDER THE IMAGE, using four way stretching,
have a totally empty button (no image, no text).

This allows you to separate the image and buttons
functions.

You can then do absolutely anything you want to the
the images, eg, reahape, have multiple images, etc etc

There's only one problem with this, empty buttons
don't work.

In short, if you add this script to an empty button
- simply drop it on - the button then works perfectly.

Regarding precisely HOW this script works, I can't
be bothered explaining. Treat it as magic or search
long discussions about it on the www.
It's a little better engineering to go Touchable:Text
rather than building one from scratch with :Graphic,
since it will be more immune to Unity deprecations...
this is the correct solution for Touchable.cs.
*/

// Don't modify ONE CHARACTER in the code here!

using UnityEngine;
using UnityEngine.UI;

#if UNITY_EDITOR
using UnityEditor;
[CustomEditor(typeof(Touchable))]
public class Touchable_Editor:Editor
    {
    public override void OnInspectorGUI ()
        {
        // just consider this magic and don't bother about it,
        // prevents treating component as a Text object in Editor
        }
    }
#endif

public class Touchable:Text
    {
    protected override void Awake()
        {
        base.Awake();
        }
    }

关于android - 按钮单击在整个侵犯版权的按钮图像中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36303391/

相关文章:

json - 使用 MiniJSON 解析嵌套 JSON (Unity3D)

java - 暂停和恢复翻译动画

java - 当我尝试在模拟器上运行时,Android Studio 返回 Transform Exception 错误

java - LibGDX And​​roid : Lag with 25+ sprites despite use of TimeKeeping

java - 调用虚方法 null context.getSystemService

android - 两个 RecyclerView 依赖项有什么区别?

c# - Unity 中的 3D 物理 compass (处理旋转)

c# - 将 nhibernate 与 Unity3D 集成

android - 如何为不同语言(Unity3d、Android)使用不同名称的应用程序

ios - WebCamTexture iOS 模糊快照