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

来源:互联网 发布:2016网络流行伤感情歌 编辑:程序博客网 时间:2024/04/28 23:50
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);    }}


0 0
原创粉丝点击