//播放动画 private void on_joystic_anima_update() { if (this.anim_state != charactor_state.idle && this.anim_state != charactor_state.walk) { //这里要播放动画等其他操作 return; } if (this.stick_x == 0 && this.stick_y == 0) { if (this.anim_state == charactor_state.walk) { this.anim.CrossFade("idle"); this.anim_state = charactor_state.idle; } return; } if (this.anim_state == charactor_state.idle) { this.anim.CrossFade("walk"); this.anim_state = charactor_state.walk; } this.do_joystick_event(Time.deltaTime);//同步英雄坐标 if (!this.is_ghost) { Camera.main.transform.position = this.transform.position + this.camera_offset; } }
public void logic_init(Vector3 logic_pos) { this.stick_x = 0; this.stick_y = 0; this.logic_position = logic_pos; this.logic_state = charactor_state.idle; }
//同步英雄坐标 private void do_joystick_event(float dt) { if (this.stick_x == 0 && this.stick_y == 0) { this.logic_state = charactor_state.idle; return; } this.logic_state = charactor_state.walk; Debug.Log(this.stick_x + " ---ed---- " + this.stick_y); float dir_x = ((float)this.stick_x / (float)(1 << 16)); float dir_y = ((float)this.stick_y / (float)(1 << 16)); Debug.Log(dir_x + " diry= " + dir_y); //float dir_x = (float)this.stick_x; //float dir_y = (float)this.stick_y; float r = Mathf.Atan2(dir_y, dir_x); float s = this.speed * dt; float sx = s * Mathf.Cos(r - Mathf.PI * 0.25f); float sz = s * Mathf.Sin(r - Mathf.PI * 0.25f); this.ctrl.Move(new Vector3(sx, 0, sz)); float degree = r * 180 / Mathf.PI; degree = 360 - degree + 90 + 45; this.transform.localEulerAngles = new Vector3(0, degree, 0); }
//处理遥杆事件 private void handle_joystic_event(OptionEvent opt) { this.stick_x = opt.x; this.stick_y = opt.y; if (this.stick_x == 0 && this.stick_y == 0) { this.logic_state = charactor_state.idle; } else { this.logic_state = charactor_state.walk; } }