コード例 #1
0
        void TransformSelected()
        {
            if (Input.GetMouseButtonDown(0))
            {
                axis = selectedObj.Direction;
                previousMousePosition = Vector3.zero;
            }

            if (Input.GetMouseButton(0))
            {
                if (selectedObj.Actived)
                {
                    ray = viewCamera.ScreenPointToRay(Input.mousePosition);
                    Vector3 mousePosition = GeometryUtil.LinePlaneIntersect(ray.origin, ray.direction, selectedObj.StartPos, axis);
                    if (previousMousePosition != Vector3.zero && mousePosition != Vector3.zero)
                    {
                        var   vec1         = previousMousePosition - selectedObj.StartPos;
                        var   vec2         = mousePosition - selectedObj.StartPos;
                        float rotateAmount = (Vector3.Angle(Vector3.Cross(vec1, vec2), axis) < 180f ? 1 : -1)
                                             * Vector3.Angle(vec1, vec2) * 1;
                        selectedObj.Rotate(rotateAmount);
                    }
                    previousMousePosition = mousePosition;
                }
            }

            if (Input.GetMouseButtonUp(0))
            {
                selectedObj.Clamp();
                selectedObj = null;
            }
        }
コード例 #2
0
        private void TrySelectRotateObj()
        {
            if (viewCamera == null)
            {
                return;
            }

            ray = viewCamera.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit, distence, rotateItemLayerMask))
            {
                selectedObj = hit.collider.GetComponentInParent <RotateItem>();
            }
        }
コード例 #3
0
        public void Update()
        {
            if (Input.GetMouseButtonDown(0) && selectedObj == null)
            {
                TrySelectRotateObj();
            }

            if (selectedObj != null)
            {
                TransformSelected();
            }

            if (Input.GetMouseButtonUp(0))
            {
                selectedObj = null;
            }
        }