using System.Collections.Generic; using UnityEngine; using UnityEngine.UI.Extensions; using UnityEngine.UI; public class DRAW : MonoBehaviour { GameObject PNL; public Texture2D cursorPoint; Vector2 hotSpot = new Vector2(64, 64); float xpos; float ypos; Vector2 XY; // void Start(){ // _G.HEIGHT = 96; // Get.o2("Canvas","DRAWPlan").SetActive(true); // _G.PNL="DRAWPlan"; // //setMesure(DOIT.CSn(IV.text)); // //print("-------------------------START DRAW----------------"); // _G.NW=1; // //print("-------------------------START DRAW 2----------------"); // PNL=Get.o2("DRAWPlan","Plan"); // PNL.SetActive(true); // //Get.o2("DRAWPlan","3D").SetActive(false); // _G.Down=false; // _G.Open=true; // UILineRenderer pr=PNL.transform.GetComponent(); // var pointlist = new List(); // pr.Points = pointlist.ToArray(); // DOIT.DELETEAllChild("Plan"); // _G.wP=new Vector2[24]; // // print("-------------------------START DRAW END----------------"); // } // void Update(){ // //print("Updat"); // XY=new Vector2(getXY("x"),getXY("y")); // if (Input.GetMouseButtonDown(0) && _G.Open==true && _G.Down==true){ // if (XY.x>-500f && XY.x<500f && XY.y>-300 && XY.y<300 ) // { // if(_G.NW==1) // { // _G.wP[_G.NW-1]=new Vector2(XY.x,XY.y); // } // if(_G.NW>=1) // { // int sens=sense(_G.wP[_G.NW-2],XY); // if(sens!=0){ _G.wP[_G.NW-1]=new Vector2(XY.x,XY.y);} // } // } // else {restart();} // } // if (Input.GetMouseButtonDown(1) && _G.Open==true && _G.Down==true && _G.NW>=4) { // print("RRRRRRRRRRRRRRRRRIIIIIIIIIIIGGGGGGGGGGGGGGGHHHHHHHHHHHHTR"); // _G.deleteLastWall = true; // _G.closingWall=0; // _G.Down=false; // _G.Open=true; // _G.NW-=1; // print("_G.NW====="+_G.NW); // if(sense(_G.wP[_G.NW-1],XY)==7){_G.wP[_G.NW-1].x=_G.wP[1-1].x;} // if(sense(_G.wP[_G.NW-1],XY)==8) // { // float disx=Mathf.Abs(_G.wP[_G.NW-1].x-_G.wP[1-1].x); // _G.wP[_G.NW-1].y=_G.wP[1-1].y-disx; // } // DOIT.DELETEAllChild("Plan"); // addlines(_G.NW); // addMesures(_G.NW); // RoomSize(); // Cursor.SetCursor(null, Vector2.zero, CursorMode.ForceSoftware);//Delete points // //_G.NW-=1; // _G.ROOMCLOSE=false; // } // if (Input.GetMouseButtonDown(0) && _G.Down==false && _G.Open==true){ // if (XY.x<-192 && XY.x>-292 && XY.y<245&& XY.y>145) // { // _G.Down=true; // _G.wP[_G.NW-1]=new Vector2(XY.x,XY.y); // } // } // if (Input.GetMouseButtonUp(0) && _G.Open==true && _G.Down){ // if( _G.NW>3 && XY.x<-210 && XY.x>-310 && XY.y<236 && XY.y>136) // { // print("-----------------------------------DOWN FALSE------------------------------------"); // _G.Down=false; // _G.Open=false; // _G.NW-=1; // if(sense(_G.wP[_G.NW-1],XY)==7){_G.wP[_G.NW-1].x=_G.wP[1-1].x;} // if(sense(_G.wP[_G.NW-1],XY)==8) // { // float disx=Mathf.Abs(_G.wP[_G.NW-1].x-_G.wP[1-1].x); // _G.wP[_G.NW-1].y=_G.wP[1-1].y-disx; // } // DOIT.DELETEAllChild("Plan"); // addlines(_G.NW); // addMesures(_G.NW); // RoomSize(); // Cursor.SetCursor(null, Vector2.zero, CursorMode.ForceSoftware);//Delete points // } // else {_G.NW+=1;} // } // } // void LateUpdate() // { // if(_G.Down && _G.NW>1 && _G.Open ) // { // //XY=new Vector2(getXY("x"),getXY("y")); // float dis=Vector2.Distance(XY,_G.wP[_G.NW-2]); // Cursor.SetCursor(cursorPoint, hotSpot, CursorMode.ForceSoftware); // int sens=sense(_G.wP[_G.NW-2],XY); // //print("sens==="+sens); // switch(sens){ // case 1:_G.wP[_G.NW-1]=new Vector2(getXY("x"),_G.wP[_G.NW-2].y);break; // case 2:_G.wP[_G.NW-1]=new Vector2(_G.wP[_G.NW-2].x+dis*0.707f ,_G.wP[_G.NW-2].y-dis*0.707f );break; // case 3:_G.wP[_G.NW-1]=new Vector2(_G.wP[_G.NW-2].x,getXY("y")); ;break; // case 4: _G.wP[_G.NW-1]=new Vector2(_G.wP[_G.NW-2].x-dis*0.707f ,_G.wP[_G.NW-2].y-dis*0.707f );break; // case 5: _G.wP[_G.NW-1]=new Vector2(getXY("x"),_G.wP[_G.NW-2].y);break; // case 6:_G.wP[_G.NW-1]=new Vector2(_G.wP[_G.NW-2].x-dis*0.707f ,_G.wP[_G.NW-2].y+dis*0.707f );break; // case 7:_G.wP[_G.NW-1]=new Vector2(_G.wP[_G.NW-2].x,getXY("y"));break; // case 8: _G.wP[_G.NW-1]=new Vector2(_G.wP[_G.NW-2].x+dis*0.707f ,_G.wP[_G.NW-2].y+dis*0.707f );break; // } // if(sens!=0){ // addlines(_G.NW); // addMesures(_G.NW); // _G.endPoint = _G.wP[_G.NW-1]; // } // Get.o3("DRAWPlan","StartHere","T_Start").GetComponent().text=TRANS.This("T_FinishHere"); // } // else{ // Cursor.SetCursor(null, Vector2.zero, CursorMode.ForceSoftware); // } // } // public void restart(){ // _G.NW=1; // print("RESATRT"); // _G.closingWall=1; // _G.Down=false; // _G.Open=true; // GameObject p=Get.o2("DRAWPlan","Plan"); // p.SetActive(true); // UILineRenderer pr=p.transform.GetComponent(); // var pointlist = new List(); // pr.Points = pointlist.ToArray(); // DOIT.DELETEAllChild("Plan"); // _G.ROOMCLOSE=true; // _G.wP=new Vector2[24]; // GameObject.Find("T_StarttHere").transform.GetComponent().alpha=1; // GameObject.Find("T_FinishHere").transform.GetComponent().alpha=0; // Measure.okShow("DRAWPlan", "FINISH", false); // } // //-------------------------------------------------------------------------------------------------------- // //-------------------------------------------------------------------------------------------------------- // // public static void RedrawRoom(string Ms,float Value){ // // print("--------pass redraw----------"); // // //print("_G.NW===== "+_G.NW); // // int Mi=int.Parse(Ms.Substring(1,3))-100; // // int i=1; // // for(i=1; i<_G.NW; i++){ _G.wD[i-1]=sense(_G.wP[i-1],_G.wP[i]);} // // _G.wD[_G.NW-1]=sense(_G.wP[_G.NW-1],_G.wP[1-1]); // // _G.WallsWidth[Mi-1]=Value; // // _G.wP[1-1].x=-242; // // _G.wP[1-1].y=195; // // //print(" _G.wD[_G.NW-1]====="+_G.wD[_G.NW-1]); // // float dis=_G.WallsWidth[1-1]*2; // // for(i=1; i<_G.NW+1; i++){ // // dis=_G.WallsWidth[i-1]*2; // // if(_G.wD[i-1]==1){_G.wP[i]=new Vector2(_G.wP[i-1].x+dis,_G.wP[i-1].y);} // // if(_G.wD[i-1]==2){_G.wP[i]=new Vector2(_G.wP[i-1].x+dis*0.707f,_G.wP[i-1].y-dis*0.707f);} // // if(_G.wD[i-1]==3){_G.wP[i]=new Vector2(_G.wP[i-1].x,_G.wP[i-1].y-dis);} // // if(_G.wD[i-1]==4){_G.wP[i]=new Vector2(_G.wP[i-1].x-dis*0.707f,-_G.wP[i-1].y-dis*0.707f);} // // if(_G.wD[i-1]==5){_G.wP[i]=new Vector2(_G.wP[i-1].x-dis,_G.wP[i-1].y);} // // if(_G.wD[i-1]==6){_G.wP[i]=new Vector2(_G.wP[i-1].x-dis*0.707f,_G.wP[i-1].y+dis*0.707f);} // // if(_G.wD[i-1]==7){_G.wP[i]=new Vector2(_G.wP[i-1].x,_G.wP[i-1].y+dis);} // // if(_G.wD[i-1]==8){_G.wP[i]=new Vector2(_G.wP[i-1].x+dis*0.707f,_G.wP[i-1].y+dis*0.707f);} // // } // // if(_G.wD[_G.NW-1]==1){_G.wP[_G.NW-1]=new Vector2(_G.wP[1-1].x-dis,_G.wP[1-1].y);} // // if(_G.wD[_G.NW-1]==2){_G.wP[_G.NW-1]=new Vector2(_G.wP[1-1].x-dis*0.707f,_G.wP[1-1].y+dis*0.707f);} // // if(_G.wD[_G.NW-1]==3){_G.wP[_G.NW-1]=new Vector2(_G.wP[1-1].x,_G.wP[1-1].y+dis);} // // if(_G.wD[_G.NW-1]==4){_G.wP[_G.NW-1]=new Vector2(_G.wP[1-1].x+dis*0.707f,_G.wP[1-1].y+dis*0.707f);} // // if(_G.wD[_G.NW-1]==5){_G.wP[_G.NW-1]=new Vector2(_G.wP[1-1].x+dis,_G.wP[1-1].y);} // // if(_G.wD[_G.NW-1]==6){ // // float disx=Mathf.Abs(_G.wP[_G.NW-1].x-_G.wP[1-1].x); // // _G.wP[_G.NW-1].y=_G.wP[1-1].y-disx; // // } // // if(_G.wD[_G.NW-1]==7){_G.wP[_G.NW-1]=new Vector2(_G.wP[1-1].x,_G.wP[_G.NW-1].y);} // // if(_G.wD[_G.NW-1]==8){ // // float disx=Mathf.Abs(_G.wP[_G.NW-1].x-_G.wP[1-1].x); // // _G.wP[_G.NW-1].y=_G.wP[1-1].y-disx; // // } // // GameObject p=Get.o2("DRAWPlan","Plan"); // // p.SetActive(true); // // UILineRenderer pr=p.transform.GetComponent(); // // var pointlist = new List(); // // for(i=1; i<_G.NW+1; i++){ pointlist.Add(_G.wP[i-1]); } // // if(_G.closingWall==1){_G.endPoint=_G.wP[1-1]; } // // else { // // _G.endPoint=new Vector3(_G.wP[_G.NW-1].x+50,_G.wP[_G.NW-1].y,1); // // } // // pointlist.Add(_G.endPoint); // // pr.Points = pointlist.ToArray(); // // for(i=1; i<_G.NW; i++) // // { // // setM("M"+(100+i).ToString(),_G.wP[i-1],_G.wP[i]); // // _G.WallsPointCenter[i-1]=(_G.wP[i-1] + _G.wP[i])/2; // // _G.WallsWidth[i-1] = Vector2.Distance(_G.wP[i-1],_G.wP[i])/2; // // } // // _G.WallsWidth[_G.NW-1] = Vector2.Distance(_G.wP[_G.NW-1],_G.wP[1-1])/2; // // _G.WallsPointCenter[_G.NW-1]=(_G.wP[_G.NW-1]+_G.wP[1-1])/2; // // for(i=1; i<_G.NW+_G.closingWall; i++){ // // Create3D.setMesureNew(Mathf.Abs(_G.WallsWidth[i-1]), "m"+(100+i).ToString()); // // } // // RoomSize(); // // } // public static void RedrawRoomFromScene(){ // int i=1; // for(i=1; i<_G.NW; i++){ _G.wD[i-1]=sense(_G.wP[i-1],_G.wP[i]);} // _G.wD[_G.NW-1]=sense(_G.wP[_G.NW-1],_G.wP[1-1]); // _G.wP[1-1].x=-242; // _G.wP[1-1].y=195; // float dis=_G.WallsWidth[1-1]*2; // for(i=1; i<_G.NW+_G.closingWall; i++){ // dis=_G.WallsWidth[i-1]*2; // if(_G.wD[i-1]==1){_G.wP[i]=new Vector2(_G.wP[i-1].x+dis,_G.wP[i-1].y);} // if(_G.wD[i-1]==2){_G.wP[i]=new Vector2(_G.wP[i-1].x+dis*0.707f,_G.wP[i-1].y-dis*0.707f);} // if(_G.wD[i-1]==3){_G.wP[i]=new Vector2(_G.wP[i-1].x,_G.wP[i-1].y-dis);} // if(_G.wD[i-1]==4){_G.wP[i]=new Vector2(_G.wP[i-1].x-dis*0.707f,-_G.wP[i-1].y-dis*0.707f);} // if(_G.wD[i-1]==5){_G.wP[i]=new Vector2(_G.wP[i-1].x-dis,_G.wP[i-1].y);} // if(_G.wD[i-1]==6){_G.wP[i]=new Vector2(_G.wP[i-1].x-dis*0.707f,_G.wP[i-1].y+dis*0.707f);} // if(_G.wD[i-1]==7){_G.wP[i]=new Vector2(_G.wP[i-1].x,_G.wP[i-1].y+dis);} // if(_G.wD[i-1]==8){_G.wP[i]=new Vector2(_G.wP[i-1].x+dis*0.707f,_G.wP[i-1].y+dis*0.707f);} // } // if(_G.wD[_G.NW-1]==1){_G.wP[_G.NW-1]=new Vector2(_G.wP[1-1].x-dis,_G.wP[1-1].y);} // if(_G.wD[_G.NW-1]==2){_G.wP[_G.NW-1]=new Vector2(_G.wP[1-1].x-dis*0.707f,_G.wP[1-1].y+dis*0.707f);} // if(_G.wD[_G.NW-1]==3){_G.wP[_G.NW-1]=new Vector2(_G.wP[1-1].x,_G.wP[1-1].y+dis);} // if(_G.wD[_G.NW-1]==4){_G.wP[_G.NW-1]=new Vector2(_G.wP[1-1].x+dis*0.707f,_G.wP[1-1].y+dis*0.707f);} // if(_G.wD[_G.NW-1]==5){_G.wP[_G.NW-1]=new Vector2(_G.wP[1-1].x+dis,_G.wP[1-1].y);} // if(_G.wD[_G.NW-1]==6){ // float disx=Mathf.Abs(_G.wP[_G.NW-1].x-_G.wP[1-1].x); // _G.wP[_G.NW-1].y=_G.wP[1-1].y-disx; // } // if(_G.wD[_G.NW-1]==7){_G.wP[_G.NW-1]=new Vector2(_G.wP[1-1].x,_G.wP[_G.NW-1].y);} // if(_G.wD[_G.NW-1]==8){ // float disx=Mathf.Abs(_G.wP[_G.NW-1].x-_G.wP[1-1].x); // _G.wP[_G.NW-1].y=_G.wP[1-1].y-disx; // } // GameObject p=Get.o2("DRAWPlan","Plan"); // p.SetActive(true); // UILineRenderer pr=p.transform.GetComponent(); // var pointlist = new List(); // for(i=1; i<_G.NW+1; i++){ pointlist.Add(_G.wP[i-1]); } // pointlist.Add(_G.wP[1-1]); // pr.Points = pointlist.ToArray(); // for(i=1; i<_G.NW; i++) // { // setM("M"+(100+i).ToString(),_G.wP[i-1],_G.wP[i]); // _G.WallsPointCenter[i-1]=(_G.wP[i-1] + _G.wP[i])/2; // _G.WallsWidth[i-1] = Vector2.Distance(_G.wP[i-1],_G.wP[i])/2; // } // if(_G.closingWall==1){ // setM("M"+(100+_G.NW).ToString(),_G.wP[_G.NW-1],_G.wP[1-1]*1); // _G.WallsWidth[_G.NW-1] = Vector2.Distance(_G.wP[_G.NW-1],_G.wP[1-1])/2; // _G.WallsPointCenter[_G.NW-1]=(_G.wP[_G.NW-1]+_G.wP[1-1])/2; // } // for(i=1; i<_G.NW+_G.closingWall; i++){ // Create3D.setMesureNew(Mathf.Abs(_G.WallsWidth[i-1]), "m"+(100+i).ToString()); // } // RoomSize(); // } // //-------------------------------------------------------------------------------------------------------- // //-------------------------------------------------------------------------------------------------------- // public static int sense(Vector2 P1,Vector2 P2){ // int s=0; // Vector2 dir=(P2-P1).normalized; // if(dir.x>=0.8f && dir.y<=0.3f && dir.y>=-0.3f){s=1;} // if(dir.x<=0.8f && dir.x>=0.3f && dir.y>=-0.8f && dir.y<=-0.3f){s=2;} // if(dir.x<=0.3f && dir.x>=-0.3f && dir.y<=-0.8f ){s=3;} // if(dir.x<=-0.3f && dir.x>=-0.8f && dir.y>=-0.8f && dir.y<=-0.3f ){s=4;} // if(dir.x<=-0.8f && dir.y<=0.3f && dir.y>=-0.3f ){s=5;} // if(dir.x<=-0.3f && dir.x>=-0.8f && dir.y<=0.8f && dir.y>=0.3f ){s=6;} // if(dir.x<=0.3f && dir.x>=-0.3f && dir.y>=0.8f){s=7;} // if(dir.x<=0.8f && dir.x>=0.3f && dir.y<=0.8f && dir.y>=0.3f ){s=8;} // return s; // } // float getXY(string xy){ // XY=new Vector2(0,0); // XY = new Vector2(Input.mousePosition.x, Input.mousePosition.y); // Vector2 localCursor; // var rect1 = Get.o2("DRAWPlan","Planboard").GetComponent(); // var pos1 = XY; // RectTransformUtility.ScreenPointToLocalPointInRectangle(rect1, pos1,null, out localCursor); // xpos = (float)(localCursor.x); // ypos = (float)(localCursor.y); // if (xpos < 0) xpos = xpos + (int)rect1.rect.width / 2; // else xpos += (float)rect1.rect.width / 2; // if (ypos > 0) ypos = ypos + (int)rect1.rect.height / 2; // else ypos += (float)rect1.rect.height / 2; // xpos-=1000/2; // ypos-=300; // xpos=Mathf.RoundToInt(xpos); // ypos=Mathf.RoundToInt(ypos); // //Debug.Log("Correct Cursor Pos: " + xpos + " " + ypos); // float r=xpos; // if(xy=="y")r=ypos; // return r; // } // void addlines(int Q){ // GameObject p=Get.o2("DRAWPlan","Plan"); // p.SetActive(true); // UILineRenderer pr=p.transform.GetComponent(); // var pointlist = new List(); // var pointAngle = new List(); // int i=1; // for(i=1; i 1) { // for (int j=1;j< pointlist.Count;j++) // { // float AngleRad = Mathf.Atan2(pointlist[j - 1].y - pointlist[j].y, pointlist[j - 1].x - pointlist[j].x); // float AngleDeg = (180 / Mathf.PI) * AngleRad; // pointAngle.Add (AngleDeg); // pr.PointAngle = pointAngle.ToArray(); // } // } // for (i=1; i().text=(i-100).ToString(); // } // void addMesures(int Q) // { // if(_G.Open==false)Q+=1; // for(int i=1; iXmax)Xmax=_G.wP[i-1].x; // if(_G.wP[i-1].yYmax)Ymax=_G.wP[i-1].y; // } // Vector2 RC=new Vector2(Xmin, Ymax); // Vector2 offset=new Vector2(RC.x+Xmax/2-Xmin/2, RC.y-Ymax/2+Ymin/2); // for(i=1; i<_G.NW+1; i++){ // _G.wP[i-1]=_G.wP[i-1]-offset; // _G.wP[i-1].x=_G.wP[i-1].x/2; // _G.wP[i-1].y=_G.wP[i-1].y/2; // } // for(i=1; i<_G.NW+1; i++){ // //print("i===="+i); // _G.WallsPointCenter[i-1]=(_G.wP[i-1] + _G.wP[i])/2; // _G.WallsWidth[i-1] = Vector2.Distance(_G.wP[i-1],_G.wP[i]); // } // Xmax=0; // Xmin=0; // Ymax=0; // Ymin=0; // for(i=1; i<_G.NW+1; i++){ // if(_G.wP[i-1].xXmax)Xmax=_G.wP[i-1].x; // if(_G.wP[i-1].yYmax)Ymax=_G.wP[i-1].y; // } // _G.WallsPointCenter[_G.NW-1]=(_G.wP[_G.NW-1] + _G.wP[1-1])/2; // _G.WallsWidth[_G.NW-1] = Vector2.Distance(_G.wP[_G.NW-1],_G.wP[1-1]); // for(i=1; i<_G.NW; i++){ // _G.wD[i-1]=sense(_G.wP[i-1],_G.wP[i]); // } // _G.wD[_G.NW-1]=sense(_G.wP[_G.NW-1],_G.wP[1-1]); // _G.WIDE=Xmax-Xmin; // _G.DEPTH=Ymax-Ymin; // Measure.okShow("DRAWPlan", "FINISH", true); // } }