Unity3D点大逃杀运行后直接没了再点退出直接黑屏。

【代码片-1】 关于Unity启动时间过长(启动黑屏时间长)的问题
标签:unity&&&&游戏场景&&&&unityplayeractivity&&&&动画&&&&场景&&&&
package com.u3d.
import java.util.L
import android.annotation.SuppressL
import android.content.C
import android.graphics.drawable.AnimationD
import android.media.AudioM
import android.media.AudioManager.OnAudioFocusChangeL
import android.os.B
import android.os.H
import android.os.L
import android.util.DisplayM
import android.util.L
import android.view.LayoutI
import android.view.V
import android.widget.ImageV
import com.unity3d.player.UnityPlayerA
public class MainActivity extends UnityPlayerActivity
static final String TAG = &com.u3d.plugins&;
private ImageView bgView =
private View view =
AnimationDrawable animationDrawable =
@SuppressLint(&NewApi&) @Override
protected void onCreate(Bundle arg0)
super.onCreate(arg0);
bgView=new ImageView(this);
String lanStr=Locale.getDefault().getLanguage();
String bgName=&splash_bg_en&;
if(lanStr.equals(&zh&))
bgName=&splash_bg_zh&;
Log.d(TAG, &System Lan:&+bgName);
int splash_bg=getResources().getIdentifier(bgName, &drawable&, getPackageName());
bgView.setBackgroundResource(splash_bg);
this.addContentView(bgView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
mUnityPlayer.addView(bgView);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
float scaleX=dm.widthPixels/1024f;
float scaleY=dm.heightPixels/600f;
Log.d(TAG, &Screen Width:&+dm.widthPixels+&;Screen Height:&+dm.heightPixels);
LayoutInflater flater = LayoutInflater.from(this);
int layoutID=getResources().getIdentifier(&activity_splash&, &layout&, getPackageName());
view = flater.inflate(layoutID, null);
int frame_id=view.getResources().getIdentifier(&splash_frame&, &id&, getPackageName());
ImageView frameView=(ImageView)view.findViewById(frame_id);//new ImageView(this);
frameView.setBackgroundResource(R.anim.splash_gif);
this.addContentView(view, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
mUnityPlayer.addView(view);
frameView.setScaleX(scaleX);
frameView.setScaleY(scaleY);
frameView=new ImageView(this);
frameView.setBackgroundResource(R.anim.splash_gif);
LinearLayout ll=new LinearLayout(this);
LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
params.leftMargin=scaleX*620;
ll.setLayoutParams(params);
ll.addView(frameView);
mUnityPlayer.addView(ll);
animationDrawable = (AnimationDrawable) frameView.getBackground();
animationDrawable.start();
public void HideSplash()
Log.d(TAG, &HideSplash&);
new Handler(Looper.getMainLooper()).post(new Runnable()
public void run()
Log.d(TAG, &HideSplash run&);
animationDrawable.stop();
mUnityPlayer.removeView(bgView);
mUnityPlayer.removeView(view);
((ViewGroup)bgView.getParent()).removeView(bgView);
((ViewGroup)view.getParent()).removeView(view);
animationDrawable=
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
Log.d(TAG, &onRestart&);
new Handler(Looper.getMainLooper()).post(new Runnable()
public void run()
muteAudioFocus(MainActivity.this,true);
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
protected void onPause()
// TODO Auto-generated method stub
super.onPause();
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
Log.d(TAG, &onStop&);
new Handler(Looper.getMainLooper()).post(new Runnable()
public void run()
muteAudioFocus(MainActivity.this,false);
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
Log.d(TAG, &onStart&);
new Handler(Looper.getMainLooper()).post(new Runnable()
public void run()
muteAudioFocus(MainActivity.this,true);
/**@param bMute 值为true时为关闭背景音乐。*/
public boolean muteAudioFocus(Context context, boolean bMute)
if(context == null)
Log.d(TAG, &context is null.&);
boolean bool =
AudioManager am = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
int result = am.requestAudioFocus(afChangeListener,AudioManager.STREAM_MUSIC,AudioManager.AUDIOFOCUS_GAIN);
bool = result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED;
int result = am.abandonAudioFocus(afChangeListener);
bool = result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED;
Log.d(TAG, &pauseMusic bMute=&+bMute +& result=&+bool);
OnAudioFocusChangeListener afChangeListener = new OnAudioFocusChangeListener()
public void onAudioFocusChange(int focusChange)
Log.d(TAG, &focusChange:&+focusChange);
if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT)
// Pause playback
else if (focusChange == AudioManager.AUDIOFOCUS_LOSS)
muteAudioFocus(MainActivity.this,false);
// Stop playback
else if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK)
// Lower the volume
else if (focusChange == AudioManager.AUDIOFOCUS_GAIN)
// Resume playback or Raise it back to normal
我要留言技术领域:
取消收藏确定要取消收藏吗?
删除图谱提示你保存在该图谱下的知识内容也会被删除,建议你先将内容移到其他图谱中。你确定要删除知识图谱及其内容吗?
删除节点提示无法删除该知识节点,因该节点下仍保存有相关知识内容!
删除节点提示你确定要删除该知识节点吗?unity一打开就黑屏,如何解决? - 知乎8被浏览1723分享邀请回答42 条评论分享收藏感谢收起0添加评论分享收藏感谢收起刚安装完了unity3d
运行后一直都是这个界面不动
求大神指教_unity3d吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:74,764贴子:
刚安装完了unity3d
运行后一直都是这个界面不动
求大神指教收藏
达内unity3d培训全程&实战教学&,unity3d金牌讲师授课.免费unity3d课程试听中!到达内unity3d学院学习unity3d,只需4个月速成unity3d游戏工程师.
安装路径不要出现中文
同问啊!!从官网下载的personal免费版打开后也是这个样子
搭车同问,我也是这种情况,应该怎么解决啊
同求!!!!!都卸载3次了
一样的...估计是他们的问题...
登录百度帐号推荐应用刚装的unity一打开就黑屏,如何解决? - 知乎8被浏览1517分享邀请回答22 条评论分享收藏感谢收起2963人阅读
javascript
Unity(2)
有些程序或者游戏要在用户关闭之前提示用户是否确定关闭改程序以避免用户误操作导致程序关闭,所以我们写以下代码防止用户误操作导致关闭,在此之前你可以通过pop一个alertView提示用户是否确定关闭此程序。
下面是代码:分析下代码在程序被点击关闭的时候会调用所有脚本的 OnApplictonQuit函数 然后我们通过调用一个异步函数实现block2秒钟 判断是否是否再次确认结束程序 如果是 就让程序结束 否则 调用异步函数再次block两秒Application.CancelQuit 取消退出
static function CancelQuit () : void
Description描述
Cancels quitting the application. This is useful for showing a splash screen at the end of a game.
取消退出。这可以用来在退出游戏的时候显示一个退出画面。
This function only works in the player and does nothing in the web player or editor. IMPORTANT: This function has no effect on iPhone. Application can not prevent termination under iPhone OS.
这个函数只工作在播发器中,在web播放器或编辑器中不做任何事。
注意,这个函数在iphone中没有效果,应用程序无法防止在iPhone OS的终止。
JavaScript
// Delays quitting for 2 seconds and
// 延迟2秒退出。
// loads the finalsplash level during that time.
// 在这段时间内加载退出画面
var showSplashTimeout : float = 2.0;
private var allowQuitting : boolean =
function Awake () {
// This game object needs to survive multiple levels
// 需要在多个关卡中使用的游戏物体
DontDestroyOnLoad (this);
function OnApplicationQuit () {
// If we haven't already load up the final splash screen level
// 如果我们还没有加载到最后的退出画面
if ( Application.loadedLevelName .ToLower() != &finalsplash&)
StartCoroutine(&DelayedQuit&);
// Don't allow the user to exit until we got permission in
// 如果我们还没有加载到最后的退出画面
if (!allowQuitting)
Application.CancelQuit ();
function DelayedQuit () {
Application.LoadLevel (&finalsplash&);
// Wait for showSplashTimeout
// 等待showSplashTimecout
yield WaitForSeconds (showSplashTimeout);
// then quit for real
// 然后退出
allowQuitting =
Application.Quit ();
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:7010次
排名:千里之外

我要回帖

更多关于 战地2运行后黑屏 的文章

 

随机推荐