自己写了个Box类,是unity自带的Rect类的3D升级版,功能还很少~~

using UnityEngine;
using System.Collections;

public class Box
{

    public Vector3 center;
    public Vector3 size;
    public Vector3 halfSize;

    public float left;
    public float right;

    public float top;
    public float down;

    public float front;
    public float back;

    public Box(Vector3 center, Vector3 size)
    {
        this.center = center;
        this.size = size;
        this.halfSize = size / 2f;

        this.right = center.x + halfSize.x;
        this.left = center.x - halfSize.x;

        this.top = center.y + halfSize.y;
        this.down = center.y - halfSize.y;

        this.front = center.z + halfSize.z;
        this.back = center.z - halfSize.z;

    }


    public Box(float right, float left, float top, float down, float front, float back)
    {
        this.right = right;
        this.left = left;
        this.top = top;
        this.down = down;
        this.front = front;
        this.back = back;

        this.center = new Vector3((left + right) / 2f, (down + top) / 2f, (back + front) / 2f);
        this.size = new Vector3((right - left) / 2f, (top - down) / 2f, (front - back) / 2f);
        this.halfSize = size / 2;
    }


    public static Box combineBox(Box box1, Box box2)
    {
        float left = box1.left < box2.left ? box1.left : box2.left;
        float down = box1.down < box2.down ? box1.down : box2.down;
        float back = box1.back < box2.back ? box1.back : box2.left;

        float right = box1.right > box2.right ? box1.right : box2.right;
        float top = box1.top > box2.top ? box1.top : box2.top;
        float front = box1.front > box2.front ? box1.front : box2.front;

        return new Box(right, left, top, down, front, back);
    }


}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值