最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Unity相機(jī)移動(dòng)之屏幕邊緣檢測(cè)

 更新時(shí)間:2020年02月20日 09:57:48   作者:萌萌的提莫隊(duì)長(zhǎng)  
這篇文章主要為大家詳細(xì)介紹了Unity相機(jī)移動(dòng)之屏幕邊緣檢測(cè),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Unity相機(jī)移動(dòng)之屏幕邊緣檢測(cè)的具體代碼,供大家參考,具體內(nèi)容如下

功能:

類似LOL 紅警 相機(jī)移動(dòng)方式。

鼠標(biāo)移動(dòng)到屏幕邊緣,相機(jī)隨之移動(dòng)。

當(dāng)然還有可以加億一點(diǎn)點(diǎn)細(xì)節(jié),比如鼠標(biāo)指針變化,滾輪推進(jìn)拉遠(yuǎn)視野,中鍵平移視野等。(沒做)。 

效果圖:

這里做了可視化數(shù)據(jù)(可以看到限定的屏幕距離),線框內(nèi)為檢測(cè)的距離。

代碼:

復(fù)制腳本,直接掛載相機(jī)上就可以用。

using UnityEngine;
 
/// <summary>
/// 相機(jī)邊緣移動(dòng)
/// </summary>
[RequireComponent(typeof(Camera))]
public class CameraScreenEdgeMove :MonoBehaviour
{
 
 
 [Header("使用邊緣移動(dòng)")]
 public bool isUseMoveOnScreenEdge = true;
 
 /// <summary>
 /// 打開調(diào)試
 /// </summary>
 public bool isDebugScreenEdge = true;
 
 //移動(dòng)速度
 public float moveSpeed = 1f;
 
 /// <summary>
 /// 距離屏幕邊緣多遠(yuǎn)就開始移動(dòng)相機(jī)
 /// </summary>
 public int ScreenEdgeSize = 20;
 
 private bool MoveUp;
 private bool MoveDown;
 private bool MoveRight;
 private bool MoveLeft;
 
 private Rect RigthRect;
 private Rect UpRect;
 private Rect DownRect;
 private Rect LeftRect;
 
 private Material mat;
 private Vector3 dir = Vector3.zero;
 
 private void Start()
 {
 CreateLineMaterial();
 }
 
 private void Update()
 {
 if (isUseMoveOnScreenEdge)
 {
  UpRect = new Rect(1f, Screen.height - ScreenEdgeSize, Screen.width, ScreenEdgeSize);
  DownRect = new Rect(1f, 1f, Screen.width, ScreenEdgeSize);
 
  LeftRect = new Rect(1f, 1f, ScreenEdgeSize, Screen.height);
  RigthRect = new Rect(Screen.width - ScreenEdgeSize, 1f, ScreenEdgeSize, Screen.height);
 
 
  MoveUp = (UpRect.Contains(Input.mousePosition));
  MoveDown = (DownRect.Contains(Input.mousePosition));
 
  MoveLeft = (LeftRect.Contains(Input.mousePosition));
  MoveRight = (RigthRect.Contains(Input.mousePosition));
 
  dir.z = MoveUp ? 1 : MoveDown ? -1 : 0;
  dir.x = MoveLeft ? -1 : MoveRight ? 1 : 0;
 
  transform.position = Vector3.Lerp(transform.position, transform.position + dir * moveSpeed,Time.deltaTime);
 
 }
 }
 
 
 void CreateLineMaterial()
 {
 if (!mat)
 {
  Shader shader = Shader.Find("Hidden/Internal-Colored");
  mat = new Material(shader);
  mat.hideFlags = HideFlags.HideAndDontSave;
  mat.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
  mat.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
  mat.SetInt("_Cull", (int)UnityEngine.Rendering.CullMode.Off);
  mat.SetInt("_ZWrite", 0);
 }
 }
 
 void OnPostRender()
 {
 if (isUseMoveOnScreenEdge && isDebugScreenEdge)
 {
  DrawRect(UpRect, MoveUp, Color.cyan, Color.red); 
  DrawRect(DownRect, MoveDown, Color.green, Color.red); 
  DrawRect(LeftRect, MoveLeft, Color.yellow, Color.red); 
  DrawRect(RigthRect, MoveRight, Color.blue, Color.red); 
 }
 }
 
 private void DrawRect(Rect rect, bool isMouseEnter, Color normalColor, Color HeighLightColor)
 {
 if (isMouseEnter)
 {
  DrawScreenRect(rect, HeighLightColor);
 }
 else
 {
  DrawScreenRect(rect, normalColor);
 }
 }
 
 private void DrawScreenRect(Rect rect, Color color)
 {
 GL.LoadOrtho();
 GL.Begin(GL.LINES);
 {
  mat.SetPass(0);
  GL.Color(color);
  GL.Vertex3(rect.xMin / Screen.width, rect.yMin / Screen.height, 0);
  GL.Vertex3(rect.xMin / Screen.width, rect.yMax / Screen.height, 0);
 
  GL.Vertex3(rect.xMin / Screen.width, rect.yMax / Screen.height, 0);
  GL.Vertex3(rect.xMax / Screen.width, rect.yMax / Screen.height, 0);
 
  GL.Vertex3(rect.xMax / Screen.width, rect.yMax / Screen.height, 0);
  GL.Vertex3(rect.xMax / Screen.width, rect.yMin / Screen.height, 0);
 
  GL.Vertex3(rect.xMax / Screen.width, rect.yMin / Screen.height, 0);
  GL.Vertex3(rect.xMin / Screen.width, rect.yMin / Screen.height, 0);
  
 }
 GL.End();
 }
 
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 在C#使用字典存儲(chǔ)事件示例及實(shí)現(xiàn)自定義事件訪問器

    在C#使用字典存儲(chǔ)事件示例及實(shí)現(xiàn)自定義事件訪問器

    這篇文章主要介紹了在C#使用字典存儲(chǔ)事件示例及實(shí)現(xiàn)自定義事件訪問器的方法,是C#事件編程中的基礎(chǔ)知識(shí),需要的朋友可以參考下
    2016-02-02
  • Unity shader實(shí)現(xiàn)百葉窗特效

    Unity shader實(shí)現(xiàn)百葉窗特效

    這篇文章主要為大家詳細(xì)介紹了Unity shader實(shí)現(xiàn)百葉窗特效,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-11-11
  • C# 9.0 特性全面總結(jié)

    C# 9.0 特性全面總結(jié)

    這篇文章主要介紹了C# 9.0 特性的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下
    2021-02-02
  • C#基于UDP進(jìn)行異步通信的方法

    C#基于UDP進(jìn)行異步通信的方法

    這篇文章主要介紹了C#基于UDP進(jìn)行異步通信的方法,實(shí)例分析了C#基于UDP實(shí)現(xiàn)異步通信的相關(guān)技巧,需要的朋友可以參考下
    2015-04-04
  • C#調(diào)用WebService實(shí)例開發(fā)

    C#調(diào)用WebService實(shí)例開發(fā)

    那么,我們?cè)趺丛陧?xiàng)目中調(diào)用WebService這個(gè)方法呢,其實(shí)這和調(diào)用天氣的webservice是一個(gè)道理,首先,通過添加“web服務(wù) 引用”將,你寫的webservice引用進(jìn)來,我們需要注意的是其中有一處要我們填寫請(qǐng)求webservice的URL地址,我們?cè)撛趺磳懀?/div> 2015-09-09
  • C#之CLR內(nèi)存字符串常量池(string)

    C#之CLR內(nèi)存字符串常量池(string)

    這篇文章主要介紹了C#之CLR內(nèi)存字符串常量池(string),對(duì)于學(xué)習(xí)和理解C#內(nèi)存原理很有幫助,需要的朋友可以參考下
    2014-08-08
  • C#中異步回調(diào)函數(shù)用法實(shí)例

    C#中異步回調(diào)函數(shù)用法實(shí)例

    這篇文章主要介紹了C#中異步回調(diào)函數(shù)用法,實(shí)例分析了異步回調(diào)函數(shù)的定義及使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-04-04
  • C#使用Socket實(shí)現(xiàn)本地多人聊天室

    C#使用Socket實(shí)現(xiàn)本地多人聊天室

    這篇文章主要為大家詳細(xì)介紹了C#使用Socket實(shí)現(xiàn)本地多人聊天室,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-02-02
  • C#驗(yàn)證碼的創(chuàng)建與使用示例

    C#驗(yàn)證碼的創(chuàng)建與使用示例

    這篇文章主要介紹了C#驗(yàn)證碼的創(chuàng)建與使用方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了C#驗(yàn)證碼的創(chuàng)建、驗(yàn)證等操作步驟與相關(guān)技巧,需要的朋友可以參考下
    2017-01-01
  • C# double和decimal數(shù)據(jù)類型以截?cái)嗟姆绞奖A糁付ǖ男?shù)位數(shù)

    C# double和decimal數(shù)據(jù)類型以截?cái)嗟姆绞奖A糁付ǖ男?shù)位數(shù)

    從事ASP.NET in C#開發(fā)快一年了,今天才知道,C#中保留小數(shù)位數(shù)時(shí)沒有使用截?cái)嗟姆绞?/div> 2012-05-05

最新評(píng)論

怀远县| 二连浩特市| 县级市| 英德市| 静乐县| 霍山县| 招远市| 安徽省| 和政县| 承德市| 建水县| 博客| 江川县| 焉耆| 稻城县| 吴堡县| 柘城县| 阳东县| 丰宁| 福清市| 山西省| 湖口县| 信丰县| 阳朔县| 普陀区| 嘉兴市| 山丹县| 龙山县| 乐业县| 庆阳市| 台湾省| 洪湖市| 茌平县| 冕宁县| 韶关市| 苍山县| 五大连池市| 璧山县| 嵊州市| 广西| 安溪县|