Laya商用グレードの3D戦闘_017読み込み遷移ページ

このセクションの目的:トランジションページの読み込みを実現する

ラヤコマーシャル3Dゲーム開発

プロジェクトの不完全な部分があり
ます。homeview.tsを参照してください。

onOpened(data) {....
    //场景读取需要时间,所以在文件读取中会有空白间隔
    SceneManager.LoadSceneByName('Home', this, this.OnSceneLoadOk);

ここに写真の説明を挿入

問題を解く

新しいloadind.scene

次のスタイルにします
ここに写真の説明を挿入

View.zoder = 1;レンダリング順序を設定します

新しいスクリプトLoadingView.ts

「./BaseView」からBaseViewをインポートします。
「…/ GameSample」から{GameSample}をインポートします。

エクスポートクラスLoadingViewArg { subpackgeName = ''; loadokfunc:関数; 発信者:任意; }



//超カジュアルなゲームでは、最も時間のかかる部分はリソースをダウンロードする時間です。この場合の進行状況バーは、ダウンロードの進行状況
エクスポートのデフォルトクラスです。LoadingViewはBaseViewを拡張します{

loadingProgressBar: Laya.ProgressBar;
loadingProgressLabel: Laya.Label;
fileLoadOk = false;
public static instance: LoadingView;
/** 0-1 */
currentProgress = 0;
arg: LoadingViewArg;
onAwake() {
    super.onAwake()
    LoadingView.instance = this;
    this.loadingProgressBar.value = 0;
}

public startLoad() {
    this.fileLoadOk = true;
    Laya.timer.frameLoop(10, this, this.loopUpdate);
}

private loopUpdate() {
    //在编辑模式或者非分包模式直接进度条为1,因为不需要下载任何资源
    if (this.fileLoadOk) {
        this.currentProgress = 1;
    }

    if (GameSample.commonData.OnIOS || GameSample.commonData.OnPc
        || Laya.Browser.onQGMiniGame || Laya.Browser.onVVMiniGame)
        this.currentProgress *= 1;
    else
        this.currentProgress *= 0.01;

    this.loadingProgressBar.value = this.currentProgress;
    this.loadingProgressLabel.text = Math.floor(this.currentProgress * 100) + '%';

    if (this.fileLoadOk) {
        Laya.timer.clear(this, this.loopUpdate);
        this.arg.loadokfunc.call(this.arg.callder)
    }

}
onClosed() {
    LoadingView.instance = null;
    super.onClosed();
    Laya.timer.clear(this, this.loopUpdate);
    this.destroy(true);
    //清空不用的资源
    Laya.Resource.destroyUnusedResources();

}

}

viewMgr.ts

增加
パブリックOpenHome_loadingeffect(callder、callbackFunc:関数){

    Laya.Scene.open(SceneType.loading, false, Laya.Handler.create(callder, view => {
        let loadingView = view as LoadingView;
        let viewArg = new LoadingViewArg();
        viewArg.subpackgeName = 'Home';
        viewArg.callder = this;

        viewArg.loadokfunc = () => {
            this.OpenHome(callder, callbackFunc);
        }

        loadingView.arg = viewArg;
        loadingView.startLoad();

    }));
}

public OpenGame_loadingeffect(callder、callbackFunc:Function){ Laya.Scene.open(SceneType.loading、false、Laya.Handler.create(callder、view => { let LoadingView = view as LoadingView; let viewArg = new LoadingViewArg(); viewArg .subpackgeName = 'ゲーム'; viewArg.callder = this;




        viewArg.loadokfunc = () => {
            Laya.Scene.open(SceneType.Game, false, Laya.Handler.create(callder, view => {
                let s = view as GameView;
                if (callbackFunc != null)
                    callbackFunc.apply(callder);
            }));
        }
        loadingView.arg = viewArg;
        loadingView.startLoad();

    }));
}

GameSample.ts增加
publicstatic
GotoHomeLoadEffect(){ ViewMgr.instance.OpenHome_loadingeffect(null、null)}

public static StartGame_LoadEffect(){

    ViewMgr.instance.OpenGame_loadingeffect(this, (view) => {

        SceneManager.LoadSceneByName('Game', this, this.OnGameSceneLoadOk);
    })

}
修改
静的OnGameSceneLoadOk(p_Scene3D:Laya.Scene3D){ Laya.stage.addChildAt(p_Scene3D、0);

    SceneManager.game = p_Scene3D;
    p_Scene3D.addComponent(Game);

    //增加
    if (LoadingView.instance != null) {
        LoadingView.instance.close();
    }
}

Iniview.ts

onAwake() {
super.onAwake()
// GameSample.GotoHome();
GameSample.GotoHomeLoadEffect();
}

Homeview.tsの読み込みが完了したら
、ページを閉じます

OnSceneLoadOk
if(LoadingView.instance!= null){ LoadingView.instance.close(); }

OnStartImageClick
// GameSample.StartGame();
GameSample.StartGame_LoadEffect();

F8 f5

ここに写真の説明を挿入

Homeview.tsを変更します
OnStartImageClick(){

    console.log('OnStartImageClick');
    this.scene3D.destroy(true);
    this.close();
    //GameSample.StartGame();
    GameSample.StartGame_LoadEffect()
}

OverView.ts
noclick(){ console.log( 'noclick');

    Game.instance.scene.destroy(true)
    this.close()
    //GameSample.GotoHome();
    GameSample.GotoHomeLoadEffect();
}

F8 f5

要約すると、このセクションでは、ページを読み取って読み込みプロセスの空白の段階を解決するための遷移メソッドを追加します

トランジションページは、最初のページ、ホームページ、ゲームページ、終了ページでそれぞれホームページに戻るときに使用されます。
ここに写真の説明を挿入

おすすめ

転載: blog.csdn.net/koljy111/article/details/108020414