【问题标题】:Loader during Unity IAP CallbackUnity IAP 回调期间的加载程序
【发布时间】:2018-01-24 15:40:35
【问题描述】:

我想在购买的对话框之间放置加载器。这是什么方法?

因为当玩家按下购买按钮时,他应该需要等待5到10秒,具体取决于互联网速度和服务器响应,这个过程发生了2到3次,因为屏幕内出现了多个对话框.

所以在这种情况下,可能是玩家可以离开屏幕。我想让加载器让玩家意识到一些处理正在后台运行,他需要等待一段时间。

目前,我完全按照此代码进行 Unity IAP 设置。 Integrating Unity IAP In Your Game

【问题讨论】:

    标签: unity3d


    【解决方案1】:

    我认为这是针对移动平台的,但即使它仍然不是以下内容也可以考虑:

    简单的解决方案是在您的 UI 中创建一个全屏图像(UI/面板)对象来阻止点击。当后台进程正在运行时,我会使用 Animator 组件(带有触发器)在其他 UI 前面显示此面板。

    public class Loader : MonoBehaviour
    {
        public static Loader Instance;
        Animator m_Animator;
    
        public bool Loading {get; private set;}
    
        void Awake()
        {
            Instance = this; // However make sure there is only one object containing this script in the scene all time. 
        }
    
        void Start()
        {
            //This gets the Animator, which should be attached to the GameObject you are intending to animate.
            m_Animator = gameObject.GetComponent<Animator>();
            Loading = false;
        }
    
        public void Show()
        {
            Loading = true;
            m_Animator.SetBool("Loading", Loading); // this will show the panel.
    
        }
    
        public void Hide()
        {
            Loading = false;
            m_Animator.SetBool("Loading", Loading); // this will hide the panel.
        }
    }
    

    然后在任何操纵 UI 的脚本中:

    public void BuyButtonClicked()
    {
        Loader.Instance.Show();
        // process time taking stuff
        Loader.Instance.Hide();    
    }
    

    您还可以使用 Unity 中的简单图像和动画工具创建任何类型的加载动画作为面板对象的子对象(例如旋转动画(使用 fidget spinner,它很酷))。

    如果 Android 用户可以选择通过按操作系统后退按钮离开屏幕,您可以通过以下示例检查是否正在进行任何加载来防止返回:

    // code for back button
    void Update() 
    {
        if (Input.GetKeyDown(KeyCode.Escape)) 
        { 
            BackButtonPressed(); 
        }
    }
    
    void BackButtonPressed()
    {
        if(Loader.Instance.Loading)
            return;
        // use back button event. (For example to leave screen)
    }
    

    希望这会有所帮助;)

    【讨论】:

    • 购买调用前后,我不能将加载程序隐藏和显示方法放在单帧中,否则所有事情都会发生,因为它不是 IEnumerator。
    • 显然你不应该那样做。它只是一个示例,只是为了让您了解在哪里调用这些方法。您可以在协程中相应地调用这两种方法
    • 兄弟,这不是确切的答复,因此我可以将其设为正确。
    • 您是否尝试过解决方案?我猜不是。有点欣赏不会有什么坏处。更不用说有人花时间写一个答案的教程。仍然不准确回复?找人为你做这项工作。快乐编码:)
    • 是的@Umair M,我并不是说你没有通过回复做好事,但如果这不是一个完美的答案,那么你不能强迫其他人将其标记为正确。我可以说你的观点是 50% 给出方向。因此,如果您有时间,请务必为他人提供帮助,因为您做得很好:)
    猜你喜欢
    • 2017-12-26
    • 1970-01-01
    • 2017-01-10
    • 1970-01-01
    • 1970-01-01
    • 2012-05-21
    • 1970-01-01
    • 2017-10-16
    • 1970-01-01
    相关资源
    最近更新 更多