private async System.Threading.Tasks.Task ResetToOldDecorate(bool isAutoPlayCloseDecorate = true) { if (isAutoPlayCloseDecorate) { isRotatingDecorate = false; //关闭界面 goRebackAndRotate.SetActive(false); } //关闭提示 TipsTileComponent._instance.CloseAll(); //旋转 //删除现在的装饰物 Destroy(currClickDecorateComponent.gameObject); //生成老的装饰物 var goDecorate = await Root2dSceneManager._instance.GenerateDecorate(BeforeRotateInfo.modelName, BeforeRotateInfo.CropGoodId); goDecorate.GetComponent <TileComponent>().SetDecorateInfo(BeforeRotateInfo.idxDecorateRotate, BeforeRotateInfo.SoilId, BeforeRotateInfo.CropGoodId, BeforeRotateInfo.regionId); goDecorate.transform.localPosition = BeforeRotateInfo.localPos; //重新设置当前的组件 currClickDecorateComponent = goDecorate.GetComponent <TileComponent>(); //重置旋转后的信息 AfterRotateInfo = new RotateInfo(); //排序 Root2dSceneManager._instance.UpdateSortLayer(true); }
public static void Rotate(RotateInfo RI) { if (IT_Gesture.onRotateE != null) { IT_Gesture.onRotateE(RI); } }
public static void Rotate(RotateInfo RI) { if (onRotateE != null) { onRotateE(RI); } }
public void TransformNext() { if (TransformSequence.Count == 0) { Transforming = false; return; } RotateInfo ri = TransformSequence[0]; TransformSequence.RemoveAt(0); Clockwise = ri.Clockwise; StartRotate(ri.Direction, ri.Index); }
public static void Push(Vector3 position, Vector3 vtPosition, LookatData.BoneConfig data) { var forward = vtPosition - position; var ri = new RotateInfo() { position = position, vtPosition = vtPosition, forward = forward, data = data, }; info.Add(ri); }
public RotateInfo GetRotationInfo() { SetActiveGroup(false); var angle = 0; var able = true; RotateInfo info = null; for (int i = DefaultPivotIndex; i >= 0; i--) { var pivot = BlockList[i]; for (angle = 90; angle < 360; angle += 180) { able = true; foreach (var pos in BlockList) { var newPos = pos.RotateByPivot(pivot, angle); if (newPos.IsAvailiable() == false) { able = false; break; } } if (able) { info = new RotateInfo(angle, i); break; } } if (able) { break; } } SetActiveGroup(true); return(info); }
void rotate(RotateInfo rotateInfo, float degree) { //Debug.Log("this is rotate!"); if (rotateInfo.axis != "") { if (rotateInfo.axis == "x") { for (int i = 0; i < 27; i++) { if (Mathf.Abs(matx[i].transform.localPosition.x - 100 * rotateInfo.a) < 1) { matx[i].RotateAround(cubeParent.transform.localPosition, Vector3.right * rotateInfo.dir, degree); } } } else if (rotateInfo.axis == "y") { for (int i = 0; i < 27; i++) { if (Mathf.Abs(matx[i].transform.localPosition.y - 100 * rotateInfo.a) < 1) { matx[i].RotateAround(cubeParent.transform.localPosition, Vector3.up * rotateInfo.dir, degree); } } } else if (rotateInfo.axis == "z") { for (int i = 0; i < 27; i++) { if (Mathf.Abs(matx[i].transform.localPosition.z - 100 * rotateInfo.a) < 1) { matx[i].RotateAround(cubeParent.transform.localPosition, Vector3.forward * rotateInfo.dir, degree); } } } } }
void Update(){ if(Input.touchCount==2){ Touch touch1=Input.touches[0]; Touch touch2=Input.touches[1]; Vector2 pos1 = touch1.position; Vector2 pos2 = touch2.position; Vector2 delta1 = pos1-lastTouchPos1; Vector2 delta2 = pos2-lastTouchPos2; if(firstTouch){ firstTouch=false; //for rotate initPos1=pos1; initPos2=pos2; initGradient=(pos1-pos2).normalized; float curX=pos1.x-pos2.x; float curY=pos1.y-pos2.y; prevAngle=Gesture.VectorToAngle(new Vector2(curX, curY)); } if(touch1.phase==TouchPhase.Moved && touch2.phase==TouchPhase.Moved){ float dot = Vector2.Dot(delta1, delta2); if(dot<0){ Vector2 grad1=(pos1-initPos1).normalized; Vector2 grad2=(pos2-initPos2).normalized; float dot1=Vector2.Dot(grad1, initGradient); float dot2=Vector2.Dot(grad2, initGradient); //rotate if(dot1<0.7f && dot2<0.7f){ float curX=pos1.x-pos2.x; float curY=pos1.y-pos2.y; float curAngle=Gesture.VectorToAngle(new Vector2(curX, curY)); float val=Mathf.DeltaAngle(curAngle, prevAngle); if(rotationSmoothing==_SmoothMethod.None){ RotateInfo rotateInfo=new RotateInfo(val, pos1, pos2); Gesture.Rotate(rotateInfo); } else{ if(Mathf.Abs(val)>0) AddRotVal(val); float valueAvg=GetAverageValue(); RotateInfo rotateInfo=new RotateInfo(valueAvg, pos1, pos2); Gesture.Rotate(rotateInfo); } prevAngle=curAngle; } //pinch else{ Vector2 curDist=pos1-pos2; Vector2 prevDist=(pos1-delta1)-(pos2-delta2); float pinch=prevDist.magnitude-curDist.magnitude; PinchInfo pinchInfo=new PinchInfo(pinch, pos1, pos2); Gesture.Pinch(pinchInfo); } } } lastTouchPos1=pos1; lastTouchPos2=pos2; } else{ if(!firstTouch){ firstTouch=true; if(rotationSmoothing!=_SmoothMethod.None) ClearRotVal(); } } }
void OnRotate(RotateInfo rinfo) { rotateSpeed=Mathf.Lerp(rotateSpeed, rinfo.magnitude*rotateSpeedModifier, 0.75f); }
public static void Rotate(RotateInfo RI) { if(onRotateE!=null) onRotateE(RI); }
void OnRotate(RotateInfo rinfo) { rotateSpeed = Mathf.Lerp(rotateSpeed, rinfo.magnitude * rotateSpeedModifier, 0.75f); }
public void Transform(string seq) { Transforming = true; TransformSequence.Clear(); seq = seq.Replace("S", "RLUUFuDFFRRBBLUUfbURRDFFURRU"); seq = seq.Replace("s", "urruffdrruBFuulbbrrffdUfuulr"); seq = seq.Replace("M", "UUDDLFFuDRRBudRLFFRUdrLUfb"); seq = seq.Replace("m", "BFulRDurfflrDUbrrdUffldduu"); for (int i = 0; i < seq.Length; i++) { char c = seq[i]; RotateInfo ri = new RotateInfo(); switch (c) { case 'F': ri.Direction = CubeFaceDirection.Forward; ri.Index = 1; ri.Clockwise = 1.0f; break; case 'f': ri.Direction = CubeFaceDirection.Forward; ri.Index = 1; ri.Clockwise = -1.0f; break; case 'B': ri.Direction = CubeFaceDirection.Back; ri.Index = -1; ri.Clockwise = 1.0f; break; case 'b': ri.Direction = CubeFaceDirection.Back; ri.Index = -1; ri.Clockwise = -1.0f; break; case 'R': ri.Direction = CubeFaceDirection.Right; ri.Index = -1; ri.Clockwise = 1.0f; break; case 'r': ri.Direction = CubeFaceDirection.Right; ri.Index = -1; ri.Clockwise = -1.0f; break; case 'L': ri.Direction = CubeFaceDirection.Left; ri.Index = 1; ri.Clockwise = 1.0f; break; case 'l': ri.Direction = CubeFaceDirection.Left; ri.Index = 1; ri.Clockwise = -1.0f; break; case 'U': ri.Direction = CubeFaceDirection.Up; ri.Index = 1; ri.Clockwise = 1.0f; break; case 'u': ri.Direction = CubeFaceDirection.Up; ri.Index = 1; ri.Clockwise = -1.0f; break; case 'D': ri.Direction = CubeFaceDirection.Down; ri.Index = -1; ri.Clockwise = 1.0f; break; case 'd': ri.Direction = CubeFaceDirection.Down; ri.Index = -1; ri.Clockwise = -1.0f; break; default: continue; } TransformSequence.Add(ri); } TransformNext(); }
void Update() { if (Input.touchCount == 2) { Touch touch1 = Input.touches[0]; Touch touch2 = Input.touches[1]; Vector2 pos1 = touch1.position; Vector2 pos2 = touch2.position; Vector2 delta1 = pos1 - lastTouchPos1; Vector2 delta2 = pos2 - lastTouchPos2; if (firstTouch) { firstTouch = false; //for rotate initPos1 = pos1; initPos2 = pos2; initGradient = (pos1 - pos2).normalized; float curX = pos1.x - pos2.x; float curY = pos1.y - pos2.y; prevAngle = IT_Gesture.VectorToAngle(new Vector2(curX, curY)); } if (touch1.phase == TouchPhase.Moved && touch2.phase == TouchPhase.Moved) { float dot = Vector2.Dot(delta1, delta2); if (dot < .5f) { Vector2 grad1 = (pos1 - initPos1).normalized; Vector2 grad2 = (pos2 - initPos2).normalized; float dot1 = Vector2.Dot(grad1, initGradient); float dot2 = Vector2.Dot(grad2, initGradient); //rotate if (dot1 < 0.7f && dot2 < 0.7f) { float curX = pos1.x - pos2.x; float curY = pos1.y - pos2.y; float curAngle = IT_Gesture.VectorToAngle(new Vector2(curX, curY)); float val = Mathf.DeltaAngle(curAngle, prevAngle); if (rotationSmoothing == _SmoothMethod.None) { RotateInfo rotateInfo = new RotateInfo(val, pos1, pos2); IT_Gesture.Rotate(rotateInfo); } else { if (Mathf.Abs(val) > 0) { AddRotVal(val); } float valueAvg = GetAverageValue(); if (valueAvg != 0) { RotateInfo rotateInfo = new RotateInfo(valueAvg, pos1, pos2); IT_Gesture.Rotate(rotateInfo); } } prevAngle = curAngle; } //pinch else { Vector2 curDist = pos1 - pos2; Vector2 prevDist = (pos1 - delta1) - (pos2 - delta2); float pinch = prevDist.magnitude - curDist.magnitude; if (Mathf.Abs(pinch) > 0.5f) { PinchInfo pinchInfo = new PinchInfo(pinch, pos1, pos2); IT_Gesture.Pinch(pinchInfo); } } } } lastTouchPos1 = pos1; lastTouchPos2 = pos2; } else { if (!firstTouch) { firstTouch = true; if (rotationSmoothing != _SmoothMethod.None) { ClearRotVal(); } } } }
private void Update() { if (Input.touchCount == 2) { Touch touch = Input.touches[0]; Touch touch2 = Input.touches[1]; Vector2 position = touch.position; Vector2 position2 = touch2.position; Vector2 vector = position - lastTouchPos1; Vector2 vector2 = position2 - lastTouchPos2; if (firstTouch) { firstTouch = false; initPos1 = position; initPos2 = position2; initGradient = (position - position2).normalized; float x = position.x - position2.x; float y = position.y - position2.y; prevAngle = IT_Gesture.VectorToAngle(new Vector2(x, y)); } if (touch.phase == TouchPhase.Moved && touch2.phase == TouchPhase.Moved) { float num = Vector2.Dot(vector, vector2); if (num < 0.5f) { Vector2 normalized = (position - initPos1).normalized; Vector2 normalized2 = (position2 - initPos2).normalized; float num2 = Vector2.Dot(normalized, initGradient); float num3 = Vector2.Dot(normalized2, initGradient); if (num2 < 0.7f && num3 < 0.7f) { float x2 = position.x - position2.x; float y2 = position.y - position2.y; float current = IT_Gesture.VectorToAngle(new Vector2(x2, y2)); float num4 = Mathf.DeltaAngle(current, prevAngle); if (rotationSmoothing == _SmoothMethod.None) { RotateInfo rI = new RotateInfo(num4, position, position2); IT_Gesture.Rotate(rI); } else { if (Mathf.Abs(num4) > 0f) { AddRotVal(num4); } float averageValue = GetAverageValue(); if (averageValue != 0f) { RotateInfo rI2 = new RotateInfo(averageValue, position, position2); IT_Gesture.Rotate(rI2); } } prevAngle = current; } else { Vector2 vector3 = position - position2; float num5 = (position - vector - (position2 - vector2)).magnitude - vector3.magnitude; if (Mathf.Abs(num5) > 0.5f) { PinchInfo pI = new PinchInfo(num5, position, position2); IT_Gesture.Pinch(pI); } } } } lastTouchPos1 = position; lastTouchPos2 = position2; } else if (!firstTouch) { firstTouch = true; if (rotationSmoothing != 0) { ClearRotVal(); } } }
void OnRotate(RotateInfo rinfo) { this.rotateSpeed=Mathf.Lerp(this.rotateSpeed, rinfo.magnitude* this.rotateSpeedModifier/IT_Gesture.GetDPIFactor(), 0.75f); }
void OnRotate(RotateInfo rinfo) { rotateSpeed = Mathf.Lerp(rotateSpeed, rinfo.magnitude * rotateSpeedModifier / IT_Gesture.GetDPIFactor(), 0.75f); }
void Update() { if (Input.GetMouseButtonUp(0)) { done = false; } if (isRotate) { if ((rotateDegree + 3.0f) > 90) { rotate(rotateInfo, 90 - rotateDegree); rotateDegree = 0; isRotate = false; return; } rotateDegree += 3.0f; rotate(rotateInfo, 3.0f); //Debug.Log("isRotate!!!"); return; } if (Input.GetMouseButtonDown(0)) { pickedNodes = null; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { pickedNodes = hit.collider.gameObject.transform.parent.gameObject; vecs = hit.point; } if (pickedNodes != null) { for (int i = 0; i < 27; i++) { if (pickedNodes.name == cubes[i].name) { vecms = matx[i].transform.position; Debug.Log(pickedNodes.name + " " + hit.collider.gameObject.name); } } } } if (Input.GetMouseButton(0)) { if (!done) { pickedNodee = null; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { pickedNodee = hit.collider.gameObject.transform.parent.gameObject; vece = hit.point; } if (pickedNodes != null) { if (pickedNodee != null) { for (int i = 0; i < 27; i++) { if (pickedNodee.name == cubes[i].name) { vecme = matx[i].transform.position; } } } rotateInfo = rotationinfo(); /*steeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeep*/ if (rotateInfo.axis != "" && islocked == false) { //Debug.Log(step); done = true; isRotate = true; step++; if (step >= 5) { islocked = true; } //GameObject.Find("Gametime").GetComponent<Timecontroller>().ChangeStepUI(); GameObject.Find("Canvas").GetComponent <GameUIController>().ChangeStepUI(); } } } } Rotate(); Scale(); }
RotateInfo rotationinfo() { RotateInfo rotateInfo = new RotateInfo(); string axis = ""; float dir = 0.0f; float a = 0.0f; if ((Mathf.Abs(vecme.x - vecms.x) >= 0.01) || (Mathf.Abs(vecme.y - vecms.y) >= 0.01) || (Mathf.Abs(vecme.z - vecms.z) >= 0.01)) { if ((Mathf.Abs(vecme.x - vecms.x) < 0.01) && (Mathf.Abs(vecme.y - vecms.y) < 0.01)) { if ((Mathf.Abs(Mathf.Abs(vece.x) - 3.0f) < 0.01) && (Mathf.Abs(Mathf.Abs(vecs.x) - 3.0f) < 0.01)) { axis = "y"; a = vecme.y / 100; float temp = (vece.z - vecs.z) * vece.x; dir = (-1) * temp / Mathf.Abs(temp); } else if ((Mathf.Abs(Mathf.Abs(vece.y) - 3.0f) < 0.01) && (Mathf.Abs(Mathf.Abs(vecs.y) - 3.0f) < 0.01)) { axis = "x"; a = vecme.x / 100; float temp = (vece.z - vecs.z) * vece.y; dir = temp / Mathf.Abs(temp); } } else if ((Mathf.Abs(vecme.x - vecms.x) < 0.01) && (Mathf.Abs(vecme.z - vecms.z) < 0.01)) { if ((Mathf.Abs(Mathf.Abs(vece.x) - 3.0f) < 0.01) && (Mathf.Abs(Mathf.Abs(vecs.x) - 3.0f) < 0.01)) { axis = "z"; a = vecme.z / 100; float temp = (vece.y - vecs.y) * vece.x; dir = temp / Mathf.Abs(temp); } else if ((Mathf.Abs(Mathf.Abs(vece.z) - 3.0f) < 0.01) && (Mathf.Abs(Mathf.Abs(vecs.z) - 3.0f) < 0.01)) { axis = "x"; a = vecme.x / 100; float temp = (vece.y - vecs.y) * vece.z; dir = (-1) * temp / Mathf.Abs(temp); } } else if ((Mathf.Abs(vecme.y - vecms.y) < 0.01) && (Mathf.Abs(vecme.z - vecms.z) < 0.01)) { if ((Mathf.Abs(Mathf.Abs(vece.y) - 3.0f) < 0.01) && (Mathf.Abs(Mathf.Abs(vecs.y) - 3.0f) < 0.01)) { axis = "z"; a = vecme.z / 100; float temp = (vece.x - vecs.x) * vece.y; dir = (-1) * temp / Mathf.Abs(temp); } else if ((Mathf.Abs(Mathf.Abs(vece.z) - 3.0f) < 0.01) && (Mathf.Abs(Mathf.Abs(vecs.z) - 3.0f) < 0.01)) { axis = "y"; a = vecme.y / 100; float temp = (vece.x - vecs.x) * vece.z; dir = temp / Mathf.Abs(temp); } } } else if ((Mathf.Abs(vecme.x - vecms.x) < 0.01) && (Mathf.Abs(vecme.y - vecms.y) < 0.01) && (Mathf.Abs(vecme.z - vecms.z) < 0.01)) { if (((Mathf.Abs(Mathf.Abs(vecs.x) - 3.0f) < 0.01) && (Mathf.Abs(Mathf.Abs(vece.y) - 3.0f) < 0.01)) || ((Mathf.Abs(Mathf.Abs(vecs.y) - 3.0f) < 0.01) && (Mathf.Abs(Mathf.Abs(vece.x) - 3.0f) < 0.01))) { if ((Mathf.Abs(vece.y - vecs.y) > 0.1) && (Mathf.Abs(vece.x - vecs.x) > 0.1)) { axis = "z"; a = vecme.z / 100; float temp = vecs.x * vece.y * (Mathf.Abs(vece.y) - Mathf.Abs(vecs.y)); dir = temp / Mathf.Abs(temp); } } else if (((Mathf.Abs(Mathf.Abs(vecs.x) - 3.0f) < 0.01) && (Mathf.Abs(Mathf.Abs(vece.z) - 3.0f) < 0.01)) || ((Mathf.Abs(Mathf.Abs(vecs.z) - 3.0f) < 0.01) && (Mathf.Abs(Mathf.Abs(vece.x) - 3.0f) < 0.01))) { if ((Mathf.Abs(vece.z - vecs.z) > 0.1) && (Mathf.Abs(vece.x - vecs.x) > 0.1)) { axis = "y"; a = vecme.y / 100; float temp = vecs.z * vece.x * (Mathf.Abs(vece.x) - Mathf.Abs(vecs.x)); dir = temp / Mathf.Abs(temp); } } else if (((Mathf.Abs(Mathf.Abs(vecs.z) - 3.0f) < 0.01) && (Mathf.Abs(Mathf.Abs(vece.y) - 3.0f) < 0.01)) || ((Mathf.Abs(Mathf.Abs(vecs.y) - 3.0f) < 0.01) && (Mathf.Abs(Mathf.Abs(vece.z) - 3.0f) < 0.01))) { if ((Mathf.Abs(vece.z - vecs.z) > 0.1) && (Mathf.Abs(vece.y - vecs.y) > 0.1)) { axis = "x"; a = vecme.x / 100; float temp = vecs.y * vece.z * (Mathf.Abs(vece.z) - Mathf.Abs(vecs.z)); dir = temp / Mathf.Abs(temp); } } } if (pickedNodee == null) { if (Mathf.Abs(Mathf.Abs(vecs.x) - 3.0f) < 0.01) { axis = (Mathf.Abs(vece.y) >= Mathf.Abs(vece.z)) ? "z" : "y"; string tempos = Mathf.Abs(vece.y) >= Mathf.Abs(vece.z) ? "y" : "z"; if (axis == "z") { a = vecms.z / 100; } else { a = vecms.y / 100; } float temp; if (axis == "z") { if (tempos == "y") { temp = vecs.x * vece.y; } else { temp = vecs.x * vece.z; } } else { if (tempos == "y") { temp = (-1) * vecs.x * vece.y; } else { temp = (-1) * vecs.x * vece.z; } } dir = temp / Mathf.Abs(temp); } else if (Mathf.Abs(Mathf.Abs(vecs.y) - 3.0f) < 0.01) { axis = (Mathf.Abs(vece.x) >= Mathf.Abs(vece.z)) ? "z" : "x"; string tempos = Mathf.Abs(vece.x) >= Mathf.Abs(vece.z) ? "x" : "z"; if (axis == "z") { a = vecms.z / 100; } else { a = vecms.x / 100; } float temp; if (axis == "x") { if (tempos == "x") { temp = vecs.y * vece.x; } else { temp = vecs.y * vece.z; } } else { if (tempos == "x") { temp = (-1) * vecs.y * vece.x; } else { temp = (-1) * vecs.y * vece.z; } } dir = temp / Mathf.Abs(temp); } else if (Mathf.Abs(Mathf.Abs(vecs.z) - 3.0f) < 0.01) { axis = (Mathf.Abs(vece.y) >= Mathf.Abs(vece.x)) ? "x" : "y"; string tempos = Mathf.Abs(vece.y) >= Mathf.Abs(vece.x) ? "y" : "x"; if (axis == "x") { a = vecms.x / 100; } else { a = vecms.y / 100; } float temp; if (axis == "y") { if (tempos == "x") { temp = vecs.z * vece.x; } else { temp = vecs.z * vece.y; } } else { if (tempos == "x") { temp = (-1) * vecs.z * vece.x; } else { temp = (-1) * vecs.z * vece.y; } } dir = temp / Mathf.Abs(temp); } } rotateInfo.axis = axis; rotateInfo.dir = dir; rotateInfo.a = a; return(rotateInfo); }
void Update() { if (Input.GetMouseButtonUp(0)) { done = false; } if (isRotate) { if ((rotateDegree + 3.0f) > 90) { rotate(rotateInfo, 90 - rotateDegree); rotateDegree = 0; isRotate = false; return; } rotateDegree += 3.0f; rotate(rotateInfo, 3.0f); return; } if (Input.GetMouseButtonDown(0)) { pickedNodes = null; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { pickedNodes = hit.collider.gameObject; vecs = hit.point; } if (pickedNodes != null) { for (int i = 0; i < 27; i++) { if (pickedNodes.name == cubes[i].name) { vecms = matx[i].transform.position; Debug.Log(pickedNodes.name); } } } } if (Input.GetMouseButton(0)) { if (!done) { pickedNodee = null; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { pickedNodee = hit.collider.gameObject; vece = hit.point; } if (pickedNodes != null) { if (pickedNodee != null) { for (int i = 0; i < 27; i++) { if (pickedNodee.name == cubes[i].name) { vecme = matx[i].transform.position; } } } rotateInfo = rotationinfo(); if (rotateInfo.axis != "") { done = true; isRotate = true; } } } } Rotate(); Scale(); }