using UnityEngine; using System.Collections; using System; using System.Collections.Generic; using System.Globalization; using UnityEngine.SceneManagement; using System.Text; public class PDFPLAN : PDFCreation { static PDFPLAN _instance; public static PDFPLAN Instance { get { if (_instance == null) { _instance = FindObjectIncludingInactive(); } return _instance; } } public static T FindObjectIncludingInactive() where T : UnityEngine.Object { foreach (GameObject rootGameObject in SceneManager.GetActiveScene().GetRootGameObjects()) { if (rootGameObject.TryGetComponent(out T component)) { return component; } foreach (T childComponent in rootGameObject.GetComponentsInChildren(true)) { return childComponent; } } return null; } private void Awake() { if (_instance == null) { _instance = this; } } public void GeneratePDFForURL() { //_isCiecommerce = true; StaticCoroutine.Start(CreatePDFPlanCoroutine()); } public void CreatePDFPlan() { StaticCoroutine.Start(CreatePDFPlanCoroutine()); } private IEnumerator CreatePDFPlanCoroutine() { Initialize(out Camera mainCam); //yield return new WaitForEndOfFrame(); //View3D //yield return TakeScreenshotScene(); //yield return new WaitUntil(() => _bytes != null) ; _G.CamWA = mainCam.fieldOfView; Vector3 campos = mainCam.gameObject.transform.position; Vector3 camA = mainCam.gameObject.transform.eulerAngles; //Plan2D //yield return TakePlan2DPicture(mainCam); //yield return TakeScreenshotPlan2D(); //_handler.EndPlan(); mainCam.gameObject.transform.position = campos; mainCam.gameObject.transform.eulerAngles = camA; mainCam.fieldOfView = _G.CamWA; yield return TakeElevationPictures(); //yield return TakeIslandPicture(); yield return TakeIslandScreenshot(); _handler.SetPlan2DButtonOverlayActive(true); _handler.Close2DPlan(); yield return PreparePdf(); } // private IEnumerator TakeIslandPicture() // { // //COUNTER // Texture2D _screenShot = null; // _islandBYTES = null; // if (_handler.IslandCutActive) // { // _handler.ShowIslandCut(); // Set.alpha(Get.o1("PLAN2DHandler/CanvasPlan/BTNS"), false); // // added a wait after starting show island cut to let time for the camera to render to their render texture // //Test to see if screenshot get the right picture this time // yield return new WaitForEndOfFrame(); // _screenShot = RTImageV3(); // _islandBYTES = _screenShot.EncodeToPNG(); // Destroy(_screenShot); // //yield return new WaitForSeconds(0.5f); // Set.alpha(Get.o1("PLAN2DHandler/CanvasPlan/BTNS"), true); // yield return new WaitForEndOfFrame(); // } // } private IEnumerator TakeIslandScreenshot() { //Texture2D _screenShot = null; _islandBYTES = null; if (_handler.IslandCutActive) { _handler.ShowIslandCut(); Set.alpha(Get.o1("PLAN2DHandler/CanvasPlan/BTNS"), false); // added a wait after starting show island cut to let time for the camera to render to their render texture //Test to see if screenshot get the right picture this time yield return new WaitForEndOfFrame(); //_screenShot = RTImageV3(); //_islandBYTES = _screenShot.EncodeToPNG(); yield return TakeScreenshotIsland(); //Destroy(_screenShot); //yield return new WaitForSeconds(0.5f); Set.alpha(Get.o1("PLAN2DHandler/CanvasPlan/BTNS"), true); yield return new WaitForEndOfFrame(); } } Byte[] GetImageKnob(string path) { string ImageName = UIT.Global(Header.KnobV,_G.G).Split('?')[0];//.LibraryValue(path, CsvHeaders.FBX, DataTypes.Knob); Sprite SP = Resources.Load("ICONS/KNOBS/" + ImageName); // Create a new texture and set its size to the sprite's size Texture2D newTexture = new ((int)SP.rect.width, (int)SP.rect.height); // Get the pixels from the atlas texture and apply them to the new texture var pixels = SP.texture.GetPixels((int)SP.textureRect.x, (int)SP.textureRect.y, (int)SP.textureRect.width, (int)SP.textureRect.height); newTexture.SetPixels(pixels); newTexture.Apply(); // Apply the changes to the texture // Encode the new texture to PNG return newTexture.EncodeToPNG(); } IEnumerator PreparePdf() { AddFieldToPDF(out WWWForm form); AddAdditionalField(form); CompleteFormInfo1To5(form); CompleteAdress(form); List Cablist=DOLIST.CABLISTint(); AddFieldForCab( Cablist,form); if(_P.ListSwitch.ContainsKey("CABINET_DOOR_RECIPE") && _P.ListSwitch["CABINET_DOOR_RECIPE"]){ AddFieldForDoor(form);} AddFieldForPnl( form); //AddFieldForFiller( form); //AddFieldForRecover(number, form); //AddFieldForKnob(number, form); int iteration = AddFieldElevation(form); AddFieldForAllPictures( form); //Doors in snene //yield return GetDoorsInScene(form); yield return new WaitForEndOfFrame(); //Texture in Scene //yield return GetTexturesInScene(form); //Kobns in snene //GetKnobsInScene(form); //yield return new WaitForEndOfFrame(); AddFieldForIsland(form, iteration+1); //Calculation counter area //yield return AddFieldCounter(form); ReturnCameraToInitialPosition(); GameObject.Find("HIDER").transform.Find("LoadingCircle").gameObject.SetActive(true); //yield return SaveToServerCoroutine(form, ThisOnly.getUrlPDFPLAN()); } protected override Dictionary AddFieldForKnob(string number, WWWForm form) { try { var KNOBdict = base.AddFieldForKnob(number, form); foreach (KeyValuePair pair in KNOBdict) { string[] CODE = pair.Key.Split('?'); string softModel = pair.Key.Split(',')[0]; //Debug.Log("Knob " + softModel); string code = Get.LibraryValue(softModel, CsvHeaders.Unique_Name, DataTypes.Knob); string color = Get.LibraryValue(softModel, CsvHeaders.Language, DataTypes.Knob); number = " "; form.AddField("ite" + _objCount, number);//Code form.AddField("c" + _objCount, code);//Code form.AddField("d" + _objCount, TRANS.This("T_Knob") + ": " + TRANS.This("T_Color") + ":" + color);//Description form.AddField("qty" + _objCount, pair.Value.ToString());//Quantity _objCount += 1; } return null; } catch (Exception e) { Debug.Log("error for knob " + e); throw; } } protected override Dictionary AddFieldForRecover(string number, WWWForm form) { try { var RECOVERdict = base.AddFieldForRecover(number, form); foreach (KeyValuePair pair in RECOVERdict) { print("pair.Key=====Recover==="+pair.Key);//1? 0# 24.063 #34 3/4'' # PB # 6 string[] Code = pair.Key.Split("?"); string code = "";//UIT.Value(Library.Panel,Code[0],Header.Unique_Name); print("pair.Key=====code==R="+code); string color = "";//UIT.Value(Library.CabTexture,Code[1],Header.Unique_Name); string des = TRANS.This("G_RECOVER");//+" "+UIT.Value(Library.Panel,Code[0],"L"+_G.L); // + ": " + code[0].Split('?')[0] + "\n" + code[1] + " x " + code[2]; float QTY = pair.Value;//Mathf.Ceil(pair.Value / 96); print("pair.Key=====color==="+color); print("pair.Key=====des==="+des); //print("pair.Key=====sizes==="+size); //number = code[4];");//Code form.AddField("ite" + _objCount, code);//Code form.AddField("c" + _objCount, color);//Code form.AddField("d" + _objCount, des);//Description form.AddField("qty" + _objCount, QTY.ToString());//Quantity _objCount += 1; } return null; } catch (Exception e) { Debug.Log("error for Recover " + e); throw; } } // protected override Dictionary AddFieldForFiller(string number, WWWForm form) // { // try // { // List Cablist=DOLIST.CABLISTint(); // var FILLERdict = MakeList.FILLERQTY(Cablist); // foreach (KeyValuePair pair in FILLERdict) // { // print("pair.Key=====Filler==="+pair.Key);//F1_1?1?90?2.5 // string[] Code = pair.Key.Split("?"); // string code =Code[0]; // string size = UIT.Value(Library.Molding,code,Header.Height)+" x "+ UIT.Value(Library.Molding,code,Header.Wide); // string des = TRANS.This("M_FILLER")+" "+UIT.Value(Library.Molding,code,"L"+_G.L); // string color = UIT.Value(Library.CabTexture,Code[1],Header.Code_ID); // float QTY = pair.Value; // if(!_P.ListSwitch["FILLER_BY_ITEMS"]){QTY=Mathf.Ceil(pair.Value / 96);} // print("pair.Key=====code==="+code); // print("pair.Key=====color==="+color); // print("pair.Key=====des==="+des); // print("pair.Key=====sizes==="+size); // //number = code[3]; // form.AddField("ite" + _objCount, code);//Code // form.AddField("c" + _objCount, color);//Code // form.AddField("d" + _objCount, des);//Description // form.AddField("qty" + _objCount, QTY.ToString());//Quantity // _objCount += 1; // } // return null; // } // catch (Exception e) // { // Debug.Log("error for Filler " + e); // throw; // } // } // private IEnumerator AddFieldCounter(WWWForm form) // { // string CounterAreaTop = CounterArea.Top(); // string CounterAreaCascade = CounterArea.Cascade(); // //string countername = Get.CounterValue(_G.GLOBAL[_G.G][8], 3); // //string countername = Get.LibraryValue(GlobalSelectionManager.GetValue(GlobalOption.COUN_8), CsvHeaders.Color, DataTypes.Counter); // string countername = UIT.Global(Header.Counter,_G.G);//Get.LibraryValue(GlobalSelectionManager.GetValue(GlobalOption.COUN_8), CsvHeaders.Color, DataTypes.Counter); // string counterCascadeDes = ""; // if (CounterAreaCascade != "0.00") counterCascadeDes = TRANS.This("and") + CounterArea.Cascade() + TRANS.This(_G.Sys2) + " " + TRANS.This("Cascade"); // string counterDes = CounterAreaTop + TRANS.This(_G.Sys2) + counterCascadeDes; // string cn = ""; // if (CounterAreaTop != "0.00") // { // cn = "C1"; // yield return GetImage(UIT.Global(Header.Counter,_G.G), "Counter",_G.G);//GlobalSelectionManager.GetValue(GlobalOption.COUN_8), // form.AddBinaryData("fC1", BYTESCounter[0], "fC1" + ".png", "fC1" + "/png"); // } // form.AddField(cn, cn); // form.AddField("CounterArea", counterDes);//number // form.AddField("countername", countername);//number // print("CounterDes====" + counterDes); // } // private void GetKnobsInScene(WWWForm form) // { // List listknob = DOLIST.KNOBINSCENE(); // int qty = listknob.Count; // if (qty > 2) qty = 2; // //yield return new WaitForEndOfFrame(); // for (int i = 0; i < qty; i++) // { // //print("listknob[i]====="+listknob[i]); // BYTESKnobs[i] = GetImageKnob(listknob[i]); // string fname = "fK" + (i + 1).ToString(); // string displayName = Get.LibraryValue(listknob[i], CsvHeaders.Unique_Name, DataTypes.Knob); // form.AddField("K" + (i + 1).ToString(), displayName); // form.AddBinaryData(fname, BYTESKnobs[i], fname + ".png", fname + "/png"); // } // } // private IEnumerator GetTexturesInScene(WWWForm form) // { // List listTexture = DOLIST.TEXTUREINSCENE(); // int qty = listTexture.Count; // if (qty > 4) qty = 4; // for (int i = 0; i < qty; i++) // { // //StartCoroutine(getimage(listTexture[i],"Texture",i,form)); // yield return GetImage(listTexture[i].Split('?')[0], "CabTexture", i); // string fname = "fT" + (i + 1).ToString(); // string displayName = Get.LibraryValue(listTexture[i].Split('?')[0], CsvHeaders.Color, DataTypes.CabTexture); // form.AddField("T" + (i + 1).ToString(), displayName); // form.AddBinaryData(fname, BYTEScabTextures[i], fname + ".png", fname + "/png"); // } // } // private IEnumerator GetDoorsInScene(WWWForm form) // { // List listdoor = DOLIST.DOORINSCENE(); // int qty = listdoor.Count; // if (qty > 4) qty = 4; // for (int i = 0; i < qty; i++) // { // //StartCoroutine(getimage(listdoor[i],"Door",i,form)); // Texture2D Texture=UIT_MATERIAL.GetDoorTexture2D(listdoor[i]); // yield return Texture; // BYTESDoors[i] =Texture.EncodeToPNG(); // string displayName =UIT.Value(Library.Door,listdoor[i],Header.Unique_Name); //Get.LibraryValue(listdoor[i], CsvHeaders.Unique_Name, DataTypes.Door) + " " + Get.LibraryValue(listdoor[i], CsvHeaders.Color, DataTypes.Door); // string fname = "fD" + (i + 1).ToString(); // form.AddField("D" + (i + 1).ToString(), displayName); // form.AddBinaryData(fname, BYTESDoors[i], fname + ".png", fname + "/png"); // } // } protected override void AddFieldForAllPictures( WWWForm form) { base.AddFieldForAllPictures( form); if (_islandBYTES == null) return; form.AddBinaryData("FourViewsUpload", _islandBYTES, "FourViewsUpload.png", "image/png"); } private static void AddAdditionalField(WWWForm form) { //form.AddField("address", _P.address); form.AddField("jn", ""/*"#:" + _G.MemberNumber + "-" + _G.JobNumber*/); form.AddField("Info7", TRANS.This("Draw by")); form.AddField("Info8", TRANS.This("Verify by")); form.AddField("D1", ""); form.AddField("D2", ""); form.AddField("D3", ""); form.AddField("D4", ""); form.AddField("T1", ""); form.AddField("T2", ""); form.AddField("T3", ""); form.AddField("T4", ""); form.AddField("K1", ""); form.AddField("K2", ""); form.AddField("door", TRANS.This("T_DOOR")); form.AddField("Cabinet", TRANS.This("T_CABINET")); string user = _G.FileName; if (user != "" && user.IndexOf('-') != -1) { user = Get.UserValue(_G.FileName.Split('-')[0], 1, 2); } form.AddField("user", user); } }