Ejemplo n.º 1
0
    public JoystickModule(GComponent mainView)
    {
        onMove = new EventListener(this, "onMove");
        onEnd  = new EventListener(this, "onEnd");

        _button = mainView.GetChild("joystick").asButton;
        _button.changeStateOnClick = false;
        _thumb     = _button.GetChild("thumb");
        _touchArea = mainView.GetChild("joystick_touch").asGraph;
        if (is_show_touch_rect)
        {
            _touchArea.DrawRect(_touchArea.width, _touchArea.height, 1, Color.gray, Color.clear);
        }
        _center        = mainView.GetChild("joystick_center");
        _frame         = mainView.GetChild("joystick_frame").asCom;
        _frame.visible = false;
        //GComponent frameView = UIPackage.CreateObject("Joystick", "frame").asCom;
        _frame_ctrler = _frame.GetController("button");

        _InitX       = _center.x + _center.width / 2;
        _InitY       = _center.y + _center.height / 2;
        touchId      = -1;
        radius       = 60;
        frame_radius = 106;
        locomotion   = Player.Locomotion.Idle;

        can_frame_touch = true;
        _touchArea.onTouchBegin.Add(this.onTouchDown);
    }
Ejemplo n.º 2
0
    private void OnTouchUp(EventContext context)
    {
        InputEvent inputEvt = (InputEvent)context.data;

        if (touchId != -1 && inputEvt.touchId == touchId)
        {
            touchId         = -1;
            _thumb.rotation = _thumb.rotation + 180;
            _center.visible = false;
            _frame.visible  = false;
            _tweener        = _button.TweenMove(new Vector2(_InitX - _button.width / 2, _InitY - _button.height / 2), 0.3f).OnComplete(() =>
            {
                _tweener         = null;
                _button.selected = false;
                _thumb.rotation  = 0;
                _center.visible  = true;
                _center.x        = _InitX - _center.width / 2;
                _center.y        = _InitY - _center.height / 2;
            }
                                                                                                                                       );
            locomotion = Player.Locomotion.Idle;

            Stage.inst.onTouchMove.Remove(this.OnTouchMove);
            Stage.inst.onTouchEnd.Remove(this.OnTouchUp);

            this.onEnd.Call();
        }
    }
Ejemplo n.º 3
0
    public void SetFrameState(FrameState state)
    {
        _frame_ctrler.SetSelectedIndex((int)state);
        switch (state)
        {
        case FrameState.NotTouch:
            locomotion = Player.Locomotion.walk;
            break;

        case FrameState.Touch:
            locomotion = Player.Locomotion.run;
            break;
        }
    }
Ejemplo n.º 4
0
    void FixedUpdate()
    {
        //Quaternion rotatio = ;
        //rotatio.z = 50;
        //Vector3 temp_vec = _joystick.GetTargetDirection();
        //Debug.Log("rotation = " + temp_vec.x + " "+ temp_vec.y + " " + temp_vec.z);
        if (_joystick.IsMove())
        {
            Rigidbody  r              = GetComponent <Rigidbody>();
            Vector3    targetDir      = _joystick.GetTargetDirection();
            Quaternion targetRotation = Quaternion.LookRotation(targetDir, Vector3.up);
            transform.rotation = targetRotation;
            //Quaternion newRotation = Quaternion.Lerp(r.rotation, targetRotation,
            //											_turnSmoothing * Time.deltaTime);
            //r.MoveRotation(newRotation);

            //_transform.rotation = new Quaternion(0, _joystick.GetRotation(), 0, 0);
        }
        Player.Locomotion locomotion = _joystick.GetLocomotion();
        float             speed      = 0f;

        switch (locomotion)
        {
        case Player.Locomotion.Idle:
            speed = 0;
            break;

        case Player.Locomotion.walk:
            speed = _walkSpeed;
            break;

        case Player.Locomotion.run:
            speed = _runSpeed;
            break;
        }
        ;
        _animator.SetFloat(hash.SpeedFloat, speed, _speedDampTime, Time.deltaTime);

        //AnimatorStateInfo animatorInfo = _animator.GetCurrentAnimatorStateInfo(0);
        //if (animatorInfo.IsName("Run")) {
        //    _animator.speed = 2f;
        //} else {
        //    _animator.speed = 1f;
        //}
    }
Ejemplo n.º 5
0
    private void onTouchDown(EventContext context)
    {
        if (touchId == -1)        //First touch
        {
            InputEvent evt = (InputEvent)context.data;
            touchId = evt.touchId;

            if (_tweener != null)
            {
                _tweener.Kill();
                _tweener = null;
            }

            Vector2 pt = GRoot.inst.GlobalToLocal(new Vector2(evt.x, evt.y));
            float   bx = pt.x;
            float   by = pt.y;
            _button.selected = true;

            if (bx < 0)
            {
                bx = 0;
            }
            else if (bx > _touchArea.width)
            {
                bx = _touchArea.width;
            }

            if (by > GRoot.inst.height)
            {
                by = GRoot.inst.height;
            }
            else if (by < _touchArea.y)
            {
                by = _touchArea.y;
            }

            _lastStageX  = bx;
            _lastStageY  = by;
            _startStageX = bx;
            _startStageY = by;

            _frame.visible = true;
            _frame.x       = bx - _frame.width / 2;
            _frame.y       = by - _frame.height / 2;

            _center.visible = true;
            _center.x       = bx - _center.width / 2;
            _center.y       = by - _center.height / 2;
            _button.x       = bx - _button.width / 2;
            _button.y       = by - _button.height / 2;

            float deltaX  = bx - _InitX;
            float deltaY  = by - _InitY;
            float degrees = Mathf.Atan2(deltaY, deltaX) * 180 / Mathf.PI;
            _thumb.rotation = degrees + 90;
            rotation        = degrees;
            targetDir       = new Vector3(deltaY, 0, deltaX);
            locomotion      = Player.Locomotion.walk;

            Stage.inst.onTouchMove.Add(this.OnTouchMove);
            Stage.inst.onTouchEnd.Add(this.OnTouchUp);
        }
    }