Unity 通过鼠标框选绘制矩形区域

2023-12-29 19:43:52

鼠标拖动的同时绘制一块同等大小的区域:如下

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 通过鼠标框选绘制矩形区域
/// </summary>
/// 

public enum MouseType
{
    left = 0,
    right = 1,
    middle = 2
}
public class DrawRectangleArea : MonoBehaviour
{

   

    bool _canAddArea = true;

    /// <summary>
    /// 是否可以绘制
    /// </summary>
    public bool canAddArea
    {
        set { _canAddArea = value; }
        get { return _canAddArea; }
    }
     bool _isDraw = false;

    [SerializeField]
    Transform areaCube;
   
     Vector3 leftTopPos = Vector3.zero;
     Vector3 rightBottomPos = Vector3.zero;


    /// <summary>
    /// 绘制区域所在的层级
    /// </summary>
    [SerializeField]
    LayerMask maskLayer = 0;

    //

文章来源:https://blog.csdn.net/lizhenxiqnmlgb/article/details/135294319
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。