在unity中调用引用了资源的java代码时,必须用动态获取资源。
下面是一段测试代码
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.story_post_test); KakaoLog.i("R.drawable.story_post_test="+R.drawable.story_post_test); KakaoLog.i("bitmap="+bitmap); int resID = getResources().getIdentifier("story_post_test", "drawable", getCurrentActivity().getPackageName()); Drawable drawable = getResources().getDrawable(resID); KakaoLog.i("drawable="+drawable); Bitmap bitmap1 = BitmapFactory.decodeResource(getResources(), resID); KakaoLog.i("R.drawable.story_post_test="+resID); KakaoLog.i("bitmap1="+bitmap1);
运行结果