嗚嗚喔學習筆記

搜尋此網誌

2018年11月15日 星期四

Unity x NSubstitute Startup

Unity 2017.4.1f + NSubstitute-1.4.3.0


1. Download Dll

https://github.com/nsubstitute/NSubstitute/downloads

2. Copy Dll to Unity Assets\Editor\



2018年11月13日 星期二

Unity Profiler On Android Device Q&A 遇到的問題及解法

Profiler & Android 遇到的問題

1. adb server version (31) doesn't match this client (39)
下載 adb 31 版本 並覆蓋舊版
2. adb forward tcp:54999 localabstract:{yourPackageName}
改為 adb forward tcp:34999 localabstract:{yourPackageName}
   貌似都有可能出現 要看Edior顯示什麼

3. 先 ADB 執行完 再開Unity 才抓得到
4. adb無反應 可以試試先執行指令 adb kill-server
之後再執行  adb forward tcp:34999 localabstract:{yourPackageName}

2018年9月16日 星期日

Unity , Detect if app is installed on Android (確認是否有安裝這個APP)

Unity中確認是不是有安裝該APP
可以用PackageName 去查詢
至於怎麼拿PackageName 這裡就不多提了 0.0

上CODE:

    private static bool IsAndroidInstalledApp(string packageName)
    {
        try
        {
            AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject ca = up.GetStatic("currentActivity");
            AndroidJavaObject packageManager = ca.Call("getPackageManager");
            AndroidJavaObject appList = packageManager.Call("getInstalledPackages", 0);
            int num = appList.Call("size");
            for (int i = 0; i < num; i++)
            {
                AndroidJavaObject appInfo = appList.Call("get", i);
                string packageNew = appInfo.Get("packageName");
                if (packageNew.CompareTo(packageName) == 0)
                {
                    return true;
                }
            }
            return false;
        }
        catch (Exception e)
        {
            Debug.LogErrorFormat("[OpenUrlHelper][IsInstalledApp] Get Exception , PackageName {0}", packageName);
            return false;
        }
    }

2018年8月29日 星期三

Unity 各平台路徑位置

Application.dataPath
建議視窗開發中用的路徑:
windows:  /Assets
IPone: Application/???/Name.app/Data
Android: /data/app/Name.apk
Application.persistentDataPath
Contains the path to a persistent data directory (Read Only).
平台中的公開目錄,文件持久性的保存不會因為應用程式更新或升級而刪除
windows:  C:/Users/xxxx/AppData/LocalLow/CompanyName/ProductName
IPone: Application/???/Documents
Android: /data/data/Name/files
Application.streamingAssetsPath
專案目錄下面的 Assets/StreamingAssets
windows:   /Assets/StreamingAssets
IPone: Application/???/Name.app/Data/Raw
Android: jar:file:///data/app/Name.apk/!/assets
Application.temporaryCachePath
Contains the path to a temporary data / cache directory (Read Only).
平台的快取儲存路徑
windows: C:/Users/xxxx/AppData/Local/Temp/CompanyName/ProductName
IPone: Application/???/Library/Caches
Android:  /data/data/Name/cache

參考: http://zxxcc0001.pixnet.net/blog/post/243195373-unity---%E5%90%84%E5%B9%B3%E5%8F%B0%E6%AA%94%E6%A1%88%E8%B7%AF%E5%BE%91

2018年3月28日 星期三

Unity -Uniy Common Region ( IOS, Android and Editor Only)


參考資料 https://docs.unity3d.com/Manual/PlatformDependentCompilation.html

各個版本 Region ----


#if UNITY_EDITOR
// your code
#endif

#if UNITY_IOS
  // your code
#endif

#if UNITY_ANDROID
  // your code
#endif

某個版本以上 Region ----

#if UNITY_X_Y_OR_NEWER
  // your code
#endif


  // unity version 5.3 以上
#if UNITY_5_3_OR_NEWER
  // your code
#endif

// unity version 2018.1 以上
#if UNITY_2018_1_OR_NEWER
 //your code
#endif

2018年1月31日 星期三

Unity - Deep Foreach Childs Component - 深度搜尋Compoent




GetComponentInChildren<Transform>();

這個方法 只會查找到 第一階層的兒子們
但有時候需求是 查找所有子孫 , 包括兒子的兒子 所有人

寫了一個Function 用遞迴的方式去找尋

程式碼 :
private void DeepForeachChildsCompoent<T>(Transform t, Action<T> Find) where T : Component
    {
        foreach (Transform child in t)
        {

            if (child == t)
                continue;

            T target = child.GetComponent<T>();
            if (target != null)
                Find(target);

            DeepForeachChildsCompoent<T>(child, Find);
        }
    }








使用方式: 
   印出所有找到的兒子 的名子 , 
   這裡Transfom 可以用任何其他Component 替代 , 就能過濾出相關的物件
結果: 最終把所有底下的東西 都找出來了 ( 不管多深層的物件都能查出來)