Exemplo n.º 1
0
        void TransformSelected()
        {
            if (Input.GetMouseButtonDown(0))
            {
                direction             = (selectedObj.targetPos - selectedObj.startPos).normalized;
                previousMousePosition = Vector3.zero;
            }

            if (Input.GetMouseButton(0))
            {
                Vector3 mousePosition = Input.mousePosition;
                if (previousMousePosition != Vector3.zero && mousePosition != Vector3.zero)
                {
                    elementDistence         = Vector3.Distance(viewCamera.transform.position, selectedObj.transform.position);
                    previousMousePosition.z = mousePosition.z = elementDistence;
                    var dir = viewCamera.ScreenToWorldPoint(mousePosition) - viewCamera.ScreenToWorldPoint(previousMousePosition);
                    selectedObj.TryMove(Vector3.Project(dir, direction));
                }

                previousMousePosition = mousePosition;
            }

            if (Input.GetMouseButtonUp(0))
            {
                selectedObj.Clamp();
                selectedObj = null;
            }
        }
Exemplo n.º 2
0
        private bool TrySelectObj()
        {
            if (viewCamera == null)
            {
                return(false);
            }

            ray = viewCamera.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit, distence, LayerMask.GetMask(DragItem.layerName)))
            {
                var obj = hit.collider.GetComponentInParent <DragItem>();
                if (obj.Actived)
                {
                    selectedObj = obj;
                }
                else
                {
                    selectedObj = null;
                }
            }

            return(selectedObj != null);
        }