Unity Android 实现桌面精灵

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值