Android:从场景外的UI组件更改Unity场景 [英] Android: Changing Unity Scene from UI components outside the scene

查看:211
本文介绍了Android:从场景外的UI组件更改Unity场景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个使用Unity进行UI渲染的Android应用,用户可以在场景外执行一些操作.

I am trying to build an Android app that uses Unity for UI rendering where the user can perform some actions from outside the scene.

这意味着说我有一个活动,其中有一个统一的场景作为子视图.屏幕的其余部分由本地android视图(按钮等)组成.我想使用这些视图来更改统一场景,例如显示文本字段,添加文本,隐藏文本,添加文本效果等.

What this means is that say I have an activity where I have a unity scene as a subview. The rest of the screen is composed of native android views (buttons etc). I want to use these views to make changes to the unity scene such as to show a text field, add text, hide text, add text effects etc.

到目前为止,我已经按照此答案将统一场景添加为子视图,并且效果很好.我是Unity的新手,我不确定如何从场景外的视图管理和更改场景.这有可能吗?我知道如果我在Unity中创建场景时向场景本身添加按钮,那么我可以使用这些按钮来更改场景.

So far I have added the unity scene as a subview by following this answer and it works fine. I am new to Unity and I am not sure how I can manage and change the scene from views outside the scene. Is this even possible? I know if I add buttons to the scene itself when I create the scene in Unity then I can use those buttons to alter the scene.

但是,不是场景一部分的UI组件可以做到这一点吗?如果是,我该怎么做?我试图找到有关此信息,但找不到太多.谢谢阅读.

But is this possible by UI components that are not a part of the scene? If yes how can I do this? I have tried to find info on this but couldn't find much. Thanks for reading.

推荐答案

  • 在Unity端和Android之间进行沟通. 如果您统一执行以下功能,则可以从技术上做到这一点.我刚刚在这里写了团结与Android如何沟通 在使用此代码之前,您需要查看Unity和Android之间的集成简介以使用来自Unity的本机插件,因此请参见此链接.

    • Make communicator between Unity side and Android. It's possible to do that technically, if you make following function in unity. I've just wrote here how unity and android communicate so before use this code you need to see brief of integration between Unity and Android to use native plugin from Unity so see this link to do that.

      https://docs.unity3d.com/Manual/PluginsForAndroid.html

      了解了如何制作适用于Android的插件后,请查看代码.它会为您提供帮助.

      After you understand that how to make plugin for android, then see codes. It will help you.

      • 游戏对象名称:LoadGameSceneObject,loadScene.cs
          public class loadScene : MonoBehaviour
          {
              public static void LoadScene(string sceneName)
              {
                  SceneManager.LoadScene(sceneName);
              }
          }
      
      
      

      • SceneLoadActivie.java
      •     public static void SendMessageToUnity(String gameObjectName, String methodName, String message) throws Exception
            {
                Log.d("unity", gameObjectName + " " + methodName + " " + message);
                final Class<?> player = Class.forName("com.unity3d.player.UnityPlayer");
                player.getMethod("UnitySendMessage", String.class, String.class,
                                 String.class).invoke(null, gameObjectName, methodName, message);
            }
        
            ...
            // call this function.
            public void LoadScene()
            {
                SceneLoadActivie.SendMessageToUnity("LoadGameSceneObject", "LoadScene", "SomeScene");
            }
        

        这篇关于Android:从场景外的UI组件更改Unity场景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆