Пример #1
0
        protected void FilterTargetList(TargetList targets)
        {
#if UNITY_EDITOR
            var debugRemoveNames = new List <string>();
#endif
            this.iterTargets.Clear();
            this.iterTargets.AddRange(targets);
            for (int i = 0; i < iterTargets.Count; i++)
            {
                this.currentTarget = iterTargets[i];

                if (this.IsInAngle(this.currentTarget))
                {
                    continue;  // This target is good. Don't ignore it. Continue.
                }
#if UNITY_EDITOR
                debugRemoveNames.Add(this.currentTarget.targetable.name);
#endif
                targets.Remove(this.currentTarget);
            }

#if UNITY_EDITOR
            if (this.debugLevel == DEBUG_LEVELS.High && debugRemoveNames.Count > 0)
            {
                string msg = string.Format
                             (
                    "Holding fire due to misalignment: {0}",
                    string.Join(", ", debugRemoveNames.ToArray())
                             );

                Debug.Log(string.Format("{0}: {1}", this, msg));
            }
#endif
        }
Пример #2
0
        private void FilterTargetList(TargetList targets, LayerMask mask, Vector3 fromPos, Color debugLineColor)
        {
            List <Target> list = new List <Target>(targets);

            foreach (Target current in list)
            {
                bool    flag     = false;
                Vector3 position = current.targetable.xform.position;
                if (this.testMode == LineOfSightModifier.TEST_MODE.SixPoint)
                {
                    foreach (Vector3 current2 in new List <Vector3>
                    {
                        new Vector3(position.x + this.radius, position.y, position.z),
                        new Vector3(position.x, position.y + this.radius, position.z),
                        new Vector3(position.x, position.y, position.z + this.radius),
                        new Vector3(position.x - this.radius, position.y, position.z),
                        new Vector3(position.x, position.y - this.radius, position.z),
                        new Vector3(position.x, position.y, position.z - this.radius)
                    })
                    {
                        flag = Physics.Linecast(fromPos, current2, mask);
                        if (!flag)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    flag = Physics.Linecast(fromPos, position, mask);
                }
                if (flag)
                {
                    targets.Remove(current);
                }
            }
        }
Пример #3
0
        protected void FilterFireTargetList(TargetList targets)
        {
            // Get the position expected to be used to fire from.
            Vector3 fromPos = this.origin.position;

#if UNITY_EDITOR
            var debugRemoveNames = new List <string>();
#endif
            this.iterTargets.Clear();
            this.iterTargets.AddRange(targets);
            float dist;
            for (int i = 0; i < iterTargets.Count; i++)
            {
                this.currentTarget = iterTargets[i];
                dist = this.currentTarget.targetable.GetDistToPos(fromPos);

                // Skip if the target is in the distance range
                if (dist > this.minDistance && dist < this.maxDistance)
                {
#if UNITY_EDITOR
                    if (this.debugLevel > DEBUG_LEVELS.Off)
                    {
                        Debug.DrawLine
                        (
                            fromPos,
                            this.currentTarget.targetable.transform.position,
                            Color.green,
                            0.01f
                        );
                    }
#endif
                    continue;
                }

#if UNITY_EDITOR
                if (this.debugLevel > DEBUG_LEVELS.Off)
                {
                    Debug.DrawLine
                    (
                        fromPos,
                        this.currentTarget.targetable.transform.position,
                        Color.red,
                        0.01f
                    );
                }
#endif
                targets.Remove(this.currentTarget);

#if UNITY_EDITOR
                debugRemoveNames.Add(this.currentTarget.targetable.name);
#endif
            }

#if UNITY_EDITOR
            if (this.debugLevel == DEBUG_LEVELS.High && debugRemoveNames.Count > 0)
            {
                string msg = string.Format
                             (
                    "Holding fire due to distance: {0}",
                    string.Join(", ", debugRemoveNames.ToArray())
                             );

                Debug.Log(string.Format("{0}: {1}", this, msg));
            }
#endif
        }
Пример #4
0
        private void FilterTargetList(TargetList targets, LayerMask mask, Vector3 fromPos,
                                      Color debugLineColor)
        {
#if UNITY_EDITOR
            var debugRemoveNames = new List <string>();
#endif

            Vector3 toPos;
            bool    isNotLOS;
            var     iterTargets = new List <Target>(targets);

            foreach (Target target in iterTargets)
            {
                isNotLOS = false;

                toPos = target.targetable.xform.position;

                if (this.testMode == TEST_MODE.SixPoint)
                {
                    var sweep = new List <Vector3>();
                    sweep.Add(new Vector3(toPos.x + this.radius, toPos.y, toPos.z));
                    sweep.Add(new Vector3(toPos.x, toPos.y + this.radius, toPos.z));
                    sweep.Add(new Vector3(toPos.x, toPos.y, toPos.z + this.radius));

                    sweep.Add(new Vector3(toPos.x - this.radius, toPos.y, toPos.z));
                    sweep.Add(new Vector3(toPos.x, toPos.y - this.radius, toPos.z));
                    sweep.Add(new Vector3(toPos.x, toPos.y, toPos.z - this.radius));

                    foreach (Vector3 pos in sweep)
                    {
                        isNotLOS = Physics.Linecast(fromPos, pos, mask);
#if UNITY_EDITOR
                        if (this.debugLevel > DEBUG_LEVELS.Off)
                        {
                            Debug.DrawLine(fromPos, pos, debugLineColor, 0.01f);
                        }
#endif
                        // Quit loop at first positive test
                        if (isNotLOS)
                        {
                            continue;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else
                {
                    isNotLOS = Physics.Linecast(fromPos, toPos, mask);
#if UNITY_EDITOR
                    if (this.debugLevel > DEBUG_LEVELS.Off)
                    {
                        Debug.DrawLine(fromPos, toPos, debugLineColor, 0.01f);
                    }
#endif
                }

                if (isNotLOS)
                {
                    targets.Remove(target);

#if UNITY_EDITOR
                    debugRemoveNames.Add(target.targetable.name);
#endif
                }
            }

#if UNITY_EDITOR
            if (this.debugLevel == DEBUG_LEVELS.High && debugRemoveNames.Count > 0)
            {
                Debug.Log("Holding fire for LOS: " +
                          string.Join(",", debugRemoveNames.ToArray()));
            }
#endif
        }
Пример #5
0
        protected void FilterTargetList(TargetList targets, LayerMask mask, Vector3 fromPos,
                                        Color debugLineColor)
        {
#if UNITY_EDITOR
            var debugRemoveNames = new List <string>();
#endif

            Vector3  toPos;
            bool     isNotLOS;
            var      iterTargets = new List <Target>(targets);
            Collider targetColl;
            foreach (Target target in iterTargets)
            {
                isNotLOS = false;

                if (this.testMode == TEST_MODE.BoundingBox)
                {
                    targetColl = target.targetable.coll;

                    // This solution works with rotation pretty well
                    Matrix4x4 mtx = target.targetable.transform.localToWorldMatrix;

                    Vector3 ext      = targetColl.bounds.extents * 0.5f;
                    var     bboxPnts = new Vector3[8];
                    bboxPnts[0] = mtx.MultiplyPoint3x4(ext);
                    bboxPnts[1] = mtx.MultiplyPoint3x4(new Vector3(-ext.x, ext.y, ext.z));
                    bboxPnts[2] = mtx.MultiplyPoint3x4(new Vector3(ext.x, ext.y, -ext.z));
                    bboxPnts[3] = mtx.MultiplyPoint3x4(new Vector3(-ext.x, ext.y, -ext.z));
                    bboxPnts[4] = mtx.MultiplyPoint3x4(new Vector3(ext.x, -ext.y, ext.z));
                    bboxPnts[5] = mtx.MultiplyPoint3x4(new Vector3(-ext.x, -ext.y, ext.z));
                    bboxPnts[6] = mtx.MultiplyPoint3x4(new Vector3(ext.x, -ext.y, -ext.z));
                    bboxPnts[7] = mtx.MultiplyPoint3x4(-ext);

                    for (int i = 0; i < bboxPnts.Length; i++)
                    {
                        isNotLOS = Physics.Linecast(fromPos, bboxPnts[i], mask);

                        // Quit loop at first positive test
                        if (isNotLOS)
                        {
#if UNITY_EDITOR
                            if (this.debugLevel > DEBUG_LEVELS.Off)
                            {
                                Debug.DrawLine(fromPos, bboxPnts[i], debugLineColor, 0.01f);
                            }
#endif
                            continue;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else
                {
                    toPos    = target.targetable.transform.position;
                    isNotLOS = Physics.Linecast(fromPos, toPos, mask);
#if UNITY_EDITOR
                    if (isNotLOS && this.debugLevel > DEBUG_LEVELS.Off)
                    {
                        Debug.DrawLine(fromPos, toPos, debugLineColor, 0.01f);
                    }
#endif
                }

                if (isNotLOS)
                {
                    targets.Remove(target);

#if UNITY_EDITOR
                    debugRemoveNames.Add(target.targetable.name);
#endif
                }
            }

#if UNITY_EDITOR
            if (this.debugLevel == DEBUG_LEVELS.High && debugRemoveNames.Count > 0)
            {
                Debug.Log("Holding fire for LOS: " +
                          string.Join(",", debugRemoveNames.ToArray()));
            }
#endif
        }