private void renderResidueIDButtons() { UnityCleanup.DestroyGameObjects(residueButtons); residueIDsScrollView.verticalNormalizedPosition = 1; residueIDButtons = new Dictionary <int, ResidueIDButton>(); foreach (int residueID in residueIDs) { bool residueEnabled = moleculeRenderSettings.EnabledResidueIDs.Contains(residueID); bool residueModified = moleculeRenderSettings.CustomResidueRenderSettings.ContainsKey(residueID); GameObject button = (GameObject)Instantiate(residueButtonPrefab, Vector3.zero, Quaternion.identity); button.GetComponent <Image>().color = new Color(1, 1, 1); ResidueIDButton buttonScript = button.GetComponent <ResidueIDButton>(); buttonScript.Initialise(residueID, residueEnabled, residueModified, toggleResidue, openCustomResidueRenderSettings); residueIDButtons.Add(residueID, buttonScript); RectTransform rect = button.GetComponent <RectTransform>(); rect.SetParent(residueButtons.GetComponent <RectTransform>(), false); } }
private void initialise() { UnityCleanup.DestroyGameObjects(ElementPanel); if (selectedMolecule == null) { return; } if (selectedMolecule.RenderSettings.EnabledElements == null) { if (modelElements.ContainsKey(selectedMolecule.ID)) { selectedMolecule.RenderSettings.EnabledElements = new HashSet <string>(modelElements[selectedMolecule.ID]); } else { selectedMolecule.RenderSettings.EnabledElements = new HashSet <string>(); } } HashSet <string> displayElements = modelElements[selectedMolecule.ID]; for (int i = 0; i < MolecularConstants.ElementNamesByAtomicNumber.Count; i++) { GameObject button; string symbol = MolecularConstants.ElementNamesByAtomicNumber[i][0]; if (displayElements.Contains(symbol.ToUpper())) { button = (GameObject)Instantiate(ButtonEnabledPrefab, Vector3.zero, Quaternion.identity); button.GetComponent <Image>().color = new Color(1, 1, 1); ElementButton buttonScript = button.GetComponent <ElementButton>(); if (selectedMolecule.RenderSettings.EnabledElements.Contains(symbol.ToUpper())) { buttonScript.Initialise(true, new SetElementDelegate(setElement)); } else { buttonScript.Initialise(false, new SetElementDelegate(setElement)); } buttonScript.ElementName = symbol; } else { button = (GameObject)Instantiate(ButtonDisabledPrefab, Vector3.zero, Quaternion.identity); } RectTransform rect = button.GetComponent <RectTransform>(); TextMeshProUGUI text = button.GetComponentInChildren <TextMeshProUGUI>(); if (text != null) { if (symbol != null) { text.text = symbol; } else { text.text = "unknown"; } } rect.SetParent(ElementPanel.GetComponent <RectTransform>()); Vector2 position = MolecularConstants.ElementsChartPosition[i]; float x = position.x * 50f; float y = position.y * -50f; rect.localPosition = new Vector3(x, y, 0); rect.localRotation = Quaternion.Euler(0, 0, 0); rect.localScale = Vector3.one; } }
public void loadSettings() { if (residueUpdateType == ResidueUpdateType.ID) { if (residueIDs != null && residueIDs.Count > 0) { panelTitle.text = "Residue " + residueIDs[0] + " - Custom Settings"; } else { panelTitle.text = "Residue - Custom Settings"; } } else if (residueUpdateType == ResidueUpdateType.Name) { panelTitle.text = "Residue " + residueName + " - Custom Settings"; } else { panelTitle.text = "Custom Residue Settings"; } colourAtomsToggle.isOn = renderSettings.ColourAtoms; cpkToggle.isOn = false; vdwToggle.isOn = false; if (renderSettings.AtomRepresentation == MolecularRepresentation.CPK) { cpkToggle.isOn = true; } else if (renderSettings.AtomRepresentation == MolecularRepresentation.VDW) { vdwToggle.isOn = true; } colourBondsToggle.isOn = renderSettings.ColourBonds; largeBondsToggle.isOn = renderSettings.LargeBonds; colourSecondaryStructureToggle.isOn = renderSettings.ColourSecondaryStructure; setResidueColourButtonColour(renderSettings.ResidueColour); // create atom option buttons atomButtons = new Dictionary <string, ResidueAtomNameButton>(); UnityCleanup.DestroyGameObjects(atomListContentPanel); if (atomNames != null) { foreach (string atomName in atomNames) { GameObject atomOptionsButton = GameObject.Instantiate(atomNameButtonPrefab); atomOptionsButton.transform.SetParent(atomListContentPanel.transform, false); ResidueAtomNameButton buttonScript = atomOptionsButton.GetComponent <ResidueAtomNameButton>(); AtomRenderSettings atomSettingsCopy = new AtomRenderSettings(atomName, Settings.ResidueColourDefault); if (renderSettings.AtomSettings.ContainsKey(atomName)) { atomSettingsCopy = renderSettings.AtomSettings[atomName].Clone(); } buttonScript.Initialise(atomSettingsCopy, colourSelectPanel, AutoSaveSettings); if (!atomButtons.ContainsKey(atomName)) { atomButtons.Add(atomName, buttonScript); } else { Debug.Log("Duplicate atom name in custom residue settings"); } } } }