import { Laya } from "Laya" ; import { Animator } from "laya/d3/component/Animator" ; import { AnimatorState } from "laya/d3/component/AnimatorState" ; import { Camera } from "laya/d3/core/Camera" ; import { DirectionLight } from "laya/d3/core/light/DirectionLight" ; import { Scene3D } from "laya/d3/core/scene/Scene3D" ; import { Sprite3D } from "laya/d3/core/Sprite3D" ; import { Matrix4x4 } from "laya/d3/math/Matrix4x4" ; import { Quaternion } from "laya/d3/math/Quaternion" ; import { Vector3 } from "laya/d3/math/Vector3" ; import { Stage } from "laya/display/Stage" ; import { Event } from "laya/events/Event" ; import { Loader } from "laya/net/Loader" ; import { Button } from "laya/ui/Button" ; import { Browser } from "laya/utils/Browser" ; import { Handler } from "laya/utils/Handler" ; import { Stat } from "laya/utils/Stat" ; import { Utils } from "laya/utils/Utils" ; import { Laya3D } from "Laya3D" ; import Client from "../../Client" ; import { CameraMoveScript } from "../common/CameraMoveScript" ; author ...
  export class BoneLinkSprite3D { private scene : Scene3D ; private role : Sprite3D ; private pangzi : Sprite3D ; private dragon1 : Sprite3D ; private dragon2 : Sprite3D ; private aniSprte3D1 : Sprite3D ; private aniSprte3D2 : Sprite3D ; private animator : Animator ; private dragonAnimator1 : Animator ; private dragonAnimator2 : Animator ; private _dragonScale : Vector3 = new Vector3 ( 1.5 , 1.5 , 1.5 ) ; private _rotation : Quaternion = new Quaternion ( - 0.5 , - 0.5 , 0.5 , - 0.5 ) ; private _position : Vector3 = new Vector3 ( - 0.2 , 0.0 , 0.0 ) ; private _scale : Vector3 = new Vector3 ( 0.75 , 0.75 , 0.75 ) ; private _translate : Vector3 = new Vector3 ( 0 , 3 , 5 ) ; private _rotation2 : Vector3 = new Vector3 ( - 15 , 0 , 0 ) ; private _forward : Vector3 = new Vector3 ( - 1.0 , - 1.0 , - 1.0 ) ; private changeActionButton : Button ; private curStateIndex : number = 0 ; /**实例类型*/ private btype : any = "BoneLinkSprite3D" ; /**场景内按钮类型*/ private stype : any = 0 ; constructor ( ) { Laya3D . init ( 0 , 0 ) ; Laya . stage . scaleMode = Stage . SCALE_FULL ; Laya . stage . screenMode = Stage . SCREEN_NONE ; Stat . show ( ) ; var resource = [ "res/threeDimen/skinModel/BoneLinkScene/R_kl_H_001.lh" , "res/threeDimen/skinModel/BoneLinkScene/R_kl_S_009.lh" , "res/threeDimen/skinModel/BoneLinkScene/PangZi.lh" ] ; Laya . loader . create ( resource , Handler . create ( this , this . onLoadFinish ) ) ; } private onLoadFinish ( ) { this . scene = ( < Scene3D > Laya . stage . addChild ( new Scene3D ( ) ) ) ; this . scene . ambientColor . setValue ( 0.5 , 0.5 , 0.5 ) ; var camera = ( < Camera > this . scene . addChild ( new Camera ( 0 , 0.1 , 100 ) ) ) ; camera . transform . translate ( this . _translate ) ; camera . transform . rotate ( this . _rotation2 , true , false ) ; camera . addComponent ( CameraMoveScript ) ; var directionLight = ( < DirectionLight > this . scene . addChild ( new DirectionLight ( ) ) ) ; var mat = directionLight . transform . worldMatrix ; mat . setForward ( this . _forward ) ; directionLight . transform . worldMatrix = mat ; this . role = ( < Sprite3D > this . scene . addChild ( new Sprite3D ( ) ) ) ; this . pangzi = ( < Sprite3D > this . role . addChild ( Loader . getRes ( "res/threeDimen/skinModel/BoneLinkScene/PangZi.lh" ) ) ) ; this . animator = ( < Animator > this . pangzi . getChildAt ( 0 ) . getComponent ( Animator ) ) ; var state1 = new AnimatorState ( ) ; state1 . name = "hello" ; state1 . clipStart = 296 / 581 ; state1 . clipEnd = 346 / 581 ; state1 . clip = this . animator . getDefaultState ( ) . clip ; state1 . clip . islooping = true ; this . animator . getControllerLayer ( 0 ) . addState ( state1 ) ; this . animator . play ( "hello" ) ; var state2 = new AnimatorState ( ) ; state2 . name = "ride" ; state2 . clipStart = 3 / 581 ; state2 . clipEnd = 33 / 581 ; state2 . clip = this . animator . getDefaultState ( ) . clip ; state2 . clip . islooping = true ; this . animator . getControllerLayer ( 0 ) . addState ( state2 ) ; this . dragon1 = Loader . getRes ( "res/threeDimen/skinModel/BoneLinkScene/R_kl_H_001.lh" ) ; this . dragon1 . transform . localScale = this . _dragonScale ; this . aniSprte3D1 = ( < Sprite3D > this . dragon1 . getChildAt ( 0 ) ) ; this . dragonAnimator1 = ( < Animator > this . aniSprte3D1 . getComponent ( Animator ) ) ; var state3 = new AnimatorState ( ) ; state3 . name = "run" ; state3 . clipStart = 50 / 644 ; state3 . clipEnd = 65 / 644 ; state3 . clip = this . dragonAnimator1 . getDefaultState ( ) . clip ; state3 . clip . islooping = true ; this . dragonAnimator1 . getControllerLayer ( 0 ) . addState ( state3 ) ; this . dragon2 = Loader . getRes ( "res/threeDimen/skinModel/BoneLinkScene/R_kl_S_009.lh" ) ; this . dragon2 . transform . localScale = this . _dragonScale ; this . aniSprte3D2 = ( < Sprite3D > this . dragon2 . getChildAt ( 0 ) ) ; this . dragonAnimator2 = ( < Animator > this . aniSprte3D2 . getComponent ( Animator ) ) ; var state4 = new AnimatorState ( ) ; state4 . name = "run" ; state4 . clipStart = 50 / 550 ; state4 . clipEnd = 65 / 550 ; state4 . clip = this . dragonAnimator2 . getDefaultState ( ) . clip ; state4 . clip . islooping = true ; this . dragonAnimator2 . getControllerLayer ( 0 ) . addState ( state4 ) ; this . loadUI ( ) ; } private loadUI ( ) { Laya . loader . load ( [ "res/threeDimen/ui/button.png" ] , Handler . create ( this , function ( ) : void { this . changeActionButton = ( < Button > Laya . stage . addChild ( new Button ( "res/threeDimen/ui/button.png" , "乘骑坐骑" ) ) ) ; this . changeActionButton . size ( 160 , 40 ) ; this . changeActionButton . labelBold = true ; this . changeActionButton . labelSize = 30 ; this . changeActionButton . sizeGrid = "4,4,4,4" ; this . changeActionButton . scale ( Browser . pixelRatio , Browser . pixelRatio ) ; this . changeActionButton . pos ( Laya . stage . width / 2 - this . changeActionButton . width * Browser . pixelRatio / 2 , Laya . stage . height - 100 * Browser . pixelRatio ) ; this . changeActionButton . on ( Event . CLICK , this , this . stypeFun0 ) ; } ) ) ; } stypeFun0 ( label = "乘骑坐骑" ) { this . curStateIndex ++ ; if ( this . curStateIndex % 3 == 1 ) { this . changeActionButton . label = "切换坐骑" ; this . scene . addChild ( this . dragon1 ) ; this . aniSprte3D1 . addChild ( this . role ) ; this . dragonAnimator1 . linkSprite3DToAvatarNode ( "point" , this . role ) ; this . animator . play ( "ride" ) ; this . dragonAnimator1 . play ( "run" ) ; this . pangzi . transform . localRotation = this . _rotation ; this . pangzi . transform . localPosition = this . _position ; this . pangzi . transform . localScale = this . _scale ; } else if ( this . curStateIndex % 3 == 2 ) { this . changeActionButton . label = "卸下坐骑" ; this . dragonAnimator1 . unLinkSprite3DToAvatarNode ( this . role ) ; this . aniSprte3D1 . removeChild ( this . role ) ; this . dragon1 . removeSelf ( ) ; this . scene . addChild ( this . dragon2 ) ; this . aniSprte3D2 . addChild ( this . role ) ; this . dragonAnimator2 . linkSprite3DToAvatarNode ( "point" , this . role ) ; this . animator . play ( "ride" ) ; this . dragonAnimator2 . play ( "run" ) ; this . pangzi . transform . localRotation = this . _rotation ; this . pangzi . transform . localPosition = this . _position ; this . pangzi . transform . localScale = this . _scale ; } else { this . changeActionButton . label = "乘骑坐骑" ; this . dragonAnimator2 . unLinkSprite3DToAvatarNode ( this . role ) ; this . aniSprte3D2 . removeChild ( this . role ) ; this . dragon2 . removeSelf ( ) ; this . scene . addChild ( this . role ) ; this . animator . play ( "hello" ) ; } label = this . changeActionButton . label ; Client . instance . send ( { type : "next" , btype : this . btype , stype : 0 , value : label } ) ; } }