首页 > 其他分享 >UI画框选人加动态烘焙导航移动

UI画框选人加动态烘焙导航移动

时间:2023-02-08 09:23:11浏览次数:45  
标签:float 烘焙 Mathf item selectplayers UI 画框 Input public

 


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class InputMag : MonoBehaviour
{
private bool isDragging;
private Vector3 startPos;
private Vector3 endPos;
public ImageMag imageMag;
public GameManager gameManager;
private Rect rect;
public float p = 0.02f;
public float max = 5;
public List<GameObject> selectplayers = new List<GameObject>();
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
ProcessDragRect();
}

private void ProcessDragRect()
{

if (Input.GetMouseButtonDown(0))//当鼠标左键按下
{
isDragging = true;
startPos = Input.mousePosition;
}
if (isDragging)
{
endPos = Input.mousePosition;
Vector3 center = (startPos + endPos) / 2;//计算中心锚点的位置
var size = new Vector3(Mathf.Abs(endPos.x - startPos.x), Mathf.Abs(endPos.y - startPos.y));//
imageMag.SetRectImage(center, size);//设置图片的锚点位置和大小
rect = new Rect(center - size / 2, size);//创建一个UI矩形
}
if (Input.GetMouseButtonUp(0))
{
isDragging = false;
imageMag.HideRectImage();//将框选框隐藏
var allMasters = gameManager.GetAllMasterInfo();//获取场景上所有的玩家对象
foreach (var item in allMasters)
{
item.GetChild(0).gameObject.SetActive(false);//将所有玩家对象身上的选中标记失活
var screenPos = Camera.main.WorldToScreenPoint(item.position);//重新计算玩家对象的坐标
if (rect.Contains(screenPos))//是否存在于屏幕上的框选框范围内
{
Debug.Log(item.name+"在框选范围");
selectplayers.Add(item.gameObject);//将玩家对象添加进选中的集合
item.GetChild(0).gameObject.SetActive(true);//将选中标志激活
}
}
}
if (Input.GetMouseButtonDown(1))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out RaycastHit hit))
{
if (selectplayers.Count > 0)//当选中的人数大于0
{
float c = 1.2f * selectplayers.Count;
float r = c / (Mathf.PI * 2);
float ang = Mathf.PI * 2 / selectplayers.Count;
for (int i = 0; i < selectplayers.Count; i++)
{
float x = Mathf.Sin(ang * i) * r+hit.point.x;
float z = Mathf.Cos(ang * i) * r+hit.point.z;
float noise = Mathf.PerlinNoise((x + 50) * p, (z + 50) * p);
float y = noise * max;
selectplayers[i].GetComponent<NavMeshAgent>().SetDestination(new Vector3(x, y, z));//让寻路组件移动到计算的位置上
}
}
}
}
}
}

标签:float,烘焙,Mathf,item,selectplayers,UI,画框,Input,public
From: https://www.cnblogs.com/Chenchen11111/p/17100493.html

相关文章

  • 如何为 Debian 11 安装图形用户界面 (GUI)
    如何为Debian11安装图形用户界面(GUI)allway2于2021-12-2617:30:14发布11767收藏23文章标签:debian服务器linux版权华为云开发者联盟该内容已被华为云开发......
  • UICC Send USSD 加密信息解析
    已以下指令为例已知发送USSD的格式为:SendUSSD aaaxxxxxxxxxxxx*yyyyyyy#;Fetch:==:SENDUSSDSEND801200001FASSERTD01D81030112008202818305008A100F2A5C0DA782......
  • ESP32+Arduino+OLED+u8g2播放视频
    1、思路分析ESP32采用Arduino开发,结合u8g2模块可以很方便地实现在oled上显示图片。因此,只需要将一个视频拆开成一帧帧,然后循环显示即可。然而,有几个问题:视频太大,esp3......
  • 抓包工具——Burp Suite的使用(简单的数据包截获)
    Burp设置代理因为Burp为抓包工具,所以它的主要任务是截获数据包,截获HTTP或HTTPS请求和服务器响应的数据包,所以要再Burp设置代理,具体操作如下:首先打开Burp进入初始界面,如图......
  • arduino 合宙esp32c3 初体验--点灯
    刷B站看到很多人都说合宙esp32c39.9元简易版,划算的很,赶紧购入一块和lcd扩展,拿到手后开始焊接接线柱,然后就开始试着点灯操作步骤:1.安装arduino2.安装arduino的esp32相关......
  • FreeSwitch:send_dtmf/uuid_send_dtmf发送按键注意事项
    很多时候我们打电话到公司前台,会听到类似“欢迎致电XXX,办公电话请直拨分机,咨询XX请按1,咨询YY请按2”这样的语音提示。在一些特定流程中,系统自动发起呼叫打到前台,希望实现自......
  • TagUI机器人流程自动化搭建与简单脚本#这是我在51CTO博客的第一篇博文
    这是我在51CTO博客的第一篇博文。下载TagUI安装包,安装即可:​​TagUIv6.46Windows安装包​​安装好之后,测试一下。新建一个文本文档,在里面输入百度的网址​​https://www.......
  • java.lang.NoSuchMethodError: com.google.gson.GsonBuilder.setLenient()Lcom/google
    引入第三方的工具类,重新启动项目就会奇奇怪怪的报错。加载不到gson类。一开始以为是没有加载到,各种引入,清理问题依然存在。直到仔细看报错信息,里面是spring的类报错,才意识......
  • 思源笔记用Python+quicker实现自动添加标题编号
    实现原理:通过Python访问笔记的源文件,将标题前面增加编号+tab键,在写回源文件为防止重复写入,每次编号前会清理之前编号清除,清理原理为将标题行用tab键分割,......
  • (树形DP+背包)POJ1947Rebuilding Roads
    RebuildingRoadsTimeLimit: 1000MS MemoryLimit: 30000KTotalSubmissions: 13307 Accepted: 6171DescriptionThecowshavereconstructedFarmerJohn'sfarm,w......