public void CreateNewRopeToPos(RopeJSONClass rope, bool DropRope, bool update) { GameObject newRope = null;// = new GameObject(); //Create rope with need type if (rope.RopeType == 0) { newRope = Instantiate(RopePrefabBigBig, new Vector3(), Quaternion.identity) as GameObject; } else if (rope.RopeType == 1) { newRope = Instantiate(RopePrefabBigSmall, new Vector3(), Quaternion.identity) as GameObject; } else if (rope.RopeType == 2) { newRope = Instantiate(RopePrefabSmallSmall, new Vector3(), Quaternion.identity) as GameObject; } else if (rope.RopeType == 3) { newRope = Instantiate(RopePrefabBridgeHorizontal, ropeRespownPos, Quaternion.identity) as GameObject; } else if (rope.RopeType == 4) { newRope = Instantiate(RopePrefabBridgeVertical, ropeRespownPos, Quaternion.identity) as GameObject; } else if (rope.RopeType == 5) { newRope = Instantiate(RopePrefabCoaxialCoaxial, ropeRespownPos, Quaternion.identity) as GameObject; } newRope.SetActive (true); //Add all sockets from stand to new rope for (int i = 0; i < SocketList.Count; i++) { newRope.GetComponent<RopeClass>().availableSocketList.Add(SocketList[i].gameObject); } //Add DragPlane for new rope newRope.GetComponent<RopeClass>().DragPlane = this.DragPlane; newRope.GetComponent<RopeClass>().ropeManager = GetComponent<RopeManager>(); //Init RopeClass links after create object rope prefab newRope.GetComponent<RopeClass>().InitAfterAdd(true, new Color(rope.RopeColor.x, rope.RopeColor.y, rope.RopeColor.z)); //Init rope with saved color from file or from database //Set rope pins to need positions newRope.GetComponent<RopeClass>().pointA.gameObject.transform.position = rope.PosA; newRope.GetComponent<RopeClass>().pointB.gameObject.transform.position = rope.PosB; //Drop all pins for fix to near sockets if(DropRope){ if (!newRope.GetComponent<RopeClass>().pointA.GetComponent<Attracted>().AttractWithOther) { newRope.GetComponent<RopeClass>().pointA.GetComponent<Drag>().isFix = false; newRope.GetComponent<RopeClass>().pointA.GetComponent<Drag>().isDropped = true; newRope.GetComponent<RopeClass>().pointA.GetComponent<Attracted>().ScanAttractors(false, false, null); newRope.GetComponent<RopeClass>().pointB.GetComponent<Drag>().isFix = false; newRope.GetComponent<RopeClass>().pointB.GetComponent<Drag>().isDropped = true; newRope.GetComponent<RopeClass>().pointB.GetComponent<Attracted>().ScanAttractors(false, false, null); } else { newRope.GetComponent<RopeClass>().pointA.GetComponent<Drag>().isFix = false; newRope.GetComponent<RopeClass>().pointA.GetComponent<Drag>().isDropped = true; newRope.GetComponent<RopeClass>().pointA.GetComponent<Attracted>().ScanAttractors(false, false, null); } } //newRope.GetComponent<RopeClass>().pointA.GetComponent<Attracted>().ScanAttractors(); //newRope.GetComponent<RopeClass>().pointB.GetComponent<Attracted>().ScanAttractors(); //Add new rope to RopeList RopeList.Add(newRope); if(update) UpdateUserRopesToDatebase(); //newRope.GetComponent<RopeClass> ().InitAfterAdd (); //CreatedRopes.Add (newRope); }
public string EncodeAllRopesToJSON() { List<string> allRopesList = new List<string>(); string allRopesInJSON = ""; //Get info from each existing rope Debug.Log("RopeList.Count = " + RopeList.Count); for (int i = 0; i < RopeList.Count; i++) { int RopeType = RopeList[i].GetComponent<RopeClass>().RopeType; Vector3 PosA = RopeList[i].GetComponent<RopeClass>().pointA.transform.position; Vector3 PosB = RopeList[i].GetComponent<RopeClass>().pointB.transform.position; Color RopeColor = RopeList[i].GetComponent<RopeClass>().RopeColor; RopeJSONClass rope = new RopeJSONClass(RopeType, PosA, PosB, new Vector3(RopeColor.r, RopeColor.g, RopeColor.b)); //Convert to JSON string string ropeInJSON = JsonConvert.SerializeObject(rope); allRopesList.Add(ropeInJSON); } allRopesInJSON = JsonConvert.SerializeObject(allRopesList); Debug.Log("allRopesInJSON = " + allRopesInJSON); return allRopesInJSON; //Create array of string and return as one JSON string }