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; } }
static public Vector3 GetVectorFromAxes(HandleAxes p_axes) { switch (p_axes) { case HandleAxes.X: return(new Vector3(1, 0, 0)); case HandleAxes.Y: return(new Vector3(0, 1, 0)); case HandleAxes.Z: return(new Vector3(0, 0, 1)); case HandleAxes.XY: return(new Vector3(1, 1, 0)); case HandleAxes.XZ: return(new Vector3(1, 0, 1)); case HandleAxes.YZ: return(new Vector3(0, 1, 1)); default: return(new Vector3(1, 1, 1)); } }
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; } }