随笔记录2

来源:互联网 发布:win10办公软件下载 编辑:程序博客网 时间:2024/06/16 11:45

1. unity提供了AndroidJavaClass支持,直接贴源码:

                if( nativeManager == null ){using( var jc = new AndroidJavaClass( "cn.easyar.android.NativeManager" ) )   nativeManager = jc.CallStatic<AndroidJavaObject>( "instance" );}string sdCardPath = nativeManager.Call<string>("GetExternalStoragePath");Debug.Log("SDCard Path : " + sdCardPath);if( sdCardPath != null && sdCardPath != "" ){// create SightPlus picture directory.if( !System.IO.Directory.Exists( System.IO.Path.Combine (sdCardPath, "Pictures") ) ){try{System.IO.Directory.CreateDirectory( System.IO.Path.Combine (sdCardPath, "Pictures") );}catch{Debug.Log("Create Pictures dir failed");}}if( !System.IO.Directory.Exists( System.IO.Path.Combine (sdCardPath, "Pictures/SightPlus") ) ){try{System.IO.Directory.CreateDirectory( System.IO.Path.Combine (sdCardPath, "Pictures/SightPlus") );}catch{Debug.Log("Create Pictures dir failed");}}if( System.IO.Directory.Exists( System.IO.Path.Combine (sdCardPath, "Pictures/SightPlus") ) ){screenshotRootPathForAndroid = System.IO.Path.Combine (sdCardPath, "Pictures/SightPlus");}}


2. UnityEngine下面的structure可以在子线程中调用,如Vector3, Color,说白了就是不继承UnityEngine.Object的对象。


3. 协程与多线程毫无关系,是多帧执行代码的方式,其他引擎也有类似的框架。原本一帧内完成的繁重工作 放到多帧里去执行,避免了卡帧的情况。贴个使用技巧:

<span style="white-space:pre"></span>float lastBreakTime = Time.time;for (int px=0; px<rpixels.Length; px++) {rpixels [px] = source.GetPixelBilinear (incX * ((float)px % targetWidth), flip ? 1 - incY * ((float)Mathf.Floor (px / targetWidth)<span style="white-space:pre"></span>) : incY * ((float)Mathf.Floor (px / targetWidth)));if (Time.time - lastBreakTime > 0.03f) {lastBreakTime = Time.time;yield return 0;}}


0 0