Exemple #1
0
    // Use this for initialization
    void Start()
    {
        _minX = minX;
        _maxX = maxX;
        _minY = minY;
        _maxY = maxY;
        _minZ = minZ;
        _maxZ = maxZ;

        // check if this is linked to another PositionBoundry
        // if so, we'll check those values for smaller boundries
        if (otherPositionBoundry != null)
        {
            _otherPositionBoundry = (PositionBoundry)otherPositionBoundry.GetComponent("PositionBoundry");
            if (_otherPositionBoundry != null)
            {
                float otherMinX = _otherPositionBoundry.GetMinXDeep();
                float otherMaxX = _otherPositionBoundry.GetMaxXDeep();
                float otherMinY = _otherPositionBoundry.GetMinYDeep();
                float otherMaxY = _otherPositionBoundry.GetMaxYDeep();
                float otherMinZ = _otherPositionBoundry.GetMinZDeep();
                float otherMaxZ = _otherPositionBoundry.GetMaxZDeep();
                if (otherMinX > _minX)
                {
                    _minX = otherMinX;
                }
                if (otherMaxX < _maxX)
                {
                    _maxX = otherMaxX;
                }
                if (otherMinY > _minY)
                {
                    _minY = otherMinY;
                }
                if (otherMaxY < _maxY)
                {
                    _maxY = otherMaxY;
                }
                if (otherMinZ > _minZ)
                {
                    _minZ = otherMinZ;
                }
                if (otherMaxZ < _maxZ)
                {
                    _maxZ = otherMaxZ;
                }
            }
        }

        // check the values, and give some warning if things are borked
        if (_minX > _maxX)
        {
            Debug.LogWarning("PositionBoundry: object " + name + " calculated a minX value of " + minX + " and maxX value of " + maxX + ". Position may get messed up.");
        }
        if (_minY > _maxY)
        {
            Debug.LogWarning("PositionBoundry: object " + name + " calculated a minY value of " + minY + " and maxY value of " + maxY + ". Position may get messed up.");
        }
        if (_minZ > _maxZ)
        {
            Debug.LogWarning("PositionBoundry: object " + name + " calculated a minZ value of " + minX + " and maxZ value of " + maxZ + ". Position may get messed up.");
        }
    }
Exemple #2
0
    // draw the bounds as represented by a box
    void OnDrawGizmosSelected()
    {
        if (drawBounds && !drawCollectedBounds)
        {
            Vector3 right  = Vector3.right * maxX;
            Vector3 left   = Vector3.right * minX;
            Vector3 top    = Vector3.up * maxY;
            Vector3 bottom = Vector3.up * minY;
            Vector3 front  = Vector3.forward * maxZ;
            Vector3 back   = Vector3.forward * minZ;

            Gizmos.color = Color.red;
            // draw the top of the box
            Gizmos.DrawLine(top + left + front, top + left + back);
            Gizmos.DrawLine(top + right + front, top + right + back);
            Gizmos.DrawLine(top + front + right, top + front + left);
            Gizmos.DrawLine(top + back + right, top + back + left);

            // draw the bottom of the box
            Gizmos.DrawLine(bottom + left + front, bottom + left + back);
            Gizmos.DrawLine(bottom + right + front, bottom + right + back);
            Gizmos.DrawLine(bottom + front + right, bottom + front + left);
            Gizmos.DrawLine(bottom + back + right, bottom + back + left);

            // draw the sides of the box
            Gizmos.DrawLine(left + front + top, left + front + bottom);
            Gizmos.DrawLine(right + front + top, right + front + bottom);
            Gizmos.DrawLine(left + back + top, left + back + bottom);
            Gizmos.DrawLine(right + back + top, right + back + bottom);
        }
        else if (drawBounds && drawCollectedBounds)
        {
            if (otherPositionBoundry != null)
            {
                _otherPositionBoundry = (PositionBoundry)otherPositionBoundry.GetComponent("PositionBoundry");
            }
            Vector3 right  = Vector3.right * GetMaxXDeep();
            Vector3 left   = Vector3.right * GetMinXDeep();
            Vector3 top    = Vector3.up * GetMaxYDeep();
            Vector3 bottom = Vector3.up * GetMinYDeep();
            Vector3 front  = Vector3.forward * GetMaxZDeep();
            Vector3 back   = Vector3.forward * GetMinZDeep();

            Gizmos.color = Color.red;
            // draw the top of the box
            Gizmos.DrawLine(top + left + front, top + left + back);
            Gizmos.DrawLine(top + right + front, top + right + back);
            Gizmos.DrawLine(top + front + right, top + front + left);
            Gizmos.DrawLine(top + back + right, top + back + left);

            // draw the bottom of the box
            Gizmos.DrawLine(bottom + left + front, bottom + left + back);
            Gizmos.DrawLine(bottom + right + front, bottom + right + back);
            Gizmos.DrawLine(bottom + front + right, bottom + front + left);
            Gizmos.DrawLine(bottom + back + right, bottom + back + left);

            // draw the sides of the box
            Gizmos.DrawLine(left + front + top, left + front + bottom);
            Gizmos.DrawLine(right + front + top, right + front + bottom);
            Gizmos.DrawLine(left + back + top, left + back + bottom);
            Gizmos.DrawLine(right + back + top, right + back + bottom);
        }
    }