// Use this for initialization void Start() { AtomPrefab atom1 = (AtomPrefab)Instantiate(atomPrefab); atom1.Coordinates = new Vector3(1, 3, 2); atom1.AtomColor = new Color(0, 255, 255, 0); AtomPrefab atom2 = (AtomPrefab)Instantiate(atomPrefab); atom2.Coordinates = new Vector3(5, 3, 1); atom2.AtomColor = new Color(0, 255, 255, 0); BondPrefab bond = (BondPrefab)Instantiate(bondPrefab); bond.StartPosition = atom1.Coordinates; bond.EndPosition = atom2.Coordinates; bond.BondColor = new Color(0, 0, 0, 0); }
void Start() { string line; using (StreamReader sr = new StreamReader(new FileStream(Application.dataPath + "/StreamingAssets/" + filePath, FileMode.Open))) { while ((line = sr.ReadLine()) != null) { Regex reg = new Regex(@"\s+"); string[] cdnt = reg.Split(line); if (cdnt.Length <= 3 || cdnt.Length > 4) { continue; } AtomPrefab atom = (AtomPrefab)Instantiate(atomPrefab); atom.Coordinates = new Vector3(float.Parse(cdnt[1]), float.Parse(cdnt[2]), float.Parse(cdnt[3])); //Debug.Log(float.Parse(cdnt[1]) + " " + float.Parse(cdnt[2]) + " " + float.Parse(cdnt[3])); if (cdnt[0] == "H") { atom.AtomColor = new Color(0, 1, 0, 1); } if (cdnt[0] == "C") { atom.AtomColor = new Color(0, 0, 0, 1); } if (cdnt[0] == "O") { atom.AtomColor = new Color(1, 0, 0, 1); } if (cdnt[0] == "N") { atom.AtomColor = new Color(1, 1, 1, 1); } } } }