unity调用安卓方法

unity导出成安卓工程,集成到安卓显示:

https://blog.csdn.net/AllBluefm/article/details/155519181

安卓调用unity中的方法

https://blog.csdn.net/AllBluefm/article/details/155520167

使用场景:比如unity中播放一个动画,播放完成之后改变安卓中按钮的样式

第一步:在unity脚本中调用安卓方法

复制代码
using UnityEngine;

public class StatusBarController : MonoBehaviour
{
    void Start()
    {
        ShowStatusBar();
    }

    private void ShowStatusBar()
    {
        // 调用插件中的方法
        using (AndroidJavaClass UnityCallUtil = new AndroidJavaClass("com.test.utils.UnityCallUtil"))
        {
            UnityCallUtil.Call("calledByAndroidShowStatusBar");
        }
    }
}

第二步:将unity打成aar,放到安卓项目中,必须保证aar和com.test.utils.UnityCallUtil在同一个模块中,否则调用不到

第三步:在com.test.utils.UnityCallUtil的calledByAndroidShowStatusBar中处理安卓需求

复制代码
package com.test.utils;

import androidx.fragment.app.Fragment;

public class UnityCallUtil extends Fragment {

    public static void calledByAndroidShowStatusBar() {
        // 在这里处理安卓需求
    }
}
相关推荐
alexhilton3 小时前
Android的Agent优先时代:构建时vs运行时
android·kotlin·android jetpack
Cutecat_4 小时前
视频字幕处理工具横向:提取模式 vs 编辑模式,该如何选择
android·前端·ios·语音识别
2601_961765295 小时前
【分享】PlayerPro媒体音乐播放器 完整专业版
android·媒体
JohnnyDeng947 小时前
【Android】Android 包体积优化:R8/ProGuard 深度配置全攻略
android·性能优化·kotlin·jetpack
故渊at7 小时前
第九板块:Android 多媒体体系 | 第二十四篇:Camera Service 与 HAL3 成像流水线
android·camera·多媒体体系·hal3
Jinkxs10 小时前
Python基础 - 初识内置函数 Python自带的便捷工具
android·java·python
私人珍藏库11 小时前
【Android】VLLO-韩国热门手机剪辑APP
android·app·工具·软件·多功能
Cloud_Shy61812 小时前
解读《Effective Python 3rd Edition》:从练气到老魔(第六章 Item 40 - 43)
android·开发语言·人工智能·笔记·python·学习方法
AFinalStone12 小时前
Android12 U盘插拔链路源码全解析(五):Framework层(下) StorageManagerService
android·frameworks
auccy13 小时前
Unity Sprite 添加法线贴图
unity·贴图·normal