コード例 #1
0
        private void Move(Message msg)
        {
            var axis = (msg.Data as Vector3Data).Value;

            axis = axis.normalized;

            //Rotate move in camera space
            //            axis = Quaternion.Euler(0, 0 - transform.eulerAngles.y +
            //                Camera.main.transform.parent.transform.eulerAngles.y, 0) * axis;
            //
            //            axis.x *=  _transformData.MovementConfig.SideSpeed;
            _curSpeed = Mathf.Lerp(_curSpeed, _speedMode[(int)_transformData.CurrentSpeedMode], Time.deltaTime * 10);
            //            axis.z *= axis.z > 0 ? _curSpeed :  _transformData.MovementConfig.SideSpeed;
            //
            //            transform.Translate(axis * Time.deltaTime);

            var pos = transform.position;

            pos = pos +
                  transform.forward * axis.z * Time.deltaTime *
                  (axis.z > 0 ? _curSpeed : _transformData.MovementConfig.SideSpeed);

            var sign = Vector3.Angle(transform.forward, Camera.main.gameObject.transform.forward) > 80 ? -1 : 1;

            pos = pos +
                  transform.right * axis.x * sign * Time.deltaTime * _transformData.MovementConfig.SideSpeed;

            transform.position = Vector3.Lerp(transform.position, pos, Time.deltaTime * 500);

            MessageBus.SendMessage(SubscribeType.Channel, Channel.ChannelIds[SubscribeType.Channel],
                                   CommonMessage.Get(API.Messages.UPDATE_POSITION,
                                                     Vector3Data.GetVector3Data(transform.position)));
        }
コード例 #2
0
        private void FixedUpdate()
        {
            var lerpPercentage = (Time.time - timeStartedLerping) / timeToLerp;

            transform.position = Vector3.Lerp(lastRealPosition, realPosition, lerpPercentage);

            if (!SendMove)
            {
                return;
            }

            Debug.Log(Vector3.Angle(transform.forward, realPosition - lastRealPosition));

            if (Vector3.Distance(realPosition, lastRealPosition) < 0.01f)
            {
                MessageBus.SendMessage(SubscribeType.Channel, Channel.ChannelIds[SubscribeType.Channel],
                                       CommonMessage.Get(API.Messages.MOVE, Vector3Data.GetVector3Data(Vector3.zero)));
            }
            else
            {
                MessageBus.SendMessage(SubscribeType.Channel, Channel.ChannelIds[SubscribeType.Channel],
                                       CommonMessage.Get(API.Messages.MOVE,
                                                         Vector3Data.GetVector3Data(Quaternion.Inverse(transform.rotation) * (realPosition - lastRealPosition))));
            }
        }
コード例 #3
0
        public void FollowCursor(Message msg)
        {
            var cursorPos = (msg.Data as Vector3Data).Value;

            _ray = Camera.main.ScreenPointToRay(cursorPos);

            if (Physics.Raycast(_ray, out _hit, 2000f, _aimTargetData.ExcludeAimLayers))
            {
                transform.position = Vector3.MoveTowards(transform.position,
                                                         new Vector3(_hit.point.x, _hit.point.y - 1.32f, _hit.point.z), Time.deltaTime * _speed);
            }

            MessageBus.SendMessage(SubscribeType.Channel, Channel.ChannelIds[SubscribeType.Channel],
                                   CommonMessage.Get(API.Messages.UPDATE_AIM_TARGET_POSITION,
                                                     Vector3Data.GetVector3Data(_aimTargetData.AimTargetObject.position)));
        }
コード例 #4
0
        private void FixedUpdate()
        {
            var lerpPercentage = (Time.time - timeStartedLerping) / timeToLerp;

            transform.position = Vector3.Lerp(lastRealPosition, realPosition, lerpPercentage);

            //if (Vector3.Distance(realPosition, lastRealPosition) < 0.01f)
            //{
            //    MessageBus.SendMessage(SubscribeType.Channel, Channel.ChannelIds[SubscribeType.Channel],
            //        CommonMessage.Get(API.Messages.MOVE, Vector3Data.GetVector3Data(Vector3.zero)));
            //}
            //else
            //{
            var localRot  = transform.localRotation;
            var direction = realPosition - lastRealPosition;

            MessageBus.SendMessage(SubscribeType.Channel, Channel.ChannelIds[SubscribeType.Channel],
                                   CommonMessage.Get(API.Messages.MOVE,
                                                     Vector3Data.GetVector3Data(Quaternion.Inverse(localRot) * direction)));
            //}
        }
コード例 #5
0
        public void FollowCursor(Message msg)
        {
            var cursorPos = (msg.Data as Vector3Data).Value;

            _ray = Camera.main.ScreenPointToRay(cursorPos);

            if (Physics.Raycast(_ray, out _hit, 2000f, _aimTargetData.TargetsAimLayers))
            {
                _aimTargetData.AimTargetObject.transform.parent.GetComponent <MeshRenderer>().enabled = false;

                transform.position = Vector3.MoveTowards(transform.position,
                                                         new Vector3(_hit.point.x, _hit.point.y - 1.32f, _hit.point.z), Time.deltaTime * _speed);

                _aimTargetData.StickyAimObject.position = Vector3.MoveTowards(transform.position,
                                                                              _hit.point, Time.deltaTime * _speed);
            }
            else if (Physics.Raycast(_ray, out _hit, 2000f, _aimTargetData.ExcludeAimLayers))
            {
                _aimTargetData.AimTargetObject.transform.parent.GetComponent <MeshRenderer>().enabled = true;

                var finalPos = new Vector3(_hit.point.x, _hit.point.y, _hit.point.z);

                transform.position = Vector3.MoveTowards(transform.position,
                                                         finalPos, Time.deltaTime * _speed);
            }

            MessageBus.SendMessage(SubscribeType.Channel, Channel.ChannelIds[SubscribeType.Channel],
                                   CommonMessage.Get(API.Messages.UPDATE_AIM_TARGET_POSITION,
                                                     Vector3Data.GetVector3Data(_aimTargetData.AimTargetObject.position)));

            if (_aimTargetData.ResultTargetObject == null)
            {
                return;
            }

            MessageBus.SendMessage(SubscribeType.Channel, Channel.ChannelIds[SubscribeType.Channel],
                                   CommonMessage.Get(API.Messages.UPDATE_RESULT_TARGET_POSITION,
                                                     Vector3Data.GetVector3Data(_aimTargetData.ResultTargetObject.position)));
        }
コード例 #6
0
 public void Update()
 {
     MessageBus.SendMessage(SubscribeType.Channel, Channel.ChannelIds[SubscribeType.Channel],
                            CommonMessage.Get(API.Messages.UPDATE_AIM_TARGET_POSITION,
                                              Vector3Data.GetVector3Data(_aimTargetData.AimTargetObject.position)));
 }
コード例 #7
0
        private void Move(Message msg)
        {
            if (charController.isGrounded)
            {
                start = true;
            }

            if (!start)
            {
                return;
            }

            if (_isGrounded && !IsGround())
            {
                MessageBus.SendMessage(SubscribeType.Channel, Channel.ChannelIds[SubscribeType.Channel],
                                       CommonMessage.Get(API.Messages.IN_FLIGHT_START));
                _isGrounded = false;
            }

            if (!_isGrounded && IsGround())
            {
                MessageBus.SendMessage(SubscribeType.Channel, Channel.ChannelIds[SubscribeType.Channel],
                                       CommonMessage.Get(API.Messages.IN_FLIGHT_END));
                _isGrounded = true;
            }


            var axis = (msg.Data as Vector3Data).Value;

            axis = axis.normalized;

            //Rotate move in camera space
//            axis = Quaternion.Euler(0, 0 - transform.eulerAngles.y +
//                Camera.main.transform.parent.transform.eulerAngles.y, 0) * axis;
//
//            axis.x *=  _transformData.MovementConfig.SideSpeed;
            _curSpeed = Mathf.Lerp(_curSpeed, _speedMode[(int)_transformData.CurrentSpeedMode], Time.deltaTime * 10);
            //            axis.z *= axis.z > 0 ? _curSpeed :  _transformData.MovementConfig.SideSpeed;
            //
            //            transform.Translate(axis * Time.deltaTime);

            var pos = transform.position;

            pos = pos +
                  transform.forward * axis.z * Time.deltaTime *
                  (axis.z > 0 ? _curSpeed : _transformData.MovementConfig.SideSpeed);

            var sign = Vector3.Angle(transform.forward, Camera.main.gameObject.transform.forward) > 80 ? -1 : 1;

            pos = pos +
                  transform.right * axis.x * sign * Time.deltaTime * _transformData.MovementConfig.SideSpeed;

            //transform.position = Vector3.Lerp(transform.position, pos, Time.deltaTime * 500);

            if (charController.isGrounded)
            {
                // We are grounded, so recalculate
                // move direction directly from axes

                moveDirection = new Vector3(
                    axis.x * sign * _transformData.MovementConfig.SideSpeed,
                    0.0f,
                    axis.z * (axis.z > 0 ? _curSpeed : _transformData.MovementConfig.SideSpeed));

                moveDirection = transform.TransformDirection(moveDirection);

                if (Input.GetKeyDown(KeyCode.Space))
                {
                    moveDirection.y = 9.0f;
                }
            }

            // Apply gravity
            //if(moveDirection.y > 0)
            moveDirection.y = moveDirection.y - (20 * Time.deltaTime);

            // Move the controller
            charController.Move(moveDirection * Time.deltaTime);

            MessageBus.SendMessage(SubscribeType.Channel, Channel.ChannelIds[SubscribeType.Channel],
                                   CommonMessage.Get(API.Messages.UPDATE_POSITION,
                                                     Vector3Data.GetVector3Data(transform.position)));

            //Debug.Log("is grounded! :" + charController.isGrounded);
            //Debug.Log("my is grounded! :" + IsGround());
        }
コード例 #8
0
        void Update()
        {
            MessageBus.SendMessage(CommonMessage.Get(API.Messages.UPDATE_CURSOR_POS,
                                                     Vector3Data.GetVector3Data(Input.mousePosition)));

            _inputVector.x = Input.GetAxis("Horizontal");
            _inputVector.z = Input.GetAxis("Vertical");

            MessageBus.SendMessage(CommonMessage.Get(API.Messages.UPDATE_AXIS,
                                                     Vector3Data.GetVector3Data(_inputVector)));

            if (Input.GetAxis("Mouse ScrollWheel") > 0f)
            {
                MessageBus.SendMessage(CommonMessage.Get(API.Messages.MOUSE_WHELL_FORWARD));
            }
            else if (Input.GetAxis("Mouse ScrollWheel") < 0f)
            {
                MessageBus.SendMessage(CommonMessage.Get(API.Messages.MOUSE_WHELL_BACK));
            }

            if (Input.GetMouseButton(0))
            {
                MessageBus.SendMessage(CommonMessage.Get(API.Messages.LMOUSE_PRESSED));
            }

            if (Input.GetMouseButtonDown(0))
            {
                MessageBus.SendMessage(CommonMessage.Get(API.Messages.LMOUSE_PRESSED_DOWN));
            }

            if (Input.GetMouseButtonUp(0))
            {
                MessageBus.SendMessage(CommonMessage.Get(API.Messages.LMOUSE_PRESSED_UP));
            }

            //            if (Input.GetMouseButtonDown(1))
            //            {
            //                MessageBus.SendMessage(ObjectData.GetMessage(API.Messages.RMOUSE_DOWN));
            //            }
            //            else if (Input.GetMouseButtonUp(1))
            //            {
            //                MessageBus.SendMessage(ObjectData.GetMessage(API.Messages.RMOUSE_UP));
            //            }

            if (Input.GetKeyDown(KeyCode.R))
            {
                MessageBus.SendMessage(CommonMessage.Get(API.Messages.R_PRESSED));
            }

            if (Input.GetKeyDown(KeyCode.F))
            {
                MessageBus.SendMessage(CommonMessage.Get(API.Messages.F_PRESSED));
            }

            if (Input.GetKeyDown(KeyCode.B))
            {
                MessageBus.SendMessage(CommonMessage.Get(API.Messages.B_PRESSED));
            }

            if (Input.GetKeyDown(KeyCode.H))
            {
                MessageBus.SendMessage(CommonMessage.Get(API.Messages.H_PRESSED));
            }

            if (Input.GetKeyDown(KeyCode.Tab))
            {
                MessageBus.SendMessage(CommonMessage.Get(API.Messages.TAB_PRESSED));
            }
        }