Exemple #1
0
    bool isTargetFound(ref TargetInfoUnit targ)
    {
        var isFound = targ.isExists();


        if (isFound)
        {
            target = targ;

            targetReleaseTime = Time.time + targetReleaseLimit;
        }
        else
        {
            if (isVirtualTargetLost)
            {
                target = new TargetInfoUnit();
            }
            else
            {
                // 敵を発見できなくても、時間限界内なら敵のだいたい(半径30m)の位置を特定し続ける。
                // ただし、残り30秒を切ると時間とともに誤差が大きくなっていく。

                var remainingTime = targetReleaseTime - Time.time;

                var errRadius = remainingTime > 30.0f ? 30.0f : 30.0f + 30.0f - remainingTime;

                target.cocapture(errRadius);
            }
        }

        isRealTargetLost = !isFound;


        return(isFound);
    }
Exemple #2
0
    public bool capture(int id, _Action3 thisTarget, bool forceChangeTarget = false)
    {
        if (thisTarget != null && !thisTarget.isDead)
        {
            target.act = thisTarget;

            var isFound = capture(id);

            if (!isFound && forceChangeTarget)
            {
                target.act = thisTarget;

                isRealTargetLost = true;
            }


            return(isFound);
        }
        else
        {
            if (forceChangeTarget)
            {
                target = new TargetInfoUnit();

                isRealTargetLost = true;
            }

            return(false);
        }
    }
Exemple #3
0
    void OnEnable()
    {
        target = new TargetInfoUnit(rb.position, 30.0f); targetReleaseTime = 1000.0f;

        setSensitiveRate(1.0f);

        isRealTargetLost = true;

        researchBaseTime = Time.time - Random.value * perceptions[0].scanInterval;
    }
Exemple #4
0
        public bool isExists()
        {
            if (act != null)
            {
                if (act.isDead)
                {
                    this = new TargetInfoUnit();
                }
                else
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #5
0
    // キャプチャ ---------------------------

    public bool capture(int id)
    {
        var resTarget = new TargetInfoUnit();


        if (target.isExists())
        {
            researchBaseTime = Time.time;


            var sqrDist = (target.act.tfObservedCenter.position - tfSensor.position).sqrMagnitude;


            resTarget = perceptions[id].capture(this, target.act, sqrDist);
        }


        return(isTargetFound(ref resTarget));
    }
Exemple #6
0
    public void forceUntarget()
    {
        target = new TargetInfoUnit();

        targetReleaseTime = 0.0f;
    }
Exemple #7
0
    public void forceTarget(Vector3 point, float errRadius = 30.0f)
    {
        target = new TargetInfoUnit(point, errRadius);

        targetReleaseTime = Time.time + targetReleaseLimit;
    }
Exemple #8
0
    // スキャン -------------------------------------------------

    public bool scan(int id)
    {
        researchBaseTime = Time.time;


        var pos = tfSensor.position;

        var maxRadius = perceptions[id].maxDistance * sensitiveRate;


        var targ = new TargetInfoUnit();


        var cs = Physics.OverlapSphere(pos, maxRadius, targetLayerMask);


        if (cs.Length > 1)
        {
            var others = new _Action3[cs.Length];

            var sqrDists = new float[cs.Length];


            for (var i = 0; i < cs.Length; i++)
            {
                var thisRb = cs[i].attachedRigidbody;

                if (thisRb != rb)
                {
                    var other = thisRb.GetComponent <_Action3>();

                    sqrDists[i] = (other.tfObservedCenter.position - pos).sqrMagnitude;

                    others[i] = other;
                }
                else
                {
                    sqrDists[i] = float.PositiveInfinity;
                }
            }


            System.Array.Sort(sqrDists, others);


            targ = perceptions[id].scan(this, others, sqrDists);
        }
        else if (cs.Length == 1 && cs[0].attachedRigidbody != rb)
        {
            var otherRb = cs[0].attachedRigidbody;

            var other = otherRb.GetComponent <_Action3>();

            var sqrDist = (other.tfObservedCenter.position - pos).sqrMagnitude;


            targ = perceptions[id].capture(this, other, sqrDist);
        }
        else
        {
            //targ = new TargetInfoUnit();
        }


        return(isTargetFound(ref targ));
    }