1.項(xiàng)目需求:
Unity接入視頻SDK讓視頻安置在Unity View的下方, Unity層作為其他布局的顯示層這樣做一個(gè)直播類的app只用寫一套代碼, 然后項(xiàng)目接入SDK即可, 少量的原生代碼即可實(shí)現(xiàn)功能, 也省去了IOS開發(fā)Android開發(fā)的必要.
效果如圖:


2.踩坑
Unity3d五 android 設(shè)置背景透明的方法 - QQ18334373taikongyi的專欄 - CSDN博客,這是前人踩過的坑我繼續(xù)踩!!!! 里面的連接一一看了個(gè)遍百度google翻個(gè)底朝天...都沒有比較好的解決方案.
當(dāng)然我現(xiàn)在項(xiàng)目用的是Unity5.6的版本, 看完最值得可信的是Unity4.2的版本修改GLSurfaceView于是乎去找class.jar 的UnityPlayer發(fā)現(xiàn)根本沒有GLSurfaceView只有SurfaceView


直接繼承UnityPlayerActivity或者UnityPlayer都是不行的,于是乎使出逆向工具,dex2jar apktool jdgui jeb smail notepad++等.
改完終究是沒有效果的,什么android窗口透明啦activity透明啦view透明啦主題透明啦,一樣一樣的.尷尬

最終意識(shí)到黑色的背景來源于渲染沒有alpha透明通道導(dǎo)致的,在UnityPlayer里面渲染的時(shí)候把SurfaceHolder傳入到ndk層去了,就是native層,于是乎去找函數(shù)導(dǎo)出表,libunity.so這玩意還做了加固的...手動(dòng)注冊(cè)的native函數(shù)...算了經(jīng)驗(yàn)不足pass
3.解決方案
找啊找啊找?Unity3D export to Android with transparent background? Search this thread... Watch Thread?



當(dāng)然引擎不能用最新的應(yīng)為不能破解,可能會(huì)出一些問題,還要考慮到兼容原來的Unity 5.6 試了下Unity 2017.2 和?Unity 2017.3 和?Unity 2017.4 TLS發(fā)現(xiàn)Unity 2017.2 這個(gè)版本是不存在那個(gè)勾選項(xiàng)的....啊這...Unity 2017.4 TLS又無法破解,最后選擇了2017.3.1p4這個(gè)版本完美升級(jí)Unity 5.6沒有任何錯(cuò)誤原來的其他項(xiàng)目.
最后附上破解地址?全系列Unity v4.x.x & v5.x.x & v2017.x.x & v2018.x.x破解Win&Mac! - 資源庫 - Unity圣典社區(qū)
希望后來人少踩些坑吧...哎
4.讓你的自定義View安置于Unity View的下方
新建一個(gè)Layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
? ? android:layout_width="match_parent"
? ? android:layout_height="match_parent" >
? ? <com.tencent.rtmp.ui.TXCloudVideoView
? ? ? ? ? ? android:id="@+id/video_view"
? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? android:layout_height="match_parent"
? ? ? ? ? ? android:layout_centerInParent="true"
? ? ? ? ? ? android:visibility="gone"/>
? ? <FrameLayout
? ? ? ? android:id="@+id/unity_layout"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="match_parent">
? ? </FrameLayout>
</RelativeLayout>
把你需要展示的View放到unity_layout之上

/**
? ? * 獲取控件,fix打成jar包無法獲取控件
? ? * @param context
? ? * @param id
? ? * @return View
? ? */
? ? public static View findViewById(Activity context, String id) {
? ? if (context == null)
? ? return null;
? ? int res_id = context.getResources().getIdentifier(id, "id", context.getPackageName());
? ? return context.findViewById(res_id);
? ? }
值得注意的是項(xiàng)目被打成jar包了,直接findViewById是找不到的,我用的eclipse導(dǎo)出的jar包不知道as會(huì)不會(huì)有這種情況
