• Android应用内嵌unity3d游戏项目


    在一个现有的Android项目中嵌入unity3d项目

    1.将unity3d项目导出android工程

     

    2.将第一步导出的Android工程中assets文件夹和libs文件夹下的所有内容复制到Android项目中对应的assets和libs文件夹下

    3.Android调转到unity

    package com.jxkj.testandroid;
    
    
    import android.support.v7.app.ActionBarActivity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    
    
    public class MainActivity extends ActionBarActivity {
        Button startGameBtn;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            
            startGameBtn = (Button) findViewById(R.id.StartGameButton);
            startGameBtn.setOnClickListener(new OnClickListener() {
                
                @Override
                public void onClick(View v) {
                    GotoGameActivity();
                }
            });
        }
        
        void GotoGameActivity(){
    
            Intent intent = new Intent(this,GameActivity.class);
    
            startActivity(intent);
    
            }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
    
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // Handle action bar item clicks here. The action bar will
            // automatically handle clicks on the Home/Up button, so long
            // as you specify a parent activity in AndroidManifest.xml.
            int id = item.getItemId();
            if (id == R.id.action_settings) {
                return true;
            }
            return super.onOptionsItemSelected(item);
        }
    }
    MainActivity.java

    package com.jxkj.testandroid;
    
    import com.unity3d.player.UnityPlayer;
    
    import android.app.Activity;
    import android.os.Bundle;
    
    public class GameActivity extends Activity{
        UnityPlayer mUnityPlayer;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            mUnityPlayer = new UnityPlayer(this);
            setContentView(mUnityPlayer);
            //setContentView(R.layout.activity_main);
        }
        
        // Resume Unity
        @Override protected void onResume()
        {
            super.onResume();
            mUnityPlayer.resume();
        }
    
        // Notify Unity of the focus change.
        @Override public void onWindowFocusChanged(boolean hasFocus)
        {
            super.onWindowFocusChanged(hasFocus);
            mUnityPlayer.windowFocusChanged(hasFocus);
        }
        
        @Override  
        public void onBackPressed() {  
            runOnUiThread(new Runnable() {  
                @Override  
                public void run() {  
                mUnityPlayer.quit();  
                }  
            });  
            super.onBackPressed();  
        }
    }
    GameActivity.java
  • 相关阅读:
    vue中判断APP 为ios系统 安卓系统 浏览器判断 微信 qq 支付宝
    vconsole调试工具使用
    vue 电话号中间四位****代替
    vue中使用倒计时
    在APP中ios输入账号和密码时键盘闪烁
    vue中返回随机数
    vue 阿里云的滑动验证
    从零开发一套完整的vue项目开发环境
    vue中修改第三方组件中的样式
    nginx 启动报错dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
  • 原文地址:https://www.cnblogs.com/ring1992/p/7827521.html
Copyright © 2020-2023  润新知