public void RemoveWire(string id) { Guid guid = Guid.Parse(id); IntegratedCircuit ic = breadBoard.GetIntegratedCircuit(guid); breadBoard.UnlinkNodes(ic.GetPinNode(0), ic.GetPinNodeIndex(0), ic.GetPinNode(1), ic.GetPinNodeIndex(1)); breadBoard.components.Remove(guid); }
public void RemoveIntegratedCircuit(string id) { Guid guid = Guid.Parse(id); IntegratedCircuit ic = breadBoard.GetIntegratedCircuit(guid); ic.Update(true); for (int i = 0; i < ic.Pins; i++) { breadBoard.RemoveNodeConnection(ic.GetPinNode(i), ic.GetPinNodeIndex(i)); } breadBoard.components.Remove(guid); }
private void LoadComponents(ZipArchive archive) { int index = GetZipArchiveEntryIndex("components.json", archive); if (index == -1) { return; } ZipArchiveEntry entry = archive.Entries[index]; using (StreamReader file = new StreamReader(entry.Open())) { JsonSerializer serializer = new JsonSerializer { TypeNameHandling = TypeNameHandling.Auto, ObjectCreationHandling = ObjectCreationHandling.Replace, Converters = { new BitArrayConverter(), new Vector3Converter(), new WireConverter() } }; Dictionary <Guid, IntegratedCircuit> components = (Dictionary <Guid, IntegratedCircuit>)serializer.Deserialize(file, typeof(Dictionary <Guid, IntegratedCircuit>)); foreach (Guid g in components.Keys) { IntegratedCircuit ic = components[g]; GameObject obj; switch (ic.IcType) { case ICType.solo: obj = cp.PlaceIntegratedCircuit(ic, ic.GetPinNode(0), ic.GetPinNodeIndex(0), true); obj.transform.position = CircuitHelper.GetPositionFromNode(ic.GetPinNode(0), ic.GetPinNodeIndex(0)); break; case ICType.dual: obj = cp.PlaceIntegratedCircuit(ic, ic.GetPinNode(0), ic.GetPinNodeIndex(0), ic.GetPinNode(1), ic.GetPinNodeIndex(1), true); Vector3 locationA = CircuitHelper.GetPositionFromNode(ic.GetPinNode(0), ic.GetPinNodeIndex(0)); Vector3 locationB = CircuitHelper.GetPositionFromNode(ic.GetPinNode(1), ic.GetPinNodeIndex(1)); obj.transform.position = new Vector3((locationA.x + locationB.x) / 2, 0, (locationA.z + locationB.z) / 2); obj.transform.localScale = new Vector3(Vector3.Distance(locationB, locationA) / 2, 1, 1); float angle = CircuitHelper.AngleBetweenVector3(locationB, locationA); angle = locationA.z > locationB.z ? -angle : angle; obj.transform.rotation = Quaternion.Euler(0, angle, 0); break; case ICType.ic4: obj = cp.PlaceIntegratedCircuit(ic, ic.GetPinNode(0), ic.GetPinNodeIndex(0), true); obj.transform.position = CircuitHelper.GetPositionFromNode(ic.GetPinNode(0), ic.GetPinNodeIndex(0)); break; case ICType.ic6: obj = cp.PlaceIntegratedCircuit(ic, ic.GetPinNode(0), ic.GetPinNodeIndex(0), true); obj.transform.position = CircuitHelper.GetPositionFromNode(ic.GetPinNode(0), ic.GetPinNodeIndex(0)); break; case ICType.wire: obj = cp.PlaceIntegratedCircuit(ic, ic.GetPinNode(0), ic.GetPinNodeIndex(0), ic.GetPinNode(1), ic.GetPinNodeIndex(1), true); Vector3[] vectors = ((Wire)ic).points; LineRenderer lineRenderer = obj.GetComponentInChildren <LineRenderer>(); lineRenderer.positionCount = vectors.Length; lineRenderer.SetPositions(vectors); CircuitHelper.CreateColliderChain(obj, vectors); break; default: break; } ic.CustomMethod(); } } }
public void RemoveBreadBoard(GameObject boardObj) { HashSet <string> nodesToDelete = new HashSet <string>(); HashSet <Guid> componentsToDelete = new HashSet <Guid>(); HashSet <Guid> wiresToDelete = new HashSet <Guid>(); for (int i = 0; i < boardObj.transform.childCount; i++) { string id = boardObj.transform.GetChild(i).name; if (id == "none") { continue; } foreach (string s in breadBoard.nodes.Keys.Where(x => x.StartsWith(id))) { nodesToDelete.Add(s); foreach (Connection c in breadBoard.nodes[s].connections.Values) { if (!c.IsNode) { componentsToDelete.Add(Guid.Parse(c.ID)); } } } foreach (Guid g in breadBoard.components.Keys) { IntegratedCircuit ic = breadBoard.components[g]; if (ic.IcType == ICType.wire) { if (ic.GetPinNode(0).StartsWith(id) || ic.GetPinNode(1).StartsWith(id)) { wiresToDelete.Add(g); } } else if (!ic.WriteToNodes) { if (ic.GetPinNode(0).StartsWith(id)) { componentsToDelete.Add(g); } } } } for (int i = breadBoardData.Count - 1; i >= 0; i--) { if (boardObj.transform.name == breadBoardData[i].ToString()) { breadBoardData.RemoveAt(i); } } foreach (Guid g in componentsToDelete) { Destroy(breadBoard.components[g].GetObjRef()); circuitPool.RemoveIntegratedCircuit(g.ToString()); } foreach (Guid g in wiresToDelete) { Destroy(breadBoard.components[g].GetObjRef()); circuitPool.RemoveWire(g.ToString()); } foreach (string s in nodesToDelete) { breadBoard.nodes.Remove(s); } Destroy(boardObj.transform.gameObject); }