Ejemplo n.º 1
0
        void LateUpdate()
        {
            if (!target)
            {
                gameObject.SetActive(false);
                return;
            }
            if (autoScale)
            {
                transform.localScale =
                    Vector3.one * (Vector3.Distance(CameraModeChanger.Instance.ActiveCamera.transform.position, transform.position) * autoScaleFactor) / 15;
            }

            if (previousType != type || previousAxes != axes)
            {
                Clear();
                CreateHandles();
                previousType = type;
                previousAxes = axes;
            }

            HandleBase axis = GetAxis();

            HandleOverEffect(axis);

            if (Input.GetMouseButton(0) && draggingAxis != null)
            {
                draggingAxis.Interact(previousPosition);
                movedHandle.Invoke();
            }

            if (Input.GetMouseButtonDown(0) && axis != null)
            {
                draggingAxis = axis;
                draggingAxis.StartInteraction();

                TakeInteractionPriority();
            }

            if (Input.GetMouseButtonUp(0) && draggingAxis != null)
            {
                Debug.Log("End interaction");
                draggingAxis.EndInteraction();
                draggingAxis = null;

                StopInteraction();
            }

            previousPosition = Mouse.current.position.ReadValue();

            transform.position = target.transform.position;
            if (space == HandleSpace.LOCAL || type == HandleType.SCALE)
            {
                transform.rotation = target.transform.rotation;
            }
            else
            {
                transform.rotation = Quaternion.identity;
            }
        }
Ejemplo n.º 2
0
        void Update()
        {
            if (autoScale)
            {
                transform.localScale =
                    Vector3.one * (Vector3.Distance(handleCamera.transform.position, transform.position) * autoScaleFactor) / 15;
            }

            if (_previousType != type || _previousAxes != axes)
            {
                Clear();
                CreateHandles();
                _previousType = type;
                _previousAxes = axes;
            }

            HandleBase handle   = null;
            Vector3    hitPoint = Vector3.zero;

            GetHandle(ref handle, ref hitPoint);

            HandleOverEffect(handle);

            if (Input.GetMouseButton(0) && _draggingHandle != null)
            {
                _draggingHandle.Interact(_previousMousePosition);
            }

            if (Input.GetMouseButtonDown(0) && handle != null)
            {
                _draggingHandle = handle;
                _draggingHandle.StartInteraction(hitPoint);
            }

            if (Input.GetMouseButtonUp(0) && _draggingHandle != null)
            {
                _draggingHandle.EndInteraction();
                _draggingHandle = null;
            }

            _previousMousePosition = Input.mousePosition;

            transform.position = target.transform.position;
            if (space == HandleSpace.LOCAL || type == HandleType.SCALE)
            {
                transform.rotation = target.transform.rotation;
            }
            else
            {
                transform.rotation = Quaternion.identity;
            }
        }
Ejemplo n.º 3
0
        void HandleOverEffect(HandleBase p_axis)
        {
            if (draggingAxis == null && previousAxis != null && previousAxis != p_axis)
            {
                previousAxis.SetDefaultColor();
            }

            if (p_axis != null && draggingAxis == null)
            {
                p_axis.SetColor(Color.yellow);
            }

            previousAxis = p_axis;
        }
Ejemplo n.º 4
0
        void HandleOverEffect(HandleBase p_axis)
        {
            if (_draggingHandle == null && _previousAxis != null && _previousAxis != p_axis)
            {
                _previousAxis.SetDefaultColor();
            }

            if (p_axis != null && _draggingHandle == null)
            {
                p_axis.SetColor(Color.yellow);
            }

            _previousAxis = p_axis;
        }
Ejemplo n.º 5
0
        void Clear()
        {
            draggingAxis = null;

            if (positionHandle)
            {
                positionHandle.Destroy();
            }
            if (rotationHandle)
            {
                rotationHandle.Destroy();
            }
            if (scaleHandle)
            {
                scaleHandle.Destroy();
            }
        }
Ejemplo n.º 6
0
        void Clear()
        {
            _draggingHandle = null;

            if (_positionHandle)
            {
                _positionHandle.Destroy();
            }
            if (_rotationHandle)
            {
                _rotationHandle.Destroy();
            }
            if (_scaleHandle)
            {
                _scaleHandle.Destroy();
            }
        }
Ejemplo n.º 7
0
        private HandleBase GetAxis()
        {
            RaycastHit[] hits = Physics.RaycastAll(Selector.mainSelectorRay, 10000, LayerMask.GetMask(raycastLayerName));
            if (hits.Length == 0)
            {
                return(null);
            }

            foreach (RaycastHit hit in hits)
            {
                HandleBase axis = hit.collider.gameObject.GetComponentInParent <HandleBase>();
                if (axis != null)
                {
                    return(axis);
                }
            }
            return(null);
        }
Ejemplo n.º 8
0
        private void GetHandle(ref HandleBase p_handle, ref Vector3 p_hitPoint)
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            RaycastHit[] hits = Physics.RaycastAll(ray);
            if (hits.Length == 0)
            {
                return;
            }

            foreach (RaycastHit hit in hits)
            {
                p_handle = hit.collider.gameObject.GetComponentInParent <HandleBase>();

                if (p_handle != null)
                {
                    p_hitPoint = hit.point;
                    return;
                }
            }
        }
Ejemplo n.º 9
0
        public ScaleHandle Initialize(RuntimeTransformHandle p_parentTransformHandle)
        {
            _parentTransformHandle = p_parentTransformHandle;
            transform.SetParent(_parentTransformHandle.transform, false);

            _axes = new List <ScaleAxis>();

            if (_parentTransformHandle.axes == HandleAxes.X || _parentTransformHandle.axes == HandleAxes.XY || _parentTransformHandle.axes == HandleAxes.XZ || _parentTransformHandle.axes == HandleAxes.XYZ)
            {
                _axes.Add(new GameObject().AddComponent <ScaleAxis>()
                          .Initialize(_parentTransformHandle, Vector3.right, -Vector3.forward, Color.red));
            }

            if (_parentTransformHandle.axes == HandleAxes.Y || _parentTransformHandle.axes == HandleAxes.XY || _parentTransformHandle.axes == HandleAxes.YZ || _parentTransformHandle.axes == HandleAxes.XYZ)
            {
                _axes.Add(new GameObject().AddComponent <ScaleAxis>()
                          .Initialize(_parentTransformHandle, Vector3.up, Vector3.forward, Color.blue));
            }

            if (_parentTransformHandle.axes == HandleAxes.Z || _parentTransformHandle.axes == HandleAxes.XZ || _parentTransformHandle.axes == HandleAxes.YZ || _parentTransformHandle.axes == HandleAxes.XYZ)
            {
                _axes.Add(new GameObject().AddComponent <ScaleAxis>()
                          .Initialize(_parentTransformHandle, Vector3.forward, Vector3.right, Color.green));
            }

            if (_parentTransformHandle.axes != HandleAxes.X && _parentTransformHandle.axes != HandleAxes.Y && _parentTransformHandle.axes != HandleAxes.Z)
            {
                _globalAxis = new GameObject().AddComponent <ScaleGlobal>()
                              .Initialize(_parentTransformHandle, HandleBase.GetVectorFromAxes(_parentTransformHandle.axes), Color.white);

                _globalAxis.InteractionStart  += OnGlobalInteractionStart;
                _globalAxis.InteractionUpdate += OnGlobalInteractionUpdate;
                _globalAxis.InteractionEnd    += OnGlobalInteractionEnd;
            }

            return(this);
        }