コード例 #1
0
        /// <summary>
        /// Finds free molecuels for a new ReactinPrep.
        /// If not enough molecules are found, the ReactionPrep is not released. It has to be done by the caller.
        /// </summary>
        /// <returns><c>true</c>, if molecuels for reaction were found, <c>false</c> if not enough molecules are availalble.</returns>
        /// <param name="reactionPrep">ReactionPrep. Must not have any Molecules added alreay.</param>
        /// <param name="referenceMolecule">Molecule that is wished to be part of the reaction</param>
        public bool FindMolecuelsForReaction(ReactionPrep reactionPrep, Molecule referenceMolecule)
        {
            // species needed for the reaction
            List <MoleculeSpecies> species = new List <MoleculeSpecies>(reactionPrep.ReactionType.Reagents);

            // add reference
            reactionPrep.AddMolecule(referenceMolecule);

            // remove the species from the reference as it is already added
            if (!species.Remove(referenceMolecule.Species))
            {
                throw new System.Exception("Species of referenceMolecule isn't needed in reaction");
            }

            // find near molecules for missing species.
            Molecule m;

            for (int i = 0; i < species.Count; i++)
            {
                if (FindNearestMoleculeForReaction(referenceMolecule, species[i], out m))
                {
                    reactionPrep.AddMolecule(m);
                }
                else
                {
                    return(false);
                }
            }

            // successful
            return(true);
        }
コード例 #2
0
        void FixedUpdate()
        {
            //
            // When in reaction, add attraction force to the location of the reaction
            //

            ReactionPrep r = ReactionPrep;

            if (r != null && r.Active)
            {
                Vector3 destination = r.GetExpectedReactionLocation();

                Vector3 force = Vector3.Normalize(destination - Position);

                rigidbody.AddForce(force, ForceMode.Acceleration);

                //Debug.Log(force);
            }

            //
            // Collide with compartment wall
            //

            CUE cue = CUE.GetInstance();

            cue.CheckCompartmentCollision(this);
        }
コード例 #3
0
        /// <summary>
        /// Assigns a reaction prep, that indicates that the molecule is involved in a reaction.
        /// The MoleculeManager is updated.
        /// </summary>
        /// <param name="reactionPrep">Reaction prep.</param>
        public void AssignReactionPrep(ReactionPrep reactionPrep)
        {
            this.reactionPrep = reactionPrep;

            CUE cue = CUE.GetInstance();

            cue.Molecules.AssignReactionPrep(this);
        }
コード例 #4
0
        /// <summary>
        /// Releases the reaction prep. Called when a planned reaction is not performed (e.g. when
        /// not enough molecules available or an reaction occurs). ReactionPrep is set to null again.
        /// </summary>
        public void ReleaseReactionPrep()
        {
            if (this.reactionPrep != null)
            {
                this.reactionPrep = null;

                CUE cue = CUE.GetInstance();
                cue.Molecules.ReleaseReactionPrep(this);
            }
        }
コード例 #5
0
        /// <summary>
        /// Clears the reaction prep after the reaction was performed. The molecule is
        /// removed from the MoleculeManager. Molecule must be deleted after calling this method
        /// </summary>
        public void ClearReactionPrep()
        {
            if (this.reactionPrep != null)
            {
                CUE cue = CUE.GetInstance();
                cue.Molecules.ClearReactionPrep(this);

                this.reactionPrep = null;
            }
        }
コード例 #6
0
        /// <summary>
        /// Finds free molecuels for a new ReactinPrep.
        /// If not enough molecules are found, the ReactionPrep is not released. It has to be done by the caller.
        /// </summary>
        /// <returns><c>true</c>, if molecuels for reaction were found, <c>false</c> if not enough molecules are availalble.</returns>
        /// <param name="reactionPrep">ReactionPrep. Must not have any Molecules added alreay.</param>
        public bool FindMolecuelsForReaction(ReactionPrep reactionPrep)
        {
            MoleculeSpecies[] species = reactionPrep.ReactionType.Reagents;

            if (species.Length > 0)
            {
                Molecule m;

                if (FindRandomMoleculeForReaction(species[0], out m))
                {
                    return(FindMolecuelsForReaction(reactionPrep, m));
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }