Android全局桌面精灵Unity实现
网页上找了一圈实现方案,大家的实现方案都是类似的。发现一个问题就是,用的都是旧版本的unity。以下的发案是基于新版本unity去实现。我使用的unity版本是2022.3.15
大致思路:
悬浮窗绘制unity场景
中间遇到的问题:
(1):相机背景不透明
解决方案
相机修改颜色值00000000
//看到这个方法
mUnityPlayer.setAlpha(0);
(2):进程切换导致画面不渲染
切换进程会执行一次暂停操作
@Override protected void onPause()
{
super.onPause();
// MultiWindowSupport.saveMultiWindowMode(this);
// if (MultiWindowSupport.getAllowResizableWindow(this))
// return;
//
// FloatingService.mUnityPlayer.pause();
}
暴力解决
直接屏蔽相关代码
1:准备Android工程
创建Android工程
相机配置修改


Android 工程导出配置

导出Android工程即可
2:android studio 工程配置
xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.unity3d.player" xmlns:tools="http://schemas.android.com/tools">
<uses-feature android:glEsVersion="0x00030001" />
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<application android:extractNativeLibs="true">
<meta-data android:name="unity.splash-mode" android:value="0" />
<meta-data android:name="unity.splash-enable" android:value="True" />
<meta-data android:name="unity.launch-fullscreen" android:value="False" />
<meta-data android:name="unity.allow-resizable-window" android:value="False" />
<meta-data android:name="android.max_aspect" android:value="2.1" />
<meta-data android:name="unity.auto-report-fully-drawn" android:value="true" />
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:theme="@style/UnityThemeSelector.Translucent" android:screenOrientation="fullUser" android:launchMode="singleTask" android:maxAspectRatio="2.1" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density" android:resizeableActivity="false" android:hardwareAccelerated="false" android:exported="true">
<intent-filter>
<c


3228

被折叠的 条评论
为什么被折叠?



