Beispiel #1
0
 public void initializeBond(AtomBehaviour anchor)
 {
     followMouse = true;
     anchors     = new AtomBehaviour[2];
     anchors[0]  = anchor;
     molecule    = GameObject.Find("Molecule").GetComponent <MoleculeBehaviour>();
 }
Beispiel #2
0
 public void initializeBond(AtomBehaviour anchor1, AtomBehaviour anchor2)
 {
     anchors    = new AtomBehaviour[2];
     anchors[0] = anchor1;
     anchors[1] = anchor2;
     molecule   = GameObject.Find("Molecule").GetComponent <MoleculeBehaviour>();
     resetAnchorPositions();
 }
Beispiel #3
0
    public static AtomBehaviour instantiateAtom(Vector3 location, string type)
    {
        MoleculeBehaviour molecule   = GameObject.Find("Molecule").GetComponent <MoleculeBehaviour>();
        GameObject        newAtom    = Instantiate((GameObject)Resources.Load("Prefabs/Atom", typeof(GameObject)), location, Quaternion.identity, molecule.transform);
        AtomBehaviour     atomScript = newAtom.GetComponent <AtomBehaviour>();

        atomScript.initializeAtom(type);
        return(atomScript);
    }
Beispiel #4
0
    public Bond getBond()
    {
        if (anchors[1] == null)
        {
            AtomBehaviour atomScript = AtomBehaviour.instantiateAtom(transform.position + Vector3.Normalize(transform.up), "z");
            anchors[1] = atomScript;
        }

        return(new Bond(anchors[0].id, anchors[1].id, (int)bondType));
    }
Beispiel #5
0
    public void newAtom(string atomType)
    {
        GameObject molecule = GameObject.Find("Molecule");
        Vector3    newLoc   = molecule.transform.position;

        if (existsCenteredAtom())
        {
            newLoc = new Vector3(Random.Range(-.5f, .5f), Random.Range(-.5f, .5f), newLoc.z);
        }

        AtomBehaviour atomScript = AtomBehaviour.instantiateAtom(newLoc, atomType);
    }
Beispiel #6
0
    public void recreateMolecule(string encodedSave)
    {
        if (encodedSave != null)
        {
            Molecule  molecule = Molecule.deserialize(UnityWebRequest.UnEscapeURL(encodedSave));
            Hashtable newAtoms = new Hashtable();

            foreach (Atom atom in molecule.a)
            {
                if (atom != null)
                {
                    GameObject    newAtom    = Instantiate((GameObject)Resources.Load("Prefabs/Atom", typeof(GameObject)), new Vector3(atom.x, atom.y, atom.z), Quaternion.identity, transform);
                    AtomBehaviour atomScript = newAtom.GetComponent <AtomBehaviour>();
                    atomScript.initializeAtom(atom.type, atom.charge);
                    newAtoms.Add(atom.id, atomScript);
                }
            }

            foreach (Bond bond in molecule.b)
            {
                if (bond != null)
                {
                    GameObject newBond = null;
                    switch (bond.type)
                    {
                    case (int)BondBehaviour.BondType.Single:
                        newBond = Instantiate((GameObject)Resources.Load("Prefabs/SingleBond", typeof(GameObject)), transform.position, Quaternion.identity, transform);
                        break;

                    case (int)BondBehaviour.BondType.Double:
                        newBond = Instantiate((GameObject)Resources.Load("Prefabs/DoubleBond", typeof(GameObject)), transform.position, Quaternion.identity, transform);
                        break;

                    case (int)BondBehaviour.BondType.Triple:
                        newBond = Instantiate((GameObject)Resources.Load("Prefabs/TripleBond", typeof(GameObject)), transform.position, Quaternion.identity, transform);
                        break;

                    case (int)BondBehaviour.BondType.Electrons:
                        newBond = Instantiate((GameObject)Resources.Load("Prefabs/Electrons", typeof(GameObject)), transform.position, Quaternion.identity, transform);
                        break;
                    }

                    if (newBond != null)
                    {
                        AtomBehaviour anchor1    = (AtomBehaviour)newAtoms[bond.a1];
                        AtomBehaviour anchor2    = (AtomBehaviour)newAtoms[bond.a2];
                        BondBehaviour bondScript = newBond.GetComponent <BondBehaviour>();
                        bondScript.initializeBond(anchor1, anchor2);

                        if (anchor1 != null)
                        {
                            anchor1.addBond(bondScript);
                        }

                        if (anchor2 != null)
                        {
                            anchor2.addBond(bondScript);
                        }
                    }
                }
            }
        }
    }