Наследование: MonoBehaviour
Пример #1
0
    private void ClosestCreature()
    {
        TargetCreature = null;                                  // Reference to the script of the closest creature
        GameObject target = null;
        var        dist   = Mathf.Infinity;

        ColliderCloud = Physics.OverlapSphere(_myTransform.position, (float)_lineOfSight);

        if (ColliderCloud.Length != 0)
        {
            foreach (Collider col in ColliderCloud)
            {
                var currentCollider = col.transform.gameObject;                     // Reference to the current collider being looked at
                if (currentCollider && currentCollider.gameObject.name == "root" &&
                    currentCollider != _myCreature.Root.gameObject)
                {
                    Vector3 diff = currentCollider.transform.position - _myTransform.position;
                    CurrentDistance = diff.magnitude;
                    _otherCreature  = currentCollider.transform.parent.GetComponent <Creature>();


                    if (CurrentDistance < dist)
                    {
                        target = currentCollider.transform.parent.gameObject;
                        dist   = CurrentDistance;
                    }

                    if (CurrentDistance < (float)_creatureMateRange)
                    {
                        _otherCreature = currentCollider.transform.parent.GetComponent <Creature>();
                        Genitalia otherGenital = _otherCreature.Genital.GetComponent <Genitalia>();
                        if (_myCreature.State == Creature.CurrentState.PersuingMate ||
                            _otherCreature.State == Creature.CurrentState.PersuingMate)
                        {
                            _collisionHandler.ObserveColliders(_myCreature.Genital.gameObject, otherGenital.gameObject);
                            _otherCreature.ChangeState(Creature.CurrentState.Mating);
                            _myCreature.ChangeState(Creature.CurrentState.Mating);
                        }

                        dist = CurrentDistance;
                    }
                }

                DistanceToGoal = 0F;
                Goal           = null;
                if (!target)
                {
                    continue;
                }
                TargetCreature = target.GetComponent <Creature>();
                Goal           = TargetCreature.Root;
                DistanceToGoal = DistanceUntilGoal();
            }
        }
        else
        {
            target = null;
            return;
        }
    }
Пример #2
0
    private void IdentifySimilarCreature()
    {
        TargetCreature = null;                          // Reference to the script of the closest creature
        GameObject target     = null;
        float      similarity = Mathf.Infinity;

        ColliderCloud = Physics.OverlapSphere(_myTransform.position, (float)_lineOfSight);

        if (ColliderCloud.Length == 0)
        {
            target = null;
            return;
        }

        foreach (Collider col in ColliderCloud)
        {
            var currentCollider = col.transform.gameObject;             // Reference of the current collider
            if (currentCollider && currentCollider.gameObject.name == "root" && currentCollider != _myCreature.Root.gameObject)
            {
                _otherCreature = currentCollider.transform.parent.GetComponent <Creature>();
                var currentSimilarity = GeneticsUtilities.CheckSimilarColour(_myCreature.ChromosomeComposition, _otherCreature.ChromosomeComposition);

                if (currentSimilarity < similarity)
                {
                    target     = currentCollider.transform.parent.gameObject;
                    similarity = currentSimilarity;
                }

                Vector3 locationDifference = currentCollider.transform.position - _myTransform.position;
                if (locationDifference.magnitude < (float)_creatureMateRange)
                {
                    _otherCreature = currentCollider.transform.parent.GetComponent <Creature>();
                    Genitalia otherGenital = _otherCreature.Genital.GetComponent <Genitalia>();

                    if (_myCreature.State != Creature.CurrentState.PersuingMate &&
                        _otherCreature.State != Creature.CurrentState.PersuingMate)
                    {
                    }
                    else
                    {
                        _collisionHandler.ObserveColliders(_myCreature.Genital.gameObject, otherGenital.gameObject);
                        _otherCreature.ChangeState(Creature.CurrentState.Mating);
                        _myCreature.ChangeState(Creature.CurrentState.Mating);
                    }

                    similarity = currentSimilarity;
                }
            }

            DistanceToGoal = 0F;
            Goal           = null;
            if (!target)
            {
                continue;
            }
            TargetCreature = target.GetComponent <Creature>();
            Goal           = TargetCreature.Root;
            DistanceToGoal = DistanceUntilGoal();
        }
    }
Пример #3
0
    void most_similar_creature()
    {
        targetCrt = null;                               // reference to the script of the closest creature
        GameObject target     = null;
        GameObject c          = null;                   // current collider being looked at
        float      similarity = Mathf.Infinity;
        float      curr_similarity;

        cs = Physics.OverlapSphere(_t.position, (float)los);


        if (cs.Length == 0)
        {
            target = null;
            return;
        }

        foreach (Collider col in cs)
        {
            c = (GameObject)col.transform.gameObject;
            if (c && c.gameObject.name == "root" && c != crt.root.gameObject)
            {
                other_crt       = c.transform.parent.GetComponent <Creature>();
                curr_similarity = GeneticsUtils.similar_colour(crt.chromosome, other_crt.chromosome);

                if (curr_similarity < similarity)
                {
                    target     = c.transform.parent.gameObject;
                    similarity = curr_similarity;
                }

                Vector3 diff = c.transform.position - _t.position;
                if (diff.magnitude < (float)crt_mate_range)
                {
                    other_crt = c.transform.parent.GetComponent <Creature>();
                    Genitalia other_genital = other_crt.genital.GetComponent <Genitalia>();
                    if (crt.state == Creature.State.persuing_mate || other_crt.state == Creature.State.persuing_mate)
                    {
                        co.observe(crt.genital.gameObject, other_genital.gameObject);
                        other_crt.state = Creature.State.mating;
                        crt.state       = Creature.State.mating;
                    }
                    similarity = curr_similarity;
                }
            }

            distance_to_goal = 0F;
            goal             = null;
            if (target)
            {
                targetCrt        = target.GetComponent <Creature>();
                goal             = targetCrt.root;
                distance_to_goal = distanceToGoal();
            }
        }
    }