Пример #1
0
    // Update is called once per frame
    void Update()
    {
        // traigo todos los atomos seleccionados
        var selectedAtoms     = atomManager.GetSelectedAtoms();
        var selectedMolecules = moleculeManager.GetSelectedMolecules();
        var selectedMaterials = materialManager.GetSelectedMaterials();

        // si hay un solo atomo seleccionado y ninguna molecula o material, actualizo los labels con sus contadores
        if (selectedAtoms.Count == 1 && selectedMolecules.Count == 0 && selectedMaterials.Count == 0)
        {
            int  atomIndex = selectedAtoms[0];
            Atom atom      = atomManager.FindAtomInList(atomIndex);

            string counterText = EMPTY_VALUE;
            switch (particleType)
            {
            case ParticleEnum.Proton:
                counterText = atom.ProtonCounter.ToString();
                break;

            case ParticleEnum.Neutron:
                counterText = atom.NeutronCounter.ToString();
                break;

            case ParticleEnum.Electron:
                counterText = atom.ElectronCounter.ToString();
                break;
            }

            gameObject.GetComponent <TextMeshProUGUI>().text = counterText;
        }
        else
        {
            // si no hay ninguno o hay mas de uno seleccionado
            gameObject.GetComponent <TextMeshProUGUI>().text = EMPTY_VALUE;
        }
    }
Пример #2
0
    //Acá tiene que ir a la bd a buscar la combinación
    public void CombineAtoms()
    {
        List <int> selectedAtoms  = atomManager.SelectedAtoms;
        List <int> elementNumbers = new List <int>();

        foreach (int index in selectedAtoms)
        {
            int numeroElemento = atomManager.FindAtomInList(index).ElementNumber;
            if (numeroElemento != 0)
            {
                elementNumbers.Add(numeroElemento);
            }
        }

        if (elementNumbers != null && elementNumbers.Count > 0)
        {
            List <List <int> > possibleCombinations = new List <List <int> >();
            IEnumerable <(int ElementId, int Count)> combinedElements = from element in elementNumbers
                                                                        group element by element into elementOccurrences
                                                                        select(
                ElementId : elementOccurrences.Key, Count : elementOccurrences.Count()
                );

            foreach ((int elementId, int count) in combinedElements)
            {
                List <int> molecules = DBManager.GetMoleculesByAtomNumberAndQuantity(elementId, count);
                possibleCombinations.Add(molecules);
            }

            if (possibleCombinations != null && possibleCombinations.Count > 0)
            {
                List <int> intersection = Intersect(possibleCombinations);
                if (intersection.Count > 0)
                {
                    bool found = false;
                    foreach (int moleculaId in intersection)
                    {
                        int elementCount = DBManager.GetUniqueElementCountInMoleculeById(moleculaId);
                        if (elementCount == combinedElements.ToList().Count)
                        {
                            MoleculeData moleculeData = DBManager.GetMoleculeById(moleculaId);
                            List <AtomInMolPositionData> atomsPosition = DBManager.GetElementPositions(moleculaId);
                            showPopUp    = true;
                            popUpMessage = "Molécula Formada: " + moleculeData.ToString;
                            found        = true;
                            DeleteCombinedAtoms(selectedAtoms);
                            SpawnMolecule(atomsPosition, moleculeData.ToString);
                            break;
                        }
                    }
                    if (!found)
                    {
                        showPopUp    = true;
                        popUpMessage = ("No se encontró ninguna combinación posible");
                    }
                }
                else
                {
                    showPopUp    = true;
                    popUpMessage = "No se encontró ninguna combinación posible";
                }
            }
            else
            {
                showPopUp    = true;
                popUpMessage = "No se encontraron moléculas que contengan esos átomos";
            }
        }
        else
        {
            showPopUp    = true;
            popUpMessage = "No hay átomos válidos seleccionados";
        }
    }