- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的 Android 2D 平台游戏上,当我第一次触摸屏幕时,我的性能出现了巨大的峰值。之后会出现一次小延迟,然后游戏就可以顺利运行了。没有错误消息。
我已经尝试将图形光线转换器分配给某些有所帮助的按钮。但小滞后仍然存在。在探查器中,性能峰值位于脚本下方并标记为 EventSystem.Update()。这是来自
的屏幕截图在单击按钮时,我使用以下代码作为 UI 管理器:
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine.UI;
using UnityEngine;
public class UIManager : MonoBehaviour
{
public GameObject menu;
public GameObject options;
public GameObject pause;
public Animator animatorMain;
public Animator animatorOptions;
public Animator animatorPause;
public bool hide;
public bool show;
public void UIDefaults()
{
menu = GameObject.Find("MainMenu");
options = GameObject.Find("optionsMenu");
pause = GameObject.Find("pauseMenu");
animatorMain = menu.GetComponent<Animator>();
animatorOptions = options.GetComponent<Animator>();
animatorPause = pause.GetComponent<Animator>();
hide = true;
show = false;
}
/* --- EXIT APPLICATION --- */
public void Exit()
{
Application.Quit();
}
/* --- EXIT APPLICATION --- */
/* --- MAIN MENU --- */
public void OpenMainMenu()
{
UIDefaults();
animatorOptions.SetBool("OptionsBool", hide);
StartCoroutine("WaitMainMenu");
}
// line 28. Coroutine
IEnumerator WaitMainMenu()
{
// wait for Options menu animation to end.
yield return new WaitForSeconds(1.15f);
SetMainMenuActive();
}
// line 35. function to Start the Main menu animation.
void SetMainMenuActive()
{
menu.GetComponent<Canvas>().enabled = true;
options.GetComponent<Canvas>().enabled = false;
pause.GetComponent<Canvas>().enabled = false;
animatorMain.SetBool("MainBool", show);
animatorOptions.SetBool("StartOptions", show);
animatorOptions.SetBool("OptionsBool", show);
}
/* --- MAIN MENU --- */
/* --- OPTIONS MENU --- */
public void OpenSettings()
{
UIDefaults();
animatorMain.SetBool("MainBool", hide);
StartCoroutine("WaitOptions");
}
// line 66. Coroutine
IEnumerator WaitOptions()
{
// wait for Main menu animation to end.
yield return new WaitForSeconds(1.15f);
SetOptionsActive();
}
// line 73. function to Start the Options menu animation.
void SetOptionsActive()
{
menu.GetComponent<Canvas>().enabled = false;
options.GetComponent<Canvas>().enabled = true;
pause.GetComponent<Canvas>().enabled = false;
animatorOptions.SetBool("StartOptions", hide);
}
/* --- OPTIONS MENU --- */
}
我希望在第一次触摸屏幕时摆脱最初的一次延迟。
最佳答案
部分原因可能是您正在使用 GameObject.Find()
来获取对菜单内容的引用。 GameObject.Find
回调引擎,可能会导致性能下降和分析器中出现峰值。
在检查器中设置这些引用,而不是在触发触摸事件时查找它们。希望这可以帮助! :)
关于c# - EventSystem.Update() 在 Android 上的第一次屏幕触摸时出现巨大的性能峰值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56447517/
我有一个包含大约 200 个图 block 的平面,我希望能够检测玩家点击了哪个图 block 。每个瓷砖都附有一个盒子对撞机。我还在场景中创建了一个空游戏对象,我附加了 EventSystem 和以
上下文:假设您正在检查键盘上是否按下了“W”,最常见的检查方法是通过以下代码: void Update(){ if (Input.GetKeyDown("W")) DoSome
我有一个处理所有鼠标事件的类,这样可以很容易地检查鼠标按钮是否被单击,但它似乎只有在我添加此行时才起作用:system.out.println(mouseManager.getMouseX());。
在我的 Android 2D 平台游戏上,当我第一次触摸屏幕时,我的性能出现了巨大的峰值。之后会出现一次小延迟,然后游戏就可以顺利运行了。没有错误消息。 我已经尝试将图形光线转换器分配给某些有所帮助的
我在脚本中使用 EventSystem.current.IsPointerOverGameObject,Unity 返回 True,尽管我发誓指针下方没有 UI/EventSystem 对象。 如何找
我花了一段时间才找到它,我什至不得不重新创建场景,我碰巧忘记了 EventSystem 但是......我正在开发一个简单的 2D 应用程序。按下按钮,它会播放随机声音。这很有效, super 简单。
我是一名优秀的程序员,十分优秀!