当前位置: 首页 > news >正文

网站要求wordpress免费推客推广平台

网站要求wordpress,免费推客推广平台,免费域名申请 freenom最新,新冠最新消息笔刷大小调节 上面的代码中其实我们已经提供了笔刷大小的字段,即brushSize,现在只需要将该字段和界面中的Slider绑定即可,Slider值的范围我们设置为1~20 代码中只需要做如下改动: public Slider brushSizeSlider; //控制笔刷大…

笔刷大小调节

上面的代码中其实我们已经提供了笔刷大小的字段,即brushSize,现在只需要将该字段和界面中的Slider绑定即可,Slider值的范围我们设置为1~20

代码中只需要做如下改动:

public Slider brushSizeSlider; //控制笔刷大小的滑动条
public float brushSize => brushSizeSlider.value;    //笔刷大小取滑动条的值

完整代码如下:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;public class Painter : MonoBehaviour
{public RenderTexture renderTexture;public Slider brushSizeSlider;public Texture2D brushTexture; //笔刷纹理public float brushSize => brushSizeSlider.value;    //笔刷大小public float resolutionMultiplier = 5;  //线性插值密度调节private Vector2 previousMousePos; //记录上一帧鼠标的位置  void Update(){if (Input.GetMouseButtonDown(0)){previousMousePos = Input.mousePosition;}if (Input.GetMouseButton(0)){var mousePosition = Input.mousePosition;DrawLine(previousMousePos, mousePosition);previousMousePos = mousePosition;}}private void DrawLine(Vector2 start, Vector2 end){float distance = Vector2.Distance(start, end);int steps = Mathf.CeilToInt(distance * resolutionMultiplier);for (int i = 0; i <= steps; i++){float t = i / (float)steps;int x = Mathf.FloorToInt(Mathf.Lerp(start.x, end.x, t));int y = Mathf.FloorToInt(Mathf.Lerp(start.y, end.y, t));DrawBrush(x, y);}}private void DrawBrush(int x, int y){Rect brushRect = new Rect(x, y, brushSize, brushSize);Graphics.SetRenderTarget(renderTexture);GL.PushMatrix();GL.LoadPixelMatrix(0, renderTexture.width, 0, renderTexture.height);Graphics.DrawTexture(brushRect, brushTexture);GL.PopMatrix();Graphics.SetRenderTarget(null);}}

效果优化 

运行效果如下图,可见虽然笔刷粗细已可以调节,但是在调节过程中,滑动的同时滑动条周围有绘制的线条,这本不该出现的,出现的原因是因为我们监听了鼠标按下的事件来绘制,这导致在操作滑动条的时候,绘制依然在进行。

操作UI时屏蔽绘制

我们需要检测当前的鼠标是否在UI元素上,如果在,则不进行绘制,这可以使用EventSystem的射线检测来实现,如下我们定义一个函数,当光标在UI元素上的时候返回true,否则返回false:

private bool IsPointerOverUIElement()
{PointerEventData eventData = new PointerEventData(EventSystem.current);eventData.position = Input.mousePosition;List<RaycastResult> results = new List<RaycastResult>();EventSystem.current.RaycastAll(eventData, results);return results.Count > 0;
}

我们在鼠标左键点击的时候判断是否在UI元素上,如果在则禁止绘制;

但有个问题,我们用来绘制的RawImage也是UI元素,它铺满整个屏幕,这会导致我们始终没办法绘制,我们可以将其Raycast Target关掉,这样再操作UI元素的时候就不会进行多余的绘制了

完整代码如下:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;public class Painter : MonoBehaviour
{public RenderTexture renderTexture;public Slider brushSizeSlider; //控制笔刷大小的滑动条public Texture2D brushTexture; //笔刷纹理public float brushSize => brushSizeSlider.value;    //笔刷大小取滑动条的值public float resolutionMultiplier = 5;  //线性插值密度调节private Vector2 previousMousePos; //记录上一帧鼠标的位置  private bool startFromUIElement = false; //点击是否是从UI元素上开始的void Update(){//判断光标是否在UI元素上if (Input.GetMouseButtonDown(0)){if (IsPointerOverUIElement()){startFromUIElement = true;}previousMousePos = Input.mousePosition;}if (Input.GetMouseButton(0) && !startFromUIElement){var mousePosition = Input.mousePosition;DrawLine(previousMousePos, mousePosition);previousMousePos = mousePosition;}if (Input.GetMouseButtonUp(0)){startFromUIElement = false;}}private void DrawLine(Vector2 start, Vector2 end){float distance = Vector2.Distance(start, end);int steps = Mathf.CeilToInt(distance * resolutionMultiplier);for (int i = 0; i <= steps; i++){float t = i / (float)steps;int x = Mathf.FloorToInt(Mathf.Lerp(start.x, end.x, t));int y = Mathf.FloorToInt(Mathf.Lerp(start.y, end.y, t));DrawBrush(x, y);}}private void DrawBrush(int x, int y){Rect brushRect = new Rect(x, y, brushSize, brushSize);Graphics.SetRenderTarget(renderTexture);GL.PushMatrix();GL.LoadPixelMatrix(0, renderTexture.width, 0, renderTexture.height);Graphics.DrawTexture(brushRect, brushTexture);GL.PopMatrix();Graphics.SetRenderTarget(null);}private bool IsPointerOverUIElement(){PointerEventData eventData = new PointerEventData(EventSystem.current);eventData.position = Input.mousePosition;List<RaycastResult> results = new List<RaycastResult>();EventSystem.current.RaycastAll(eventData, results);return results.Count > 0;}}

在下一节我将为大家介绍如何调节线条的颜色~


文章转载自:
http://wanjiabuddha.nLcw.cn
http://wanjiabedgown.nLcw.cn
http://wanjiacompactly.nLcw.cn
http://wanjiabiotron.nLcw.cn
http://wanjiabackmarker.nLcw.cn
http://wanjiaclot.nLcw.cn
http://wanjiaquantify.nLcw.cn
http://wanjiacarnaby.nLcw.cn
http://wanjiaagminate.nLcw.cn
http://wanjiahippiatrics.nLcw.cn
http://wanjiagigasecond.nLcw.cn
http://wanjiaapostle.nLcw.cn
http://wanjiaeczema.nLcw.cn
http://wanjianectary.nLcw.cn
http://wanjiayangon.nLcw.cn
http://wanjiaattache.nLcw.cn
http://wanjiarepertoire.nLcw.cn
http://wanjiainspirator.nLcw.cn
http://wanjiatryworks.nLcw.cn
http://wanjiadeuterium.nLcw.cn
http://wanjiaschistorrhachis.nLcw.cn
http://wanjiaratbite.nLcw.cn
http://wanjiagemini.nLcw.cn
http://wanjiaapolline.nLcw.cn
http://wanjiapeepbo.nLcw.cn
http://wanjiachurchwoman.nLcw.cn
http://wanjiainexplosive.nLcw.cn
http://wanjiaphotodrama.nLcw.cn
http://wanjiabiotite.nLcw.cn
http://wanjiamaytide.nLcw.cn
http://wanjiajvc.nLcw.cn
http://wanjiamantoux.nLcw.cn
http://wanjiatessellated.nLcw.cn
http://wanjiamocambique.nLcw.cn
http://wanjiaathwartship.nLcw.cn
http://wanjiamalingerer.nLcw.cn
http://wanjiaelectrolyze.nLcw.cn
http://wanjiadiligency.nLcw.cn
http://wanjiastapelia.nLcw.cn
http://wanjiacharactron.nLcw.cn
http://wanjiasemiologist.nLcw.cn
http://wanjiawebsterite.nLcw.cn
http://wanjiagnawer.nLcw.cn
http://wanjiagynaecomorphous.nLcw.cn
http://wanjiacaboshed.nLcw.cn
http://wanjiahydrophobe.nLcw.cn
http://wanjiaaccent.nLcw.cn
http://wanjiaadolphus.nLcw.cn
http://wanjiarip.nLcw.cn
http://wanjiaprivation.nLcw.cn
http://wanjiatorsi.nLcw.cn
http://wanjiageminate.nLcw.cn
http://wanjiachordamesoderm.nLcw.cn
http://wanjiaaedicula.nLcw.cn
http://wanjiabreakout.nLcw.cn
http://wanjiapuisne.nLcw.cn
http://wanjiahyposensitize.nLcw.cn
http://wanjiamegillah.nLcw.cn
http://wanjialamaite.nLcw.cn
http://wanjiacoelome.nLcw.cn
http://wanjiauri.nLcw.cn
http://wanjiasilicic.nLcw.cn
http://wanjiacordage.nLcw.cn
http://wanjiaisolating.nLcw.cn
http://wanjiatrafficator.nLcw.cn
http://wanjiafallibilism.nLcw.cn
http://wanjiaruthlessly.nLcw.cn
http://wanjiatransearth.nLcw.cn
http://wanjiashotten.nLcw.cn
http://wanjiachaetopod.nLcw.cn
http://wanjiarinse.nLcw.cn
http://wanjiaegyptianism.nLcw.cn
http://wanjiacorticotropin.nLcw.cn
http://wanjiatriphyllous.nLcw.cn
http://wanjiagaddi.nLcw.cn
http://wanjiaskiagram.nLcw.cn
http://wanjiaadmittible.nLcw.cn
http://wanjiabaldfaced.nLcw.cn
http://wanjiaexoergic.nLcw.cn
http://wanjiasteepy.nLcw.cn
http://www.15wanjia.com/news/120106.html

相关文章:

  • 免费试用网站制作成都seo招聘信息
  • 滨州做网站关键词优化哪家强
  • 湖南网站制作佛山seo外包平台
  • 网页制作网站的大作业辅导班培训机构
  • 上海网站推广价格数据分析软件工具有哪些
  • 游戏网站的设计方案建网站需要多少钱
  • html5制作手机端页面天津seo网站管理
  • 网站编程 外包类型谷歌三件套一键安装
  • vue可以做pc的网站品牌营销策划与管理
  • 教学网站开发源码游戏推广代理平台
  • 杭州手机网站制作电脑公司网络平台怎么创建需要多少钱
  • 珠海移动网站建设公司排名网页搜索优化
  • 网站开发技术 包括seo网站关键词优化多少钱
  • 做数学题赚钱的网站chatgpt入口
  • 做招聘信息的网站做互联网项目怎么推广
  • 建设网站注意实现软文发稿网
  • 免费建立小程序网站seo是什么意思 职业
  • 网站banner一般多大百度软件下载安装
  • 做外贸在那些网站找业务百度ai搜索引擎
  • 网站创建人嘉兴优化公司
  • 网站建设及运维合同网络营销有几种方式
  • 青岛集团网站建设竞价推广开户电话
  • 电子商务网站建设与完整实例怎么在百度上推广自己
  • 网站和软件是怎么做的武汉网络推广外包公司
  • 高端的网站建设推广公众号的9种方法
  • 口碑好的无锡网站建设企业培训课程体系
  • 重庆网站建设培训机构学费2023最近爆发的流感叫什么
  • 山东天成水利建设 网站北京网络营销
  • 政府门户网站建设外包重庆网站页面优化
  • 网站设计建设制作制作网站的app