Android開發 調試環境

咱們這裏有3種調試方法,Unity Remote,Android Studio和第三方模擬器測試

 

準備工做

(1)Android Studio:安裝Google USB Driverui

(2)手機安裝Unity Remote3d

安裝Unity Remote後,能夠將手機與PC用USB線鏈接,在Unity界面運行,並在手機上顯示畫面,這樣能夠不用打包就能測試大部分功能,可是缺點是不能測試所有功能,有一些仍是檢測不到的。調試

 

 

調試

(1)使用Unity Remote調試code

首先設置Unity中的Editor Settings,依次打開Edit > Project Settings > Editororm

打開手機,確保開發人員選項打開,而且在USB調試模式下,打開Unity Remote,而後啓動Unity項目,手機上就會顯示對象

 

(2)使用AVD + [Logcat] 調試(Android Virtual Device)blog

打開Android Studio,選擇Tools > AVD Manager遊戲

建立一個虛擬設備開發

這個根據須要選擇型號

這一步注意,選擇一個穩定的,存在的

建立好後以下

選擇運行,就出現一個咱們建立好的虛擬設備

最後,在Unity中Build And Run,之前是Bulid,這裏會建立好一個apk,而且在建立的時候unity會搜索鏈接的Android設備,並將apk安裝上去。這個時候咱們的虛擬設備上就運行了這個包。

在虛擬設備運行的時候,能夠在這裏選擇看到Android的打印顯示

 

(3)使用真機 + [Logcat] 調試

和第2種方法不同的事,這裏不適用虛擬設備,直接使用咱們的手機來調試。手機用數據線和電腦鏈接,和第2種方法同樣的打包,可是這裏會在咱們的手機上面安裝一個包運行。一樣能夠在Android Studio中看到Logcat

 

(4)使用模擬器調試

安裝模擬器,將打出的包安裝上去,運行就好了。 

 

移動端相關API:

using UnityEngine;
using UnityEngine.UI;

public class Test : MonoBehaviour
{
    public Text infoText;
    string platform = string.Empty;
    string info = string.Empty;

    void Update()
    {
        info = string.Empty;
        //使用預編譯的宏命令檢測平臺
        //Editor模式下目標平臺選Android也會觸發UNITY_ANDROID的宏
#if UNITY_ANDROID
        platform = "UNITY_ANDROID";
#elif UNITY_EDITOR
        platform = "UNITY_EDITOR";
#endif
        Debug.Log("platform : " + platform);
        info += "platform : " + platform + "\n";
        //使用Application.platform檢測平臺
        Debug.Log("platform : " + Application.platform);
        info += "platform : " + Application.platform + "\n";
        //獲取當前設備分辨率
        Debug.Log("currentResolution : " + Screen.currentResolution);
        info += "currentResolution : " + Screen.currentResolution + "\n";
        //獲取當前DPI
        Debug.Log("dpi : " + Screen.dpi);
        info += "dpi : " + Screen.dpi + "\n";
        //獲取是否全屏
        Debug.Log("fullScreen : " + Screen.fullScreen);
        info += "fullScreen : " + Screen.fullScreen + "\n";
        //獲取遊戲窗口的寬高
        Debug.Log("height : " + Screen.height);
        info += "height : " + Screen.height + "\n";
        Debug.Log("width : " + Screen.width);
        info += "width : " + Screen.width + "\n";
        //獲取屏幕方向
        Debug.Log("orientation : " + Screen.orientation);
        info += "orientation : " + Screen.orientation + "\n";
        //獲取屏幕超時時間(僅在移動端有效)
        Debug.Log("sleepTimeout : " + Screen.sleepTimeout);
        info += "sleepTimeout : " + Screen.sleepTimeout + "\n";
        //任意鍵按下
        Debug.Log("anyKey : " + Input.anyKey);
        info += "anyKey : " + Input.anyKey + "\n";
        //獲取最後一次加速度計報告的加速度
        Debug.Log("acceleration : " + Input.acceleration);
        info += "acceleration : " + Input.acceleration + "\n";
        //獲取本幀加速度計報告的次數
        Debug.Log("accelerationEventCount : " + Input.accelerationEventCount);
        info += "accelerationEventCount : " + Input.accelerationEventCount + "\n";
        //獲取本幀加速度計的全部報告信息
        for (int i = 0; i < Input.accelerationEvents.Length; i++)
        {
            Debug.Log("accelerationEvents" + i + " : " + Input.accelerationEvents[i].acceleration + " , " + Input.accelerationEvents[i].deltaTime);
            info += "accelerationEvents" + i + " : " + Input.accelerationEvents[i].acceleration + " , " + Input.accelerationEvents[i].deltaTime + "\n";
        }
        //獲取電子羅盤向量
        Debug.Log("compass : " + Input.compass.rawVector);
        info += "compass : " + Input.compass.rawVector + "\n";
        //獲取設備方向
        Debug.Log("deviceOrientation : " + Input.deviceOrientation);
        info += "deviceOrientation : " + Input.deviceOrientation + "\n";
        //獲取陀螺儀重力
        Debug.Log("gyro : " + Input.gyro.gravity);
        info += "gyro : " + Input.gyro.gravity + "\n";
        //獲取位置服務狀態
        Debug.Log("location : " + Input.location.status);
        info += "location : " + Input.location.status + "\n";
        //獲取設備是否帶有鼠標
        Debug.Log("mousePresent : " + Input.mousePresent);
        info += "mousePresent : " + Input.mousePresent + "\n";
        //獲取平臺是否支持多點觸控
        Debug.Log("multiTouchEnabled : " + Input.multiTouchEnabled);
        info += "multiTouchEnabled : " + Input.multiTouchEnabled + "\n";
        //獲取是否支持筆觸(可檢測壓感、觸摸夾角等)
        Debug.Log("stylusTouchSupported : " + Input.stylusTouchSupported);
        info += "stylusTouchSupported : " + Input.stylusTouchSupported + "\n";
        //獲取是否支持壓感
        Debug.Log("touchPressureSupported : " + Input.touchPressureSupported);
        info += "touchPressureSupported : " + Input.touchPressureSupported + "\n";
        //獲取是否支持觸摸
        Debug.Log("touchSupported : " + Input.touchSupported);
        info += "touchSupported : " + Input.touchSupported + "\n";
        if (Input.touchCount > 0)
        {
            //當前幀的觸摸數
            Debug.Log("touchCount : " + Input.touchCount);
            info += "touchCount : " + Input.touchCount + "\n";
            for (int i = 0; i < Input.touchCount; i++)
            {
                //獲取當前Touch對象的一系列屬性
                Debug.Log("touch" + i + "altitudeAngle : " + Input.GetTouch(i).altitudeAngle);
                info += "touch" + i + "altitudeAngle : " + Input.GetTouch(i).altitudeAngle + "\n";
                Debug.Log("touch" + i + "azimuthAngle : " + Input.GetTouch(i).azimuthAngle);
                info += "touch" + i + "azimuthAngle : " + Input.GetTouch(i).azimuthAngle + "\n";
                Debug.Log("touch" + i + "deltaPosition : " + Input.GetTouch(i).deltaPosition);
                info += "touch" + i + "deltaPosition : " + Input.GetTouch(i).deltaPosition + "\n";
                Debug.Log("touch" + i + "deltaTime : " + Input.GetTouch(i).deltaTime);
                info += "touch" + i + "deltaTime : " + Input.GetTouch(i).deltaTime + "\n";
                Debug.Log("touch" + i + "fingerId : " + Input.GetTouch(i).fingerId);
                info += "touch" + i + "fingerId : " + Input.GetTouch(i).fingerId + "\n";
                Debug.Log("touch" + i + "maximumPossiblePressure : " + Input.GetTouch(i).maximumPossiblePressure);
                info += "touch" + i + "maximumPossiblePressure : " + Input.GetTouch(i).maximumPossiblePressure + "\n";
                Debug.Log("touch" + i + "phase : " + Input.GetTouch(i).phase);
                info += "touch" + i + "phase : " + Input.GetTouch(i).phase + "\n";
                Debug.Log("touch" + i + "position : " + Input.GetTouch(i).position);
                info += "touch" + i + "position : " + Input.GetTouch(i).position + "\n";
                Debug.Log("touch" + i + "pressure : " + Input.GetTouch(i).pressure);
                info += "touch" + i + "pressure : " + Input.GetTouch(i).pressure + "\n";
                Debug.Log("touch" + i + "radius : " + Input.GetTouch(i).radius);
                info += "touch" + i + "radius : " + Input.GetTouch(i).radius + "\n";
                Debug.Log("touch" + i + "radiusVariance : " + Input.GetTouch(i).radiusVariance);
                info += "touch" + i + "radiusVariance : " + Input.GetTouch(i).radiusVariance + "\n";
                Debug.Log("touch" + i + "rawPosition : " + Input.GetTouch(i).rawPosition);
                info += "touch" + i + "rawPosition : " + Input.GetTouch(i).rawPosition + "\n";
                Debug.Log("touch" + i + "tapCount : " + Input.GetTouch(i).tapCount);
                info += "touch" + i + "tapCount : " + Input.GetTouch(i).tapCount + "\n";
                Debug.Log("touch" + i + "type : " + Input.GetTouch(i).type);
                info += "touch" + i + "type : " + Input.GetTouch(i).type + "\n";
            }
        }
        infoText.text = info;
    }
}
相關文章
相關標籤/搜索