美文网首页
动态更换3d物体贴图

动态更换3d物体贴图

作者: 沉麟 | 来源:发表于2019-12-05 14:49 被阅读0次
    export default class Score extends Base3DEntity {
    
        private _selfScore: Laya.MeshSprite3D;
        private _colon: Laya.MeshSprite3D;
        private _otherScore: Laya.MeshSprite3D;
        private _selfMat: Laya.BlinnPhongMaterial;
        private _otherMat: Laya.BlinnPhongMaterial;
        protected _anim: Laya.Animator;
        private _imgUrls = [];
    
        private static sInstance: Score = null;
        public static get Instance(): Score {
            if (this.sInstance == null) {
                this.sInstance = new Score();
            }
            return this.sInstance;
        }
    
        onAwake() {
    
            this._imgUrls.push("res/nums/0.png");
            this._imgUrls.push("res/nums/1.png");
            this._imgUrls.push("res/nums/2.png");
            this._imgUrls.push("res/nums/3.png");
            this._imgUrls.push("res/nums/4.png");
            this._imgUrls.push("res/nums/5.png");
            this._imgUrls.push("res/nums/6.png");
            this._imgUrls.push("res/nums/7.png");
            this._imgUrls.push("res/nums/8.png");
            this._imgUrls.push("res/nums/9.png");
            this._imgUrls.push("res/nums/Colon.png");
    
            this._selfScore = this.owner.getChildByName("SelfScore") as Laya.MeshSprite3D;
            this._colon = this.owner.getChildByName("Colon") as Laya.MeshSprite3D;
            this._otherScore = this.owner.getChildByName("OtherScore") as Laya.MeshSprite3D;
            this._anim = this.owner.getComponent(Laya.Animator);
            this._anim.play("ScoreHide", undefined, 0);
            this._selfMat = this._selfScore.meshRenderer.material as Laya.BlinnPhongMaterial;
            this._otherMat = this._otherScore.meshRenderer.material as Laya.BlinnPhongMaterial;
            Laya.loader.load(this._imgUrls, Laya.Handler.create(this, this.onCompelte));
    
        }
    
        onCompelte() {
            this._selfMat.albedoTexture = Laya.loader.getRes(this._imgUrls[0]);
            this._otherMat.albedoTexture = Laya.loader.getRes(this._imgUrls[0]);
        }
    
        /**
         * resetMat
         */
        public resetScore() {
            this._selfMat.albedoTexture = Laya.loader.getRes(this._imgUrls[0]);
            this._otherMat.albedoTexture = Laya.loader.getRes(this._imgUrls[0]);
        }
    
        /**
         * changeSocre
         */
        public changeSocre(uid: string) {
            if (uid == GameDataManager.Instance.uid) {
                this._selfMat.albedoTexture = Laya.loader.getRes(this._imgUrls[DynamicDataManager.Instance.selfScore]);
            } else {
                this._otherMat.albedoTexture = Laya.loader.getRes(this._imgUrls[DynamicDataManager.Instance.otherScore]);
            }
        }
    
        /**
         * showScore
         */
        public showScore() {
            this._anim.play("ScoreShow", undefined, 0);
        }
    
        /**
         * hideScore
         */
        public hideScore() {
            this._anim.play("ScoreHide", undefined, 0);
        }
    }
    

    相关文章

      网友评论

          本文标题:动态更换3d物体贴图

          本文链接:https://www.haomeiwen.com/subject/hgbdgctx.html