unity C# 计算3D空间任意多边形面积,距离,角度测量工具

效果图

在这里插入图片描述

代码

using UnityEngine;
using System.Collections.Generic;
using System;
/// <summary>
/// 划线面积,距离,角度
/// </summary>
public class UnderlinedMeasureTool : MonoBehaviour
{
    /// <summary>
    /// 相机
    /// </summary>
    public Camera _camera;
    public int size = 30;//文字大小
    //圆点的预制体
    public GameObject aim;
    public LineRenderer lineRender;
    bool sb = false;

    //GL 绘制的顶点数组  顺序是  0->1  2->3 4->5    取法 0 1 3 5 7 9
    //参考UI界面
    private List<Vector3> lv;//划线的点
    private List<Vector3> lv1;//存坐标的点
    public List<GameObject> aims;
    public int type = 3;
    void Start()
    {
        lv = new List<Vector3>();
        lv1 = new List<Vector3>();
        aims = new List<GameObject>();
    }
    void Update()
    {
        if (Input.GetMouseButtonDown(0))//绘制多边形
        {
            Ray ray = _camera.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, Mathf.Infinity))
            {
                //创建圆点
                GameObject go = Instantiate(aim, new Vector3(hit.point.x, hit.point.y, hit.point.z), Quaternion.Euler(90, 0, 0)) as GameObject;
                aims.Add(go);
                lv1.Add(hit.point);
                if (type == 1)
                {
                    if (lv.Count >= 2)
                    {
                        ClearLines();
                        GameObject go1 = Instantiate(aim, new Vector3(hit.point.x, hit.point.y, hit.point.z), Quaternion.Euler(90, 0, 0)) as G
  • 1
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值