Exemplo n.º 1
0
    private void OnMouseUp()
    {
        GameObject newBond = null;

        switch (molecule.getMode())
        {
        case MoleculeBehaviour.Mode.SingleBondStage1:
            newBond = Instantiate((GameObject)Resources.Load("Prefabs/SingleBond", typeof(GameObject)), transform.position, Quaternion.identity, molecule.transform);
            molecule.setMode(MoleculeBehaviour.Mode.SingleBondStage2);
            break;

        case MoleculeBehaviour.Mode.DoubleBondStage1:
            newBond = Instantiate((GameObject)Resources.Load("Prefabs/DoubleBond", typeof(GameObject)), transform.position, Quaternion.identity, molecule.transform);
            molecule.setMode(MoleculeBehaviour.Mode.DoubleBondStage2);
            break;

        case MoleculeBehaviour.Mode.TripleBondStage1:
            newBond = Instantiate((GameObject)Resources.Load("Prefabs/TripleBond", typeof(GameObject)), transform.position, Quaternion.identity, molecule.transform);
            molecule.setMode(MoleculeBehaviour.Mode.TripleBondStage2);
            break;

        case MoleculeBehaviour.Mode.ElectronsStage1:
            newBond = Instantiate((GameObject)Resources.Load("Prefabs/Electrons", typeof(GameObject)), transform.position, Quaternion.identity, molecule.transform);
            molecule.setMode(MoleculeBehaviour.Mode.ElectronsStage2);
            break;

        case MoleculeBehaviour.Mode.PositiveStage:
            charge += 1;
            setAtomChargeText();
            break;

        case MoleculeBehaviour.Mode.NegativeStage:
            charge -= 1;
            setAtomChargeText();
            break;
        }

        if (newBond != null)
        {
            BondBehaviour bondScript = newBond.GetComponent <BondBehaviour>();
            bondScript.initializeBond(this);
            bonds.Add(bondScript);
        }

        if (molecule.getMode().Equals(MoleculeBehaviour.Mode.AdjustingAtom))
        {
            molecule.setMode(MoleculeBehaviour.Mode.None);
        }
    }
Exemplo n.º 2
0
 public void removeBond(BondBehaviour bond)
 {
     bonds.Remove(bond);
 }
Exemplo n.º 3
0
 public void addBond(BondBehaviour bond)
 {
     bonds.Add(bond);
 }
Exemplo n.º 4
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);
                        }
                    }
                }
            }
        }
    }