IEnumerator cutGraphic() { if (Input.GetMouseButtonDown (0) && clickCount == 0){ changelControl (); if(changeObj) { updateListPos(); parentList=new List<Vector3>(); for(int i=0;i<ControlObj.GetComponent<graphicMes>().graphicPointsMes.Count;i++) { parentList.Add(ControlObj.GetComponent<graphicMes>().graphicPointsMes[i]); } childList1=new List<Vector3>(); childList2=new List<Vector3>(); childList=new List<List<Vector3>>(); } else { clickCount=-1; } } if (isCut && Input.GetMouseButtonDown (0) && clickCount == 1){ mouseStartpos=Camera.main.ScreenToWorldPoint(Input.mousePosition); mouseStartpos.z=0; // startPos=setMousePos(Camera.main.ScreenToWorldPoint(Input.mousePosition),out startFlag); GameObject cutStart=(GameObject)Instantiate (pointPrefab,mouseStartpos,transform.rotation); cutStart.name="cutStart"; } if (isCut && Input.GetMouseButtonDown (0) && clickCount >= 2) { while(Input.GetMouseButton(0)) { if(GameObject.Find("cutline")!=null) Destroy(GameObject.Find("cutline")); mouseEndPos=Camera.main.ScreenToWorldPoint(Input.mousePosition); mouseEndPos.z=0; MLine line=new MLine(mouseStartpos,mouseEndPos,Color.black,GameObject.Find("cutStart").transform); line.obj.name="cutline"; yield return new WaitForFixedUpdate(); } if(GameObject.Find("cutline")!=null) Destroy(GameObject.Find("cutStart")); //crosspoint and crossflag cutGraphic mcut=new cutGraphic(); mcut.initCutGriphic(mouseStartpos,mouseEndPos); if(mcut.cutOperate()) { Destroy(ControlObj); yield return new WaitForFixedUpdate(); setChildgraphic(mcut.childList); setChildgraphic(mcut.originList); } clickCount=-1; //change state; state=Clickstate.oprateGraphic; } clickCount++; yield return null; }
public void pointTline() { if (Input.GetMouseButtonDown (0) && clickCount == 0) { linestart=Camera.main.ScreenToWorldPoint(Input.mousePosition); linestart.z=10; linestart=snapPoint(linestart); GameObject start=GameObject.Instantiate(pointPrefab); start.transform.position=linestart; start.name="linestart"; } if (Input.GetMouseButtonDown (0) && clickCount == 1) { linend=Camera.main.ScreenToWorldPoint(Input.mousePosition); linend.z=10; linend=snapPoint(linend); if(linestart!=linend) { GameObject end=GameObject.Instantiate(pointPrefab); end.transform.position=linend; end.name="linend"; creatRline mline=new creatRline(); mline.drawRLine(linestart,linend); linestart=new Vector3(); linend=new Vector3(); } else { Destroy(GameObject.Find("linestart")); } //change state; state=Clickstate.oprateGraphic; } clickCount = (clickCount > 0) ? 0 : 1; }
public void pointTgraphic() { if (Input.GetMouseButtonDown (0) && graphicPoints.Count == 0) { Vector3 pos=Camera.main.ScreenToWorldPoint(Input.mousePosition); pos.z=10; pos=snapPoint(pos); graphicPoints.Add(pos); // creatmGraphic _graphic=new creatmGraphic(); // mGraphic=_graphic; // _graphic.InitGraphic(pos); // graphicTrans=_graphic._transParent.transform; graphicTrans=new GameObject("tempGraphic").transform; GameObject start=GameObject.Instantiate(pointPrefab); start.transform.position=pos; // start.name=_graphic._transName+"point0"; start.transform.parent=graphicTrans; clickCount=0; } if (Input.GetMouseButtonDown (0) && graphicPoints.Count>0&&clickCount>0){ Vector3 pos=Camera.main.ScreenToWorldPoint(Input.mousePosition); pos.z=10; pos=snapPoint(pos); if(graphicPoints[graphicPoints.Count-1]!=pos) { MLine line=new MLine(graphicPoints[graphicPoints.Count-1],pos,Color.black,graphicTrans); graphicPoints.Add(pos); GameObject point=GameObject.Instantiate(pointPrefab); point.transform.position=pos; // point.name=mGraphic._transName+"point"+clickCount.ToString(); point.transform.parent=graphicTrans; } if(graphicPoints[0]==pos) { // MLine line=new MLine(graphicPoints[graphicPoints.Count-1],pos,Color.black,graphicTrans); Destroy(GameObject.Find("tempGraphic")); mGraphic=new creatmGraphic(); mGraphic.InitGraphic(mGraphic.getcenter(graphicPoints)); mGraphic.drawGraphic(graphicPoints); mGraphic.creatLine(graphicPoints); mGraphic.creatPoint(graphicPoints); mGraphic._transParent.GetComponent<graphicMes>().setPointMes(graphicPoints); graphicPoints=new List<Vector3>(); //change state; state=Clickstate.oprateGraphic; } } clickCount++; }
public void linelenth() { if (Input.GetMouseButtonDown (0) && clickCount == 0) { lenthPos[0]=Camera.main.ScreenToWorldPoint(Input.mousePosition); lenthPos[0].z=10; lenthPos[0]=snapPoint(lenthPos[0]); GameObject start=GameObject.Instantiate(pointPrefab); start.transform.position=lenthPos[0]; start.name="lenthstart"; } if(Input.GetMouseButtonDown (0) && clickCount == 1) { lenthPos[1]=Camera.main.ScreenToWorldPoint(Input.mousePosition); lenthPos[1].z=10; lenthPos[1]=snapPoint(lenthPos[1]); Destroy(GameObject.Find("lenthstart")); } if(clickCount==1) { Vector3 center=new Vector3(); if(lenthPos[1].x!=lenthPos[0].x&&lenthPos[1].y!=lenthPos[0].y) { GameObject.Find("UI_Canvas").GetComponent<UISingleton>().setbtnMes("只可標示水平長度或垂直長度"); } else { lenth=(Mathf.RoundToInt(Vector3.Distance(lenthPos[0],lenthPos[1])/fgz_width)).ToString()+"cm"; MLine linelenth=new MLine(lenthPos[0],lenthPos[1],GameObject.Find("linelenth").transform,"linelenthobj"); if(lenthPos[0].x!=lenthPos[1].x) { Vector3 temp=lenthPos[0]; if(lenthPos[0].x>lenthPos[1].x) { lenthPos[0]=lenthPos[1]; lenthPos[1]=temp; } center=new Vector3(lenthPos[0].x+Vector3.Distance(lenthPos[0],lenthPos[1])/2,lenthPos[0].y+0.3f,lenthPos[0].z); for(int i=0;i<5;i++) { MLine linejt1=new MLine(lenthPos[0],new Vector3(lenthPos[0].x+0.2f,lenthPos[0].y+0.04f*i),linelenth.obj.transform,"jiantou"); MLine linejt2=new MLine(lenthPos[0],new Vector3(lenthPos[0].x+0.2f,lenthPos[0].y+0.04f*(-i)),linelenth.obj.transform,"jiantou"); MLine linejt3=new MLine(lenthPos[1],new Vector3(lenthPos[1].x-0.2f,lenthPos[1].y+0.04f*i),linelenth.obj.transform,"jiantou"); MLine linejt4=new MLine(lenthPos[1],new Vector3(lenthPos[1].x-0.2f,lenthPos[1].y+0.04f*(-i)),linelenth.obj.transform,"jiantou"); } } if(lenthPos[0].y!=lenthPos[1].y) { Vector3 temp=lenthPos[0]; if(lenthPos[0].y>lenthPos[1].y) { lenthPos[0]=lenthPos[1]; lenthPos[1]=temp; } center=new Vector3(lenthPos[0].x+0.5f,lenthPos[0].y+Vector3.Distance(lenthPos[0],lenthPos[1])/2,lenthPos[0].z); for(int i=0;i<5;i++) { MLine linejt1=new MLine(lenthPos[0],new Vector3(lenthPos[0].x+0.04f*i,lenthPos[0].y+0.2f),linelenth.obj.transform,"jiantou"); MLine linejt2=new MLine(lenthPos[0],new Vector3(lenthPos[0].x+0.04f*(-i),lenthPos[0].y+0.2f),linelenth.obj.transform,"jiantou"); MLine linejt3=new MLine(lenthPos[1],new Vector3(lenthPos[1].x+0.04f*i,lenthPos[1].y-0.2f),linelenth.obj.transform,"jiantou"); MLine linejt4=new MLine(lenthPos[1],new Vector3(lenthPos[1].x+0.04f*(-i),lenthPos[1].y-0.2f),linelenth.obj.transform,"jiantou"); } } GameObject shuzi=Instantiate(lenthshow); shuzi.transform.position=center; shuzi.transform.parent=linelenth.obj.transform; shuzi.GetComponent<TextMesh>().text=lenth; } lenthPos=new Vector3[2]; //change state; state=Clickstate.oprateGraphic; } clickCount = (clickCount>0)?0:1; }
public void graphicHB() { if (Input.GetMouseButtonDown (0) && clickCount == 0) { changelControl (); updateListPos(); graphicFirst=ControlObj; } if (Input.GetMouseButtonDown (0) && clickCount == 1) { changelControl (); updateListPos(); graphicSecond=ControlObj; } if (graphicFirst != null && graphicSecond != null) { if(isHB(graphicFirst.GetComponent<graphicMes>().graphicPointsMes,graphicSecond.GetComponent<graphicMes>().graphicPointsMes)&&graphicFirst!=graphicSecond) { StartCoroutine("doHB"); } //change state; state=Clickstate.oprateGraphic; } clickCount++; }
public void copyGraphic(GameObject obj) { Vector3 pos = obj.transform.position; GameObject copyObj =(GameObject)Instantiate (obj,new Vector3 (pos.x+1f,pos.y-0.5f,pos.z),transform.rotation); copyObj.name = obj.name+"copy"; for (int i=0; i<copyObj.transform.childCount; i++) { if(copyObj.transform.GetChild(i).name.Contains(obj.name)) { string newname=copyObj.transform.GetChild(i).name.Replace(obj.name,copyObj.name); copyObj.transform.GetChild(i).name=newname; } } copyObj.transform.parent = graphicsParent.transform; //change state; state=Clickstate.oprateGraphic; }