// Update is called once per frame void Update() { float scroll = Input.GetAxis("Mouse ScrollWheel"); if (noScrollMode) { if (Input.GetKey(zoomInKey)) { scroll = 0.01f; } if (Input.GetKey(zoomOutKey)) { scroll = -0.01f; } } if (focusPoint == null) { return; } float distance = Vector3.Distance(myCamera.transform.position, focusPoint.transform.position); GameObject gizmo = transform.parent.Find("Gyzmo").gameObject; float scale = distance / 5.5f; if (scale < 1) { scale = 1; } cameraDistance = scale; gizmo.transform.localScale = new Vector3(scale, scale, scale); gyzmoTransform.NormalizeScaling(scale); if (scroll > 0 && Vector3.Distance(myCamera.transform.position, focusPoint.transform.position) <= minimalDistance) { scroll = 0; } Vector3 cameraPos = myCamera.transform.position; if (focusPoint == null) { Transform parent = transform.parent; TRS_Gizmo trs = (TRS_Gizmo)parent.GetComponent(typeof(TRS_Gizmo)); trs.stopTRSGizmo(); print("The Point Object was destroyed , so we stop the TRS Gizmo process"); return; } Vector3 pointPos = focusPoint.transform.position; // Si on est en local myCamera.transform.Translate(new Vector3(0, 0, 1) * scroll * (cameraPos - pointPos).magnitude); // Si on est en global //myCamera.transform.Translate(transform.forward *scroll * (cameraPos - pointPos).magnitude ); //} }
// Update is called once per frame void Update() { if (point == null) { trs.stopTRSGizmo(); return; } if (selected != null && Input.GetMouseButton(0)) { ChangeMaterialOnMouseOver change = (ChangeMaterialOnMouseOver)selected.GetComponent(typeof(ChangeMaterialOnMouseOver)); change.displaySelected(); currentMousePosition = Input.mousePosition; GetDimensionType dimension = (GetDimensionType)selected.GetComponent(typeof(GetDimensionType)); //print (selected.name); if (dimension == null) { GyzmoTransformScript gyzmoScript = (GyzmoTransformScript)transform.parent.GetComponent(typeof(GyzmoTransformScript)); if (selected.name == "TranslateMode") { gyzmoScript.setActiveMode(0); } if (selected.name == "RotateMode") { gyzmoScript.setActiveMode(1); } if (selected.name == "ScaleMode") { gyzmoScript.setActiveMode(2); } return; } int dimensionType = dimension.returnDimension(); //print ("current Dimension Type is "+dimensionType); if (dimensionType == 0) { gapValue = getXgap(); } if (dimensionType == 1) { gapValue = getYgap(); } if (dimensionType == 2) { gapValue = getXgap(); } GetMode mode = (GetMode)selected.GetComponent(typeof(GetMode)); modeValue = mode.returnMode(); //TRANSLATE MODE if (modeValue == 0) { Vector3 rightDirection = gyzmo.transform.right * XtranslationSpeed * gapValue; Vector3 upDirection = gyzmo.transform.up * YtranslationSpeed * gapValue; Vector3 forwardDirection = gyzmo.transform.forward * ZtranslationSpeed * gapValue; if (myCamera.transform.position.z > point.transform.position.z) { rightDirection *= -1; //orwardDirection*=-1; } float distanceScale = scaleCamera.returnDistance() / 2; distanceScale = Mathf.Clamp(distanceScale, 1, 4); //distanceScale = 1; if (dimensionType == 0) { TranslateObject(rightDirection * distanceScale); } if (dimensionType == 1) { TranslateObject(upDirection * distanceScale); } if (dimensionType == 2) { TranslateObject(-forwardDirection * distanceScale); } } //ROTATE MODE if (modeValue == 1) { currentTranslation = new Vector3(0, 0, 0); gapValue = getXgap(); Vector3 rightDirection = gyzmo.transform.right * XrotationSpeed * gapValue; Vector3 upDirection = gyzmo.transform.up * YrotationSpeed * gapValue; Vector3 forwardDirection = gyzmo.transform.forward * ZrotationSpeed * gapValue; previousEuler = currentEuler; if (dimensionType == 0) { currentEuler = forwardDirection; } if (dimensionType == 1) { currentEuler = rightDirection; } if (dimensionType == 2) { currentEuler = upDirection; } RotateObject(currentEuler - previousEuler); } //SCALING MODE if (modeValue == 2) { currentTranslation = new Vector3(0, 0, 0); gapValue = getXgap(); //Vector3 rightDirection = gyzmo.transform.right * XrotationSpeed * gapValue ; //Vector3 upDirection = gyzmo.transform.up * YrotationSpeed * gapValue ; //Vector3 forwardDirection = gyzmo.transform.forward * ZrotationSpeed * gapValue ; previousEuler = currentEuler; if (dimensionType == 0) { ScaleObject((float)gapValue / (float)10 * (float)scalingSpeed); } if (dimensionType == 1) { ScaleObject((float)gapValue / (float)10 * (float)scalingSpeed); } if (dimensionType == 2) { ScaleObject((float)gapValue / (float)10 * (float)scalingSpeed); } } } if (Input.GetMouseButtonUp(0) && trs.isActive()) { saveRotation = point.transform.rotation; if (modeValue == 2) { GyzmoTransformScript gyzmo = trs.returnGyzmoTransform(); //trs gyzmo.NormalizeScaling(); } if (selected != null) { //myCamera.transform.Translate(currentTranslation); currentTranslation = new Vector3(0, 0, 0); // myCamera.transform.LookAt(point.transform.position); unselect(); } } }